AS THIS IS THE MOST IN DEMAND ENTRY. I’M CONSTANTLY UPDATING IT.
IF YOU HAVE ANY QUESTIONS PLEASE ASK.
- 2019.06.03: This setup has been rock solid for over a year without any changes. 👌
- 2019.05.05: Commenter SeByDocKy provided a work around listed below for quicker timing that the 10 second minimum tasmota offers.
- 2019.04.26: from Sendorm is a cleaner way to power the system without a separate usb power adapter
- 2019.04.16:To simplify the process of the code below I have put it online at https://github.com/halfforked/PowerMeter/tree/master
- 2018.09.09 – Post split in multiple pieces see part 2 as well
ALTERNATIVES* (added 2019.03.02)
- This is an Energy meter (for a single device?) but the principle is the same. Note the if you try this you’ll NEED a SPLIT COIL instead. https://github.com/arendst/Sonoff-Tasmota/wiki/PZEM004T,-Wemos-D1-Mini-and-a-1602-I2C-display
- SMART METER: if you have a smart meter then things may get much easier for you. https://cloudenius.com/2018/08/04/use-smart-energy-meter-with-home-assistant/
- PRE-BUILT/service – 3 phase: https://efergy.com/engage-online-monitoring/ (unsure about integration in Home Assistant)
- PRE-BUILT/service: https://openenergymonitor.org/ (unsure about integration in Home Assistant)
- There is a suggestion for a 3 phase system on https://community.home-assistant.io/t/whole-house-power-monitoring-single-phase-for-under-30/68793/15
The standard disclaimer: Please do not attempt anything seen here if you’re not comfortable with breakers and mains power.
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]
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)
- 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)
UPDATE 2019.04.26 from Sendorm
One thing to add, I am powering the pzem-004t TTL from the nodemcu VU pin and it is working perfectly. It seems a separate usb power adapter is not necessary after all.
- 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)
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.
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) link
- 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
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)
Next, how to extract the Tasmota’s PZEM004T information. Without any more steps the MQTT is receiving the following data.
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
UPDATE 2019.04.16: To simplify the process of the code below I have put it online at https://github.com/halfforked/PowerMeter/tree/master
By entering the above as MQTT entities the data will be properly extracted to Home Assistant.
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 usable. By entering “Teleperiod 10” to update every 10 seconds.
UPDATE 2019.05.05: If “Teleperiod 10” for 10 second interval updates is still too slow for your liking there is the possibility to update the Tasmota code as commenter SeByDocKy
Finally, I recompiled the last tasmota firmware and made the two following changes in the sonoff.ino (around line 1204)if ((payload >= 0) && (payload 0) && (Settings.tele_period < 10)) Settings.tele_period = 10; // Do not allow periods < 10 secondsWorks fine for Teleperiod 1
SeByDocKy‘s link: see the comments (I didn’t have time to test it myself, see comments for any issues that may arise)
This is an interesting workaround. However having said that I will be leaving the tasmota code untouched for the time being as 10 seconds doesn’t bother me so much. Plus I’m curious as to why there would be a 10 second minimum in tasmota in the first place. Long term usage to be the final test perhaps.
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