Home power monitoring with PZEM-004 & home assistant for under 30$! Part 2

The physical setup. Once again this is working in proximity to MAINS power. If you’re not comfortable STOP NOW and get professional help.

As much as I didn’t want to split this into two pieces it’s becoming far too big for one post. See part 1

The physical setup that I did is as follows



  • SHUT OFF THE MAIN BREAKER to the house.
  • Attach the split coil current transformer (CT) to ONE of the mains cables after the breaker, meaning on the house side power. (in my case red or black)
  • Then using another cable with both ends bare (and one end split in two) OR cutting off the plug on the remaining end (then splitting in two), I connected the PZEM004 behind a smaller breaker to power the unit. (behind the smaller breaker in case I need to shut it off or dismantle it without turning the main breaker off)
  • Turned on the main breakers and the PZEM004 displayed the AMPS and VOLTS with kWh. (the included manual is pretty useless)

[Note the CT should ONLY go around ONE of the wires to be effective. If it goes around both the inflow and outflow of current will CANCEL themselves out and the readout will be ZERO]

See the following for the dirty breaker and setup.

The Split Coil Current Transformer goes around ONLY one, in my case the red wire.

Dirty I know..

Here you can see the white wire on the top right going in the break on the far right. That’s where the PZEM reads the power from (AFTER THE BREAKER).  The other black and white wires coming out from the bottom have separate breakers of their own.

So dirty I needed to make a cover for it

Here you can see the white cable that goes from the breaker on the far right to the PZEM. Just before the PZEM it splits in two 1– to the PZEM  2-to a female socket o connect a double USB power charger.

The double USB charger as mentioned before may not be needed as the VIN on the NodeMCU is also at 5v. The blue LED is just a remnant of the BRUH Multisensor setup.

Wiring done!

Now how to put the who together an not have pieces hanging everywhere? The “case” the breaker box had before was an open design and a 1950s green. That was a nope especially since JUST next to this was the shower/bathroom.


The very temporary cover for the breaker box, the real thing is incidentally an OPEN plastic box. To the right is the SHOWER…. #facepalm

With steam eminatting from the shower/bath and mains voltage not sitting well in my mind, I built a new housing to limit said steam from the shower/bath room to the box with materials from Daiso (dollar store). The wood was very generously doused in sealant as well as the screws to prevent rot.

Later I discovered my DHT22 (humidity and temperature) sensor indicated that the holes in the walls were sucking dry air from between the walls and it has made a positive pressure in the box, so even less steam/moisture would get in.

Plastic sheets, some treated/sealed wood, foam for tighter air control. The PZEM-004 is now flush against the plastic and level so it’s easily read through said plastic
The case I made has frosted panels so the PZEM readout isn’t super clear but that’s okay. I might cut a hole for the PZEM to sit in or not.

As for the NodeMCU as per the picture above it lays behind the PZEM on the wood of the case. I was thinking that doing something like this would be a nice next step.

picture from https://forum.mysensors.org/topic/5353/wireless-peacefair-pzem-004t-energy-monitor-on-audrino-web-server

Physical wiring and case done!







Remnant of old blog here before I delete and redo the grafana bit

Looking around I saw a nice graph style interface with node red so I installed node red as an accompaniment for hassio just as the Dr ZZs video about just that came out.

Update June 2018: although I had installed node red I haven’t properly set it up. But I do have graphs via grafana

This following video has the nice graphs with the node red dashboard.


The peacefair app also had a nice interface

This however meant that I wouldn’t be using MQTT but something else. That didn’t really interest me at the moment. So digging deeper I found it simpler to reflash the nodemcu with tasmota and have it connect to the PZEM-004 with its prebuilt pull down menus.

I used the arduino ide software to flash the NODEMCU as I could edit the options to select WIFI-MANAGER so that it would offer an easy to access AP should wifi not be available.

Once flash complete with remaining sonoff settings (changing the board type to nodemcu) the upload went well.

Once flashed I logged in the AP and set the WIFI and MQTT information as well as selecting Generic 18, for the Node MCU.


The beauty of tasmota is the pzem already had support. The power factor, energy today/yesterday/total, etc were all preloaded in the web interface of the nodemcu running tasmota.

To get this information to display in home assistant the configuration.yaml file needed editing.

This was my first foray into the YAML/JSON code without much guidance. (Previously I’ve edited code to attach two PIRs to the BRUH multisensor.)

To skip passed my trial & error see link PZEM-004 in configuration.yaml Or see my quote below

