zorruno wikki: Whole House 3 Phase Energy Monitoring using PZEM-004T

Whole House 3 Phase Energy Monitoring using PZEM-004T

PZEM-004T 3 Phase Monitoring


A robust, accurate, low cost and safe whole house energy monitoring setup, using PZEM004T modules. These use current transformers (CTs), and send data as TTL Modbus-RTU. Recently Tasmota has added support for up to 3 of these directly (on the same data channel) so there are fewer hoops to jump though to get them working (previously my testing involved sending serial commands)

Project Goals

The project evolved into a small companion switchboard and combined a few additional needs.
-- Use of 3 PZEM-004T modules to measure ALL incoming power (and at maximum accuracy) including fluctuations in voltage and power factor
-- Measure other energy sources using kWh meters with impulse outputs (EV Charging, and a remote sub DB)
-- Whole house 3 Phase surge suppression/protection (just because I could)
-- Main (and companion) switchboard temperature monitoring (could be useful)
-- Switchboard open/close detection (why not)

This page is not a full project build, but my notes for the main parts and how/why it was put together


3x PZEM-004T (eg, Aliexpress, various suppliers) In plastic case, with CT
2x Pulse count kWH Meters. (Bought locally for SDoc compliance, but there are many imported versions). The ones I got were 100A and 1 pulse per 2Wh.
1x Wemos D1 mini (eg Aliexpress)
1x Hi-Link HLK-5M05 (or other 5v power regulator of about 0.5 of an Amp) (eg Aliexpress
1x 4 Pole Surge Suppression module rail mount (eg Aliexpress)
1x perf or veroboard to mount everything on (from Parts box)
1x 2 row, 12 way switchboard case, with rails etc (I got locally from a supplier for around NZ$42)
1x 3 Phase MCB/Main switch (I already had a Schneider 20A unit, unusual model but perfect for this job)
3x MCBs (I already had some GE quality 16A ones spare)
2x DHT11 temp/humidity sensors
3x BAT38 or equiv Schottky diodes
Shielded data cable for current transformer extensions etc
Board mount 1A fuse, 5mm LED, Resistors 1k (3.3v pullups), 10k (serial pullup), Wire, connectors etc
1x 300 Ohm (approx) resistor for LED
Plastic cover insert for DB (to stop fingers entering the DB top row)

PZEM-004T Individual Setup and Summary

These modules should be bought with a current transformer coil, and they are the Version 3, 100A units.
PZEM-004T Coils You can buy them with a split coil if you can't or don't have someone competent/qualified to remove the incoming mains wiring. I also completely recommend buying them with the plastic case (clear blue so you can still see the internal LEDs etc) for safety reasons. They have optical isolation across the board, but no protection for fingers etc.

The serial output is TTL level, and we will be needing around a 3V signal into our Wemos so they need a resistor mod internally.
Notes on resistor mod: https://tasmota.github.io/docs/PZEM-0XX/
PZEM-004T 1k Resistor Serial mod

Using 3x PZEM-004T over serial comms

The modules use Modbus-RTU and can have an individual ID set for serial replies. Tasmota added support in late 2019 for up to 3 PZEM modules on the same bus (hardware or software serial is fine)... and no you can't run more than 3 at this stage due to memory and performance limitations.

Multidrop Wiring

To avoid clashes on response, some diodes need to be added when more than one are used, the circuit also needs to be pulled high and below is a wiring diagram. A fast/low voltage drop Schottky diode is needed to make the comms work successfully. Remember to crossover RX/TX from the Wemos to the PZEM modules.
PZEM-004T Multidrop Modbus

Setting Module ID

As well as wiring for multidrop, the devices need to have an ID set (Sometimes referred to as IP address online, but it is a serial address). Tasmota now also allows you to set this easily with the ModuleAddress command- previously this was done with some serial commands (or with windows software linked below, but I tried this unsuccessfully).

To set the address, connect each module one at a time and on the Tasmota console, run eg
ModuleAddress 2

You'll get a response to say 'Done', but there is no reply to ensure it is carried out successfully. Obviously, set 1, 2 or 3 as needed but remember to disconnect the others when you set each one.

Main DB CT Connections

Photo of the connected CTs in the main DB. The leads were extended (using shielded data cable that was grounded at the main DB end). You can see the green earth cables running to the earth bus at the top of the board.
CT wiring

Tasmota Configuration

This is not a full detail on Tasmota setup, but some notes for this project. There are plenty of places to learn about installing and configuring Tasmota on a Wemos D1 Mini

-- I chose "Generic" Module type for the Wemos D1
-- I used hardware serial, and therefore TX GPIO1 (Serial Out) is selected as PZEM0XX Tx (62)
-- Important Note: RX GPIO3 (Serial In) is PZEM016 Rx (98) (NOT: PZEM004 Rx (63))
-- Screenshot of the Generic Tasmota Module Config (Before I added all sensors I finished up with)
-- Screenshot of what the web display looks like with 3 sensors (not yet being monitored, so no output shown)
-- Screenshot of 2 of the 3 phases being monitored

A graph of power (only 2 phases shown here)
Grafana Power Monitoring

A graph of power factor (only 2 phases shown here). You can see on both graphs, a large fridge/freezer cycling on and off on the white phase.
Grafana Power Factor Monitoring

Energy/Check Meter Pulse Output Counting

I also had a couple of kWh counters (often called Check Meters) on my main and a sub board. Not as accurate, and can't monitor V or power factor etc, but useful to look at targeted areas of power use as well as having their own LCD display on the unit itself. The ones I use give a pulse/contact output for every 2Wh of energy that passes though them.
Check Meter Pulse Measuring
This same principal will apply for most pulse count meters (eg water/gas), but I just wired a GPIO on the Wemos to the pulse count output on the meter, the other to 0v. I used a 10k Resistor to pull the GPIO high (to 3.3V, but 5V would likely be fine too according to Wemos literature). So on every pulse, the meter pulls the GPIO low.
Check Meter Pulse Count GPIO Wiring

Set the Tasmota GPIO to be a Counter (eg Counter 1 (42) )

Now, the counter input will start counting up every time there is 2Wh of energy used (the check meter will also flash in unison). This would now be fine if you can use Node Red or Home assistant to further interpret that data, but there is more you can do in Tasmota itself if you'd like to get yourself an actual average "Watts" output, over say one minute.

Firstly, set the teleperiod to 1 minute on the console. This will help us get a Wh per minute number.
TelePeriod 60

Then set up a rule to push the value of the count to MQTT, then reset the counter... once per minute (don't forget to turn on the Rule also)
rule1 on tele-counter#c1>=0 do 
	backlog publish stat/%topic%/EnergyMeterCount {"EVChargerWhCount":%value%} ; 
	counter1 0 
rule1 on   

If you wanted to compile Tasmota and use a non standard build, there are some mathematical functions you could use to get an actual Watts value into MQTT. I prefer to stick to the standard build so I can update without issue, and I now have at least a value in MQTT that is a count of half the number of Watt hours used in the last minute (remember it gives a pulse for every 2Wh in this case)

This is fine for me as I use Grafana to display the results and Grafana allows some maths to happen before display so I can convert the Wh to Watts.

(W) = (Wh)/(h) or in this case W = 2x (Pulse count) / (1/60)

This is the grafana query I used, allowing for the fact that I'm getting data every minute and 1 pulse every 2Wh:
Grafana Pulse Count Energy Wh

My basic grafana graph looks like this. More accuracy than a minute might be nice, and low power (ie less than 2Wh in a minute) will give some bumps in the graph, but this is perfectly acceptable to me.
EV Power Use

Whole House Surge Suppression for 3 Phase

Common in Europe and other locations around the world, but not really in NZ is the use of surge suppression modules in a main DB. I have a few servers and sensitive equipment so thought it might be a good idea. Standard install practice is to use an MCB before each one, and my 4 pole set also protects the neutral circuit.
Whole House Surge Suppression

Final Board Layout and Pics

-- The monitoring setup mounted on perf board, including Wemos, DHT11 and input connectors for two pulse count KWh meters, another DHT11 and microswitch (open/close on db). Currently powered by a 5v bench PSU.
-- The whole setup installed and powered up, with one PZEM004T removed as I was replacing it. Top right is the pulse count from the main board KWh meter (for my EV charging).
-- The whole board with DB cover on and flashy comms lights. Just awaiting a piece of plastic to cover the top row (or maybe glue the tinted cover in place)
Whole House Surge Suppression

Improvements and Safety Notes

Obviously, note that you must understand the licencing requirements for your country if carrying out any electrical works
-- The whole setup was designed to be completely separate to the main DB so it could be disconnected or removed in future easily if ever needed. It would be a lot simpler (but less safe) to just install all of this in a main DB.
-- It was very handy having a way to easily power the board without having 230V connected (I bought out the 5V to a connector on the right hand side of the board)
-- I took care to separate the 230V from the low voltage by dremelling away some of the perf board tracks where the 230V was connected under the Hi-Link HLK-5M05
-- I used individually twisted/shielded cable to feed the coils (and grounded the shield at the main DB end) for a couple of reasons. I was concerned there may be slight interference with extending the coil tails, and also wanted to ensure that the cables were more protected from damage. I also had some nice robust data cable perfect for the job, and extending the CT leads more than 30cms or so is probably not recommended.
-- I suggest you buy a spare set of surge suppressors, in case one blows and you want to replace it quickly. It would be nice to have a monitoring circuit to notify on suppressor failure, and although it looks like the surge base has the possibility of switching something, I haven't seen anything sensible to do this yet.
-- Care is needed to understand the neutral & grounding methods for our MEN systems, for convenience separate neutrals were run direct from the main board (but bonded them in the sub board anyway), but the earths can't be bonded to the Neutral in the sub board.
-- If you or your electrician doesn't understand the electrical connections, don't do it. You need to wire each phase to each correct PZEM, to get sensible phase, Voltage and power comparisons. If you run them off one phase, you also won't get sensible results. You also have to understand any RCD/RCBO circuitry in the main panel to ensure any earth leakage detection works correctly.
-- Research suggests it is a good idea to short out the CTs if you set them up and don't connect them to the PZEMs, as high current flowing though can damage them if open circuit.
-- I also put a simple glass fuse on the 5V rail (I used 1A), and an LED to see if the fuse was intact.

Tasmota PZEM Summary Page: https://tasmota.github.io/docs/PZEM-0XX/
PZEM 3 Phase Wiring: https://github.com/arendst/Tasmota/issues/2315#issuecomment-384643624
Setting PZEM Device IDs via serial commands: https://github.com/arendst/Tasmota/issues/2315#issuecomment-527894673

Windows Software (on my G Drive, no promises it won't contain spyware from the supplier): https://drive.google.com/file/d/1UFmQ8QEyVJhMIQZzhti2v0CutlplsEqz/view?usp=sharing
Note, this was touted as a simple way to set the device ID, but I couldn't get it to work - potentially as it may need the 230V connected to do so.

Another esp8266 project using PZEM-004T these with 3 phase: https://github.com/apreb/eNode

Useful Youtube Links re these din rail surge supressors: