
Energy measurement with espeasy and pzem-004t
Moderator: leecollings
-
- Posts: 9
- Joined: Wednesday 21 February 2018 19:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
More information about the connection PZEM-004T :


-
- Posts: 317
- Joined: Thursday 12 January 2017 15:30
- Target OS: Linux
- Domoticz version: Beta Ch
- Location: Finland
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Yeah ok, so this is not ideal for computing one devices energy usage(without braking its cable), shame :/
But, i would still prefer clamp. Using clamp i wouldnt need to take wire off from main electric box to fit it in to wire.
But, i would still prefer clamp. Using clamp i wouldnt need to take wire off from main electric box to fit it in to wire.
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
-
- Posts: 9
- Joined: Wednesday 21 February 2018 19:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Hi, aleph0aleph0 wrote: ↑Tuesday 13 March 2018 21:44 Hi ! The PZEM-004T is in the "testing" mode, and I'm pretty sure we didn't port it to the 2018-03-13 version. I might try to compile it for this version on week-end, but won't have any hardware to test it anymore :/ Or you can use our development version here https://www.letscontrolit.com/forum/vie ... =30#p21383
Did you have time to compile a newer version? ))
-
- Posts: 317
- Joined: Thursday 12 January 2017 15:30
- Target OS: Linux
- Domoticz version: Beta Ch
- Location: Finland
- Contact:
Re: Energy measurement with espeasy and pzem-004t
On which device name ? Just did install latest sonoff-tasmota, but cannot find pzem under devices ?
I can see it enabled in config.user, but its not in devices list ? Is it supported only through sonoff device ?
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
-
- Posts: 85
- Joined: Thursday 12 May 2016 15:47
- Target OS: Linux
- Domoticz version: 11838
- Location: South of France
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Ok then ! Here it is in version 2018-03-26, tell us what

http://megzou.freeboxos.fr/photos/domot ... re.bin.zip
I expect some problems because I recompiled it against the ESPeasySoftwareSerial provided in the 2018-03-26 to avoid duplicating the libraries, but it's not the version recommended by the original author of the plugin. So let's try and see !
Last edited by aleph0 on Saturday 14 March 2020 10:31, edited 1 time in total.
-
- Posts: 317
- Joined: Thursday 12 January 2017 15:30
- Target OS: Linux
- Domoticz version: Beta Ch
- Location: Finland
- Contact:
Re: Energy measurement with espeasy and pzem-004t
JST 2.5 XH 4-Pin Connector Plug
That seems to be the connector that fits to white 4pin connector on pzem.
That seems to be the connector that fits to white 4pin connector on pzem.
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
-
- Posts: 1
- Joined: Sunday 01 April 2018 18:52
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Hello,
Today I tried to setup PZEM-004t with domoticz but without success.
I received this error in domoticz log:
2018-04-01 20:00:49.208 Error: EventSystem: in pzem1: [string "--[[Script to read infos from espeasy/pzem-00..."]:42: bad argument #1 to 'match' (string expected, got nil)

Can you please tell me how can solve the issue?
Regards
PS. I solved the issue with domoticz update.
Today I tried to setup PZEM-004t with domoticz but without success.
I received this error in domoticz log:
2018-04-01 20:00:49.208 Error: EventSystem: in pzem1: [string "--[[Script to read infos from espeasy/pzem-00..."]:42: bad argument #1 to 'match' (string expected, got nil)