Given my recent habit of looking for a quick answer on YouTube I neglected the tasmota wiki. I blame awesome videos from BRUH Automation, Dr ZZs, and The Hook Up.

As I was in the dark about how to proceed and as my DHT-22 (humidity and temperature) sensor was still attached (with mods) I decided to activate it in the tasmota menu, and adding the entry in the configuration.yaml file.

Browsing other places for Tasmota commands and after installing my DHT-22 as SI7021 In the tasmota software I used that as a guide to create the JSON entries for the DHT-22.

The link on the tasmota page for versions newer than 5.9 didn’t seem to work. (Can’t find link anymore)

With many variables I decided to change all of them incrementally to test every permutation of code as possible.

Then I got lucky with the AMP sensor. It worked but only displayed the A value, using this and the working example for the temperature and humidity I crafted a new entry for extracting the Current, Voltage, Amps etc. (See below for code)

One problem I encountered was the slow update time of the information. The humidity and temperatures were updating by the second whereas the power updates were every 300 seconds.

Changing that to 10 seconds made everything so much better and useable. By entering “Teleperiod 10” to update every 10 seconds.

“Teleperiod 10” for 10 second interval updates

This is what my Sensor field now looks like spaces are not accurate [edit: see link below]

  – platform: mqtt
name: “Voltage”
state_topic: “tele/PowerMeter/SENSOR”
value_template: “{{ value_json[‘ENERGY’].Voltage }}”
unit_of_measurement: “V”
icon: mdi:flash
– platform: mqtt
name: “Current”
state_topic: “tele/PowerMeter/SENSOR”
value_template: “{{ value_json[‘ENERGY’].Current }}”
unit_of_measurement: “A”
icon: mdi:power-socket


– platform: mqtt
name: “Tele Temperature”
state_topic: “tele/PowerMeter/SENSOR”
value_template: “{{ value_json[‘SI7021’].Temperature }}”
unit_of_measurement: “°C”
icon: mdi:thermometer
– platform: mqtt
name: “Tele Humidity”
state_topic: “tele/PowerMeter/SENSOR”
value_template: “{{ value_json[‘SI7021’].Humidity }}”
unit_of_measurement: “%”
icon: mdi:water-percent

Typing this I found the info online. So my efforts were… a confirmation.
PZEM-004 in configuration.yaml


-With breaker turned off. Connected one end of a cable from both Terminals of the off side of the circuit breaker. The other end splits in two, 1 goes to the PZEM-004, and the other to a dual USB socket charger.
– From the charger is the cable included with the PZEM-004 powering the 5v and the Ground. It didn’t work at 3.3v in previous test powering from the nodemcu directly. I have plans to use the Vin from the nodemcu for a RCWL-0516 to detect motion inside my bathroom for light control.
– The other USB cable is a micro USB which powers the nodemcu.
– The split coil current transformer as mentioned is attached around one of the main wires from the MAINS breaker (house breaker).

The end result is:

From about 1:00 the system flatlined. So there may be some bugs to iron out. An unplug of the nodemcu and all is back to normal. Could it be a memory issue?

To be updated with more info should there be a need… I’m looking at you nodemcu freeze!



30 days later
For graphs I’m now using Grafana see post


A month later.

A comparison with the utility company’s bill.

[utility total pic here] (sorry I forgot it)

I think it was 264kwh for 6.11-7.10

Grafana gives me 355kwh for the same period. Although I think that I may have made a typo with the dates. If this is accurate then the pzem is pretty close.

I wonder if there’s a way to fine tune the calibration.


7 thoughts on “Home power monitoring with PZEM-004 & home assistant for under 30$! Part 2

  1. Hi! I want to do this also but could you clarify if I need to make any resistor mods to the PZEM or not? Most of the online instructions tell us to solder a 1k resistor.


    1. I don’t remember anymore if I saw that information anywhere. (It’s been a year)
      Do you have a link?
      Personally I did only and exactly what I wrote in the post. So no resistor.
      Try with a resistor if you’re concerned.


    1. On the second link
      “ALTERNATIVE: No modification required on the PZEM-004T. Rather than using the 3.3V output from the Wemos D1 Mini to power the PZEM-004T serial interface, use the same 5V buck converter output (also used to supply power to the display and the Wemos D1 Mini) as VDD on the PZEM-004T serial interface. This eliminates the need for the resistor and the need to modify the PZEM-004T in any way at all.”

      I personally do not use a 1k resistor. The power is from the usb cable directly (which comes with the pzem)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s