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

AS THIS IS THE MOST IN DEMAND ENTRY. I’M CONSTANTLY UPDATING IT.
IF YOU HAVE ANY QUESTIONS PLEASE ASK.

LATEST UPDATE 2018.09.09 – Post split in multiple pieces see part 2 as well

ALTERNATIVES* (added 2019.03.02) 

The standard disclaimer: Please do not attempt anything seen here if you’re not comfortable with breakers and mains power.

Home assistant home power monitoring
The unboxing 📦. [[[[[[
At this point I had BRUH room sensors in every room (except bathroom) and outside.

The next step was to have whole house monitoring. Which was finally done this morning.

A couple weeks back I received my PZEM-004. Without a clue on how to hook it up to hassio. I figured there had to be a way.

I was ready to reflash a nodemcu with original programming if I had to. I wanted house wide power monitoring but couldn’t get many ready made products in Japan nor wanted to pay 200-500USD for them. For example this awesome looking SENSE unit reviewed a while back by BRUH.

Sure I won’t have the detection software that will figure out the various appliances for me, which would be very nice, but realistically at sub 30$ I’m quite happy.

The PZEM-004 with display, split coil current transformer (CT) with a usb wire for power set me back a tiny 2116JPY (20USD) [nodemcu was 3USD]

PZEM004 home power monitoring
[a SPLIT COIL IS IMPORTANT, as it will be much easier to open the coil around the wire than to remove the wire to put it through the coil]
This unit has a limit of 100Amps, but as this leaning house has a average-small 30Amp breaker box, this would be AMP-le. (har har, ode to Dr ZZs)

This is what I bought. PZEM-004 link here. I commented that it does make a buzzing noise when powered, if it’s an issue in tiny-house-Japan. Of course if you want an even cheaper one, get it without the display. (Although I don’t recommend it as with display it’s easier to test)

TESTING:

  • Using a cable with a plug on one end and bare cable on the other (i.e. like a cut extension cord).  I used a cable bare on both ends and temporarily attached a plug to one end.
  • Connect the bare cable ends into the PZEM-004 as per the instructions on the unit
  • Connect the coil (if not already attached) and put ONE of the two wires in the extension cable through it again as per the instructions on the unit.  (not both wires as the currents will cancel each other out)
  • Power the PZEM004 via the included USB cable. I opted to use a double USB charger with one side powering the NodeMCU and the other powering the PZEM004 plugged into a power strip with a switch. (I’m guessing you could *maybe* power the PZEM004 from the VIN pin of the NodeMCU as this is the same as connecting to the USB plug directly)
  • USING a power strip with a switch at OFF, plug in the “plug” end of the cut extension cable.
  • Clearing away any other debris, things around, turn on the power strip.
  • You should be getting a reading on the PZEM004 (if you have a screen)
Hassio home power monitoring
VDD to 5v USB or maybe the VIN NodeMCU Picture from https://mysku.ru/blog/china-stores/38717.html

Providing power to the PZEM004 to TEST it worked without a hitch with a cable to the mains. I used a cable with a plug on the end and bare wires on the other. The bare wires powered the PZEM004 and splitting cable into the two wires carefully preserving the rubber the coil was attached to ONE of the wires. After the setup I plugged the cable into the wall and power readouts appeared on screen. TEST successful.

Whole house power monitoring

How to get it to play nicely with TASMOTA? (then Home Assistant)

  • Flash tasmota on the NodeMCU or Wemos. The Sonoff basic doesn’t have the pins necessary to connect with. (I flashed with the ARUDINO IDE as I wanted to select the WIFI AP mode and Enter a name for this NodeMCU as “powermeter“)
    **If using the Arduino IDE be sure not to use ESP8266 version 2.4.X I would downgrade to 2.3.0 for now (2018.09.09)
  • Make sure the PZEM-004 is disconnected or the switch is off. Using the picture on the back of the unit connect the PZEM RX -> NODEMCU TX and the PZEM TX-> NODEMCU RX pins.

That pretty much takes care of the physical connection.

  • Connect to the tasmota firmware at the IP address on your network
  • Set to generic
  • Set the pins you chose (in my case see below)
  • Enter the MQTT server info
PZEM004 tasmota home assistant
Node TX -> PZEM RX // Node  RX-> PZEM TX  and as for D7 the DHT-22 also known as the SI7021

And that should be it for Tasmota-NodeMCU (Wemos).

When switching on the power again, the PZEM and the USB powered NodeMCU should be working together and logging into the NodeMCU you should see the following. (WITHOUT THE TEMPERATURE INFO)

Home assistant power monitoring diy
The temperature info is not there without installing a DHT22

Next, how to extract the Tasmota’s PZEM004T information. Without any more steps the MQTT is receiving the following data.

How to check house power consumption

To find this out I got lucky as this NodeMCU was a former BRUH Multisensor. Checking the logs and was able to find the JSON code to extract this information. I tested many ways to get the information from the PZEM MQTT messages. In the end after I got my results I stumbled on this page. https://github.com/arendst/Sonoff-Tasmota/issues/1595

- platform: mqtt
    name: "Voltage"
    state_topic: "tele/sonoffpow/SENSOR"
    value_template: "{{ value_json['ENERGY'].Voltage}}"
    unit_of_measurement: "V"

By entering the above as MQTT entities the data will be properly extracted to Home Assistant.

Real time power usage hassio
After setting up a card this is what my setup looks like.

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.

Real time power consumption home assistant
“Teleperiod 10” for 10 second interval updates

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

Congrats the safe part is done.

Just FYI this seems to be a good link to check for bugs with the PZEM.  https://github.com/olehs/PZEM004T/issues

Part 2

Advertisements

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

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