Can you please tell me how can solve the issue?
Regards
PS. I solved the issue with domoticz update.
-
- Posts: 11
- Joined: Monday 05 March 2018 22:54
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Hello everybody,
My energy measurement is operationnal by following this post and this one https://www.letscontrolit.com/forum/vie ... f=5&t=2595.
I use an ESP8266_4096.
But I have a problem :
- if I boot my ESP connected to the PZEM. My ESP doesn't start (no effect if I push on RESET button),
- If I boot my ESP (not connected to the PZEM), this one start normaly and after i can connect the PZEM to the ESP and the Energy measurement is OK.
This problem is painful because if i have a power cut, my Energy measurement does not restart.
Can you help me ?
Thanks in advance.
My energy measurement is operationnal by following this post and this one https://www.letscontrolit.com/forum/vie ... f=5&t=2595.
I use an ESP8266_4096.
But I have a problem :
- if I boot my ESP connected to the PZEM. My ESP doesn't start (no effect if I push on RESET button),
- If I boot my ESP (not connected to the PZEM), this one start normaly and after i can connect the PZEM to the ESP and the Energy measurement is OK.
This problem is painful because if i have a power cut, my Energy measurement does not restart.
Can you help me ?
Thanks in advance.
-
- Posts: 85
- Joined: Saturday 14 January 2017 21:34
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Thanks for this great job,
but I don't understand how link pzem004 to the power (I mean physical connection).
Thanks
but I don't understand how link pzem004 to the power (I mean physical connection).
Thanks
Raspberry PI 3, 3x Yeelight bulbs, 1x Yeeligh led strip, 1x Sonoff with ESP826, Controlicz, Kodi
-
- Posts: 11
- Joined: Monday 05 March 2018 22:54
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
I modified the GPIO pin : GPIO-12 and 13 instead of GPIO-14 and 15 and all is OK.Dim33 wrote: ↑Wednesday 29 August 2018 0:14 Hello everybody,
My energy measurement is operationnal by following this post and this one https://www.letscontrolit.com/forum/vie ... f=5&t=2595.
I use an ESP8266_4096.
But I have a problem :
- if I boot my ESP connected to the PZEM. My ESP doesn't start (no effect if I push on RESET button),
- If I boot my ESP (not connected to the PZEM), this one start normaly and after i can connect the PZEM to the ESP and the Energy measurement is OK.
This problem is painful because if i have a power cut, my Energy measurement does not restart.
Can you help me ?
Thanks in advance.
-
- Posts: 66
- Joined: Tuesday 19 April 2016 23:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Could be better use ESPEASY rules to split and send data to Domoticz
on Energy#Current do
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=30&nvalue=0&svalue=[Energy#Voltage]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=31&nvalue=0&svalue=[Energy#Current]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=[Energy#ActivePower]
endon
on Energy#Current do
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=30&nvalue=0&svalue=[Energy#Voltage]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=31&nvalue=0&svalue=[Energy#Current]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=[Energy#ActivePower]
endon
Fronius plugin
https://github.com/ayasystems/froniusHttp
Solax plugin
https://github.com/ayasystems/SolaxHTTP
Openevse plugin
https://github.com/ayasystems/OpenEVSEPlugin
https://github.com/ayasystems/froniusHttp
Solax plugin
https://github.com/ayasystems/SolaxHTTP
Openevse plugin
https://github.com/ayasystems/OpenEVSEPlugin
-
- Posts: 85
- Joined: Thursday 12 May 2016 15:47
- Target OS: Linux
- Domoticz version: 11838
- Location: South of France
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Right ! Much better solution
Thanks for pointing this out

- sincze
- Posts: 1300
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: Energy measurement with espeasy and pzem-004t
I started with this pzem-004t as well, but due to some posts regarding it's safety I switched to POW R2, however some nice things to know.
To avoid 'spamming' domoticz you could add a virtual device as well.. store the 'on change' values in that device.. and send the data (if changed) to domoticz every 30 sec or so. Great examples on the website: https://www.letscontrolit.com/forum/vie ... =50#p30912
Examples:
To avoid 'spamming' domoticz you could add a virtual device as well.. store the 'on change' values in that device.. and send the data (if changed) to domoticz every 30 sec or so. Great examples on the website: https://www.letscontrolit.com/forum/vie ... =50#p30912
Examples:
- Spoiler: show
- Spoiler: show
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
-
- Posts: 69
- Joined: Friday 14 November 2014 9:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
I want to push the data of the pzem script into influxdb, but this doesn't work.
After som reading on the wiki I found out that i should use JSON API to update my Dummy sensors in stead of ['UpdateDevice'], how can i change this?
Domoticz wiki:
Note to Virtual / Dummy sensors: If the HTTP link or MQTT is not sending any values to the database, check the update method of your virtual sensors in your scripts. If using the ['UpdateDevice'] method, you will directly write the value to the internal database without triggering an HTTPlink or MQTT update for this sensor. Better is to use the JSON API of Domoticz and update your virtual sensors this way.
An alternative is to use ESPEASY but i don´t no how to do this
After som reading on the wiki I found out that i should use JSON API to update my Dummy sensors in stead of ['UpdateDevice'], how can i change this?
Domoticz wiki:
Note to Virtual / Dummy sensors: If the HTTP link or MQTT is not sending any values to the database, check the update method of your virtual sensors in your scripts. If using the ['UpdateDevice'] method, you will directly write the value to the internal database without triggering an HTTPlink or MQTT update for this sensor. Better is to use the JSON API of Domoticz and update your virtual sensors this way.
An alternative is to use ESPEASY but i don´t no how to do this

ayasystems wrote: ↑Wednesday 19 September 2018 14:25 Could be better use ESPEASY rules to split and send data to Domoticz
on Energy#Current do
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=30&nvalue=0&svalue=[Energy#Voltage]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=31&nvalue=0&svalue=[Energy#Current]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=[Energy#ActivePower]
endon
-
- Posts: 3
- Joined: Saturday 18 February 2017 16:40
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Piacco!
1. In ESP EASY go to Tools-Advanced and enable Rules.
2. In ESP EASY go to your pzem device set name pzem1
3. In ESP EASY set Values as on pic: 4. In ESP EASY go to Rules tab and place in text field:
do not forget to change IP, Port and IDX of each device.
1. In ESP EASY go to Tools-Advanced and enable Rules.
2. In ESP EASY go to your pzem device set name pzem1
3. In ESP EASY set Values as on pic: 4. In ESP EASY go to Rules tab and place in text field:
Code: Select all
on pzem1#Current do
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=30&nvalue=0&svalue=[pzem1#Voltage]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=31&nvalue=0&svalue=[pzem1#Current]
SendToHTTP 192.168.0.100,8080,/json.htm?type=command¶m=udevice&idx=32&nvalue=0&svalue=[pzem1#Power]
endon
Re: Energy measurement with espeasy and pzem-004t
Hello and thank you for the nice "How to".
I did it and it is working.
Seems to work properly, I also included the ">0" mod.
I have only one observation: the "Current" value is showing the last maximum current.
I wonder if someone can help me with LUA script to make the "Current" show the "now" value of the current.
Thank you and please forgive my stupidity.
LE. I think I got it like this:
if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V)
UpdateDev(dev_A,0,val_A) end
-- if tonumber(val_A)>0 then UpdateDev(dev_A,0,val_A) end--
I did it and it is working.
Seems to work properly, I also included the ">0" mod.
I have only one observation: the "Current" value is showing the last maximum current.
I wonder if someone can help me with LUA script to make the "Current" show the "now" value of the current.
Thank you and please forgive my stupidity.
LE. I think I got it like this:
if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V)
UpdateDev(dev_A,0,val_A) end
-- if tonumber(val_A)>0 then UpdateDev(dev_A,0,val_A) end--
Re: Energy measurement with espeasy and pzem-004t
Can anyone help me to relate the costs of energy with the Elec happy switch?
I do have T1 and T2 energy on the Energy report... T1 is with Elec Happy switch OFF and T2 with switch ON?
Thank you,
Adrian
I do have T1 and T2 energy on the Energy report... T1 is with Elec Happy switch OFF and T2 with switch ON?
Thank you,
Adrian
-
- Posts: 85
- Joined: Thursday 12 May 2016 15:47
- Target OS: Linux
- Domoticz version: 11838
- Location: South of France
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Yes, it's exactly add you said
Envoyé de mon moto g(6) en utilisant Tapatalk
Envoyé de mon moto g(6) en utilisant Tapatalk
-
- Posts: 11
- Joined: Monday 05 March 2018 22:54
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Hello,
I used the script (page 1) since one year and all is OK but I would like displayed also (as active power) :
- Reactive power (P=UxI)
- Reactive Energy consumption
Is it possible to modify the script to update two additionnal virtual sensors ?
Thanks.
I used the script (page 1) since one year and all is OK but I would like displayed also (as active power) :
- Reactive power (P=UxI)
- Reactive Energy consumption
Is it possible to modify the script to update two additionnal virtual sensors ?
Thanks.
-
- Posts: 4
- Joined: Tuesday 09 October 2018 20:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Contact:
Re: Energy measurement with espeasy and pzem-004t
Can you please show full script and how it's runyo3hjv wrote: ↑Thursday 25 April 2019 4:22 Hello and thank you for the nice "How to".
I did it and it is working.
Seems to work properly, I also included the ">0" mod.
I have only one observation: the "Current" value is showing the last maximum current.
I wonder if someone can help me with LUA script to make the "Current" show the "now" value of the current.
Thank you and please forgive my stupidity.
LE. I think I got it like this:
if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V)
UpdateDev(dev_A,0,val_A) end
-- if tonumber(val_A)>0 then UpdateDev(dev_A,0,val_A) end--

Who is online
Users browsing this forum: No registered users and 0 guests