arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.96k stars 4.77k forks source link

Adding support for PZEM004T energy monitor for 3 phase - request #2315

Closed roblad closed 4 years ago

roblad commented 6 years ago

Hi,

Is it possible add USE_PZEM004T and add support for PZEM004T Energy monitor for 3 phase by using USE_SERIAL_BRIDGE and report each phase through that functionality ? May be there is possibility to use 3 phase config for USE_PZEM004T as it is in that project:

https://github.com/apreb/eNode

sendorm commented 4 years ago

If 1 is not connected the code does not look for 2 and 3. The zero you are reading, when 2 and 3 is connected is the value of the absent 1 which is zero. Connect to the tasmota web page and check the values just after a restart. For a brief period you’ll see 0/220/220 then 0/220 and finally 0.

sheminasalam commented 4 years ago

ok..thanks..will check it out

sheminasalam commented 4 years ago

I have been using PZEM004t in 3 phase mode without issues for some time. I have connected it to my back power supply so that even when power cuts off, the device will be alive. But recently i noticed that as soon the power came back, the energy today reading is corrupted. I becomes more than 100 times the original value. This again affects the energy total. I have to manually Energyreset1 to set energy today zero to make it right. Why is it so? what is the solution?

Jason2866 commented 4 years ago

@sheminasalam energy values are non power failure proof. This is by design. Doing it in a different way would corrupt flash very fast because of the many needed writes to flash. If you need it more failsafe you have to setup a Home Automation hub where the values are stored in short intervals from tele message.

sheminasalam commented 4 years ago

@Jason2866 My PZEM004T are connected to my backup power supply so it wont be affected by any power failure. This device measures the power and other parameters of my mains which is three phase. In case of power failure, thus the device will be always on with my backup UPS and in theory the voltage , power utilization and all will be zero. And when the power comes back power utilizd values resumes from the point where it was left before power outage. This was what was happening till yesterday. From yesterday, after power supply is re-instigated, the energy today value becomes about 100-300 times the original value. This is only a recent phenomena and i dont know why?

arendst commented 4 years ago

Play with command SetOption72

sheminasalam commented 4 years ago

Setoption72 is not making any significant change. I had to do energyreset 1 to reset the value of today counter. But after that there reading was normal.

rflx18 commented 4 years ago

hi, is it possible to connect multiple pzems for different reading in one ESP8266?

jziolkowski commented 4 years ago

If you read this thread instead of lazily asking, you'll notice that this entire thread is about it, and yes, up to 3 pzem can be connected to tasmota

rflx18 commented 4 years ago

If you read this thread instead of lazily asking, you'll notice that this entire thread is about it, and yes, up to 3 pzem can be connected to tasmota

i did read it and tried to go without asking, i even tried to connect 2 pzem´s but the reading was only from one, that why i asked, is because i went in a dead end, i didnt find any how to regarding my question

jziolkowski commented 4 years ago

then read the thread again and look for command ModuleAddress

rflx18 commented 4 years ago

i did read it, but to be honest im not finding the answer :p

localhost61 commented 4 years ago

@rflx18 the thread is VERY long and lot's of comments are hidden, especially those related to ModuleAddress. You have to unfold them... The command was introduced 16 sept 2019

sheminasalam commented 4 years ago

I have been using PZEM004t in 3 phase mode without issues for some time. I have connected it to my back power supply so that even when power cuts off, the device will be alive. But recently i noticed that as soon the power came back, the energy today reading is corrupted. I becomes more than 100 times the original value. This again affects the energy total. I have to manually Energyreset1 to set energy today zero to make it right. Why is it so? what is the solution?

still having this issue, can anybody help?

bucsib commented 4 years ago

Hi Guys,

I need some help and almost a clarification. I built a 3 phase setup with Wemos D1 mini and 3pcs PZEM004T V3.0 with latest Tasmota. Look like its working fine even without the shottky diodes. I eliminated those because in my understanding the pzems are working with RS485 modbus, which communication basically doesn't need any diodes. The pzems are modified for 3V, Wemos powered with 5V and the pzems gets the 3V from the Wemos built in regulator. I can read all of the data, but...

Do you have any ideas for the three above questions? Thanks

Jason2866 commented 4 years ago

@bucsib without the diodes you WILL damage your hardware (sooner or later) Reason for restarts are the missing diodes.

bucsib commented 4 years ago

@Jason2866 OK, Its a trial setup, I have bunch of Wemos.

Please describe the need of the diodes in electrical language.

localhost61 commented 4 years ago

If you're not too clumsy with an iron, you'd better make your PZEM-004T 3.3V compliant, either replacing the Rx diode pullup (R17 on v2.0, R8 on v3.0) with 510Ω or adding 1kΩ in parallel but don't change the Tx transistor pullup (R15 on v2.0). That way you would not need an additional 5V power supply to only feed some optocouplers and could avoid those shottky diodes related in this thread. Just ask for pictures with "PZEM-004T 3.3V" in your favorite search engine. ;-) I have no hardware to test but Koshka's Blog seems a good resource.

Once 3.3v compliant, and assuming that PZEM interface is made of optocouplers that get their energy from the VDD you provide, I see no protective reason to keep the shottky diodes, the only concern is about TTL fan-out... The ESP Tx low level has to provide enough current to drive 3 optocouplers diodes (at 4mA) (+3 Rx monitoring diodes D3 on v3.0), it's looks heavy!

bucsib commented 4 years ago

@localhost61 Thanks, I thought the same regarding the shottkies. Pzems are still on 3.3V. Wemos is running from 5V cuz I have some nice and small 5V Ac/Dc converters what I would like to use. The 3.3V supply comes from a separate voltage regulator, I don't want to push extra load to the wemos built in 3.3V regulator. I have wemos clones. First one was terrible, 2nd a bit better. I will remove the LEDs from the 3 pzems to lower the current flow on the Rx/Tx pairs.

Will check tomorrow.

bucsib commented 4 years ago

I removed the 1-1 red LEDs from the boards next to the optocouples. Better but still not the best... And only pxem016 RX works for me. Couldn't get it work with the pzem004 RX serial config. Do you have any idea?

Edit: Dammit! Just realized, that I soldered the 1K resistor to the other optocouple... I'll rework it in the evening.

clifforddw commented 4 years ago

@sheminasalam I am having the exact same issues as you, I have a D1 mini connected to three power meters. The D1 is powered by a UPS so has no power interruptions.

When we have a power failure all is good Tasmota reports 0v and and 0w as expected but on return the "Energy Today" total spikes and sometimes Tasmota stops reporting any further consumption.

Secondly if the devices is rebooted the "Energy Today" returns to 0.

I am logging all the tele messages from the device. As can be seen in the graph below the Today value jumps straight after the power returns but the total sometimes reflects the jump but not always.

image

I am considering using send serial and Ned-Red to parse the actual modbus messages for while just to see where the issue arises from but if there is anyway I could assist with TASMOTA please let me know.

sheminasalam commented 4 years ago

@sheminasalam I am having the exact same issues as you, I have a D1 mini connected to three power meters. The D1 is powered by a UPS so has no power interruptions.

When we have a power failure all is good Tasmota reports 0v and and 0w as expected but on return the "Energy Today" total spikes and sometimes Tasmota stops reporting any further consumption.

Secondly if the devices is rebooted the "Energy Today" returns to 0.

I am logging all the tele messages from the device. As can be seen in the graph below the Today value jumps straight after the power returns but the total sometimes reflects the jump but not always.

image

I am considering using send serial and Ned-Red to parse the actual modbus messages for while just to see where the issue arises from but if there is anyway I could assist with TASMOTA please let me know.

I have found a solution for this using node red. Instead of taking the values of energy today and others directly from the mqtt messages, I have created virtual sensors in nodered and also flows to record the value of energy today when the voltage of the phases becomes zero. then when the power comes back node red will check if the value of today energy is more than 15 which is the max energy usage of mine daily. If it is so then the energy today is reset and the device is rebooted. Also the energy today is adjusted to include the value before power outage.

clifforddw commented 4 years ago

@sheminasalam I am having the exact same issues as you, I have a D1 mini connected to three power meters. The D1 is powered by a UPS so has no power interruptions. When we have a power failure all is good Tasmota reports 0v and and 0w as expected but on return the "Energy Today" total spikes and sometimes Tasmota stops reporting any further consumption. Secondly if the devices is rebooted the "Energy Today" returns to 0. I am logging all the tele messages from the device. As can be seen in the graph below the Today value jumps straight after the power returns but the total sometimes reflects the jump but not always. image I am considering using send serial and Ned-Red to parse the actual modbus messages for while just to see where the issue arises from but if there is anyway I could assist with TASMOTA please let me know.

I have found a solution for this using node red. Instead of taking the values of energy today and others directly from the mqtt messages, I have created virtual sensors in nodered and also flows to record the value of energy today when the voltage of the phases becomes zero. then when the power comes back node red will check if the value of today energy is more than 15 which is the max energy usage of mine daily. If it is so then the energy today is reset and the device is rebooted. Also the energy today is adjusted to include the value before power outage.

OK thanks for the idea I am still going to implement the raw modbus parser for a while just to see if the issue is the pzem or tasmota, will let you know.

sheminasalam commented 4 years ago

@sheminasalam I am having the exact same issues as you, I have a D1 mini connected to three power meters. The D1 is powered by a UPS so has no power interruptions. When we have a power failure all is good Tasmota reports 0v and and 0w as expected but on return the "Energy Today" total spikes and sometimes Tasmota stops reporting any further consumption. Secondly if the devices is rebooted the "Energy Today" returns to 0. I am logging all the tele messages from the device. As can be seen in the graph below the Today value jumps straight after the power returns but the total sometimes reflects the jump but not always. image I am considering using send serial and Ned-Red to parse the actual modbus messages for while just to see where the issue arises from but if there is anyway I could assist with TASMOTA please let me know.

I have found a solution for this using node red. Instead of taking the values of energy today and others directly from the mqtt messages, I have created virtual sensors in nodered and also flows to record the value of energy today when the voltage of the phases becomes zero. then when the power comes back node red will check if the value of today energy is more than 15 which is the max energy usage of mine daily. If it is so then the energy today is reset and the device is rebooted. Also the energy today is adjusted to include the value before power outage.

OK thanks for the idea I am still going to implement the raw modbus parser for a while just to see if the issue is the pzem or tasmota, will let you know.

keep me posted

clifforddw commented 4 years ago

@sheminasalam I have implemented a 3ph node-red parser using @adityama excellent work above.

I summary I am using Tasmota rules to send the serial commands to read the three phases every 10s and then parse the response with node red.

rule1 on System#Boot do RuleTimer1 20 endon on Rules#Timer=1 do backlog RuleTimer1 10; delay 1; SerialSend5 01040000000A700D; delay 1; SerialSend5 02040000000A703E; delay 1; SerialSend5 03040000000A71EF endon

I will now run it through a few power outages and let you know what I see.

One thing I did pick up is that when there is an outage tasmota drops off two of the phases, and since the three phase scan happens on startup it never finds them again without a power reboot.

sheminasalam commented 4 years ago

@clifforddw I have seen that this issues of ours doesnot occur always, infact i have seen that when the first phase is cut off with other two still on, the output of the tasmota is not correct. infact i think that there is some kind of dependency between the PZEOMs which i am not aware of.

clifforddw commented 4 years ago

Hi @sheminasalam update from my side.

Firstly @adityama i discovered a few bugs in your node-red code parsing out the serial data, the way you parse the the high and low order bytes was not correct . https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-Manual.pdf

Attached is the corrected node.

@sheminasalam I managed to log a power outage and return across all three phases, it seems like the PZEM total jumps after power return, but then corrects it in the following sample. My log showed it only happened across one of the phases the other two did not show the spike of the energy total metric.

image

Next I will look at the Tasmota code to see how it handles the samples.

flows.zip

ASL07 commented 4 years ago

I have a setup similar to this. But with several pzem sensors wired in parallel to the level shifter.

ESP8266 connected to a 3V3-5V level shifter, which then goes to the pzem sensors. The bus is working at 5V so I guess there is no need for protection diodes and we can wire the sensors directly: image

When several devices are connected to the same bus, then it doesn't work, the TX and RX pins on the pzem are always high. I only one device is in the bus, it works fine. Each sensor is configured with a different modbus address.

Has anyone had success with a similar setup as mine? @0x3333 @Jason2866 Why is there a need for a pullup resistor on the bus? Is the internal one on the ESP8266 not strong enough?

Thanks for your help

0x3333 commented 4 years ago

@ASL07 you can just replace the resistor on the PZEM to make it work with 3.3v... I just did on mine. Replace R17 resistor from 1K to 510R.

ASL07 commented 4 years ago

@0x3333 Thank you Ok, so if I replace R17 on pzem to 510R then the UART bus of the pzem will work at 3.3V, then I can power the pzem from the 3v3 pin on the Wemos? By doing this, I can skip protection diodes and pullup resistor? I am concerned also wether the Wemos voltage regulator of ESP8266 is able to drive several optocouplers from the 3v3 pin

0x3333 commented 4 years ago

nope. You power it with 3.3v. Diode is to not put a short circuit.

On 14 Apr 2020, at 05:56, a.santos notifications@github.com wrote:

 @0x3333 Thank you Ok, so if I replace R17 on pzem to 510R then the UART bus of the pzem will work at 3.3V, but I still have to power it with 5V right? By doing this, I can skip protection diodes and pullup resistor?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

IamStadam commented 4 years ago

Hi, guys!

Am I understand correctly? First I should use these commands in Tasmota console: SerialSend5 01040000000A700D SerialSend5 010600020002A9CB SerialSend5 02040000000A703E SerialSend5 020600020001E9F9 SerialSend5 010600020003680B SerialSend5 03040000000A71EF (it answers only: SerialSend: Done)

The second is the physical connection: Wemos D1 TX GPIO1 Serial TX (PZEM0XX TX (62)) ----> PZEM1-RX, PZEM2-RX, PZEM3-RX in parallel Wemos D1 TX GPIO3 Serial RX (PZEM016 RX (98)) ----> PZEM1-TX, PZEM2-TX, PZEM3-TX in parallel

PZEM v3.0 is used Somehow it doesn`t want to work...

ASL07 commented 4 years ago

@IamStadam Can you post details about your serial port configuration? I have a working setup similar to yours (but using esphome, not tasmota)

IamStadam commented 4 years ago

@ASL07 I described the configuration above. What exactly do you mean? I have nothing soldered, gave 5v to PZEMs. Wemos D1 has 3,3v. Tried to use devided connection D1, D2, D3 instead of GPIO3 (RX). I have a big doubt according these SerialSend5 commands. I simply copypased them one by one, and enter by enter :) Is this right?

ASL07 commented 4 years ago

Hi @IamStadam . Are you using baud rate 9600, and 1 stop bit? I think nothing is being returned by the device, so maybe your TX/RX are swapped... Did you try swapping them?

IamStadam commented 4 years ago

Hi @ASL07 After all manipulations, I can`t connect even ONE pzem! When the main page starts, it shows: Voltage 0/0/228 V (works as third)

after second Voltage 0/0 V

after two seconds Voltage 0 V

All the other states are the same. Where can I choose parameters of (rate 9600, and 1 stop bit) in Tasmota frimware?

upd: I found commands Baudrate and SerialConfig, set 9600 and 8N1. No luck Even the only PZEM starts like third, then main page shows "0" after a few seconds.

ASL07 commented 4 years ago

Are both RX and TX leds in the pzem blinking when you try to communicate with it?

IamStadam commented 4 years ago

When the Wemos starts the both are blinking, and the data recieved once. Then only RX blinking.

IamStadam commented 4 years ago

Victory! The original software helped. There is a possibility to change the address manualy. Simply connected every PZEM by USB TTL and set them up 1, 2, 3. The problem was that, all PZEMs were number 3. http://www.mediafire.com/file/lk5wukg2v5n5iry/004T_software%252Bdriver%252Buser_manual.zip/file

tomtzeng commented 4 years ago

help!! how to connect pzem-004t to split phase 3 wire system to measure total power consumption? 2 or 3 pzem-004t i need? Image 3

0x3333 commented 4 years ago

I used 3, one per phase.

1random commented 4 years ago

Hi all,

Assembled 3 phase PZEM-004T, changed addresses everything working fine except one note: After device restart, the only 1 phase detected, need to make 1 more restart of ESP to make visible all 3 phases, can you please advise how i can resolve this ? thanks!

image

1random commented 4 years ago

Hi all,

Assembled 3 phase PZEM-004T, changed addresses everything working fine except one note: After device restart, the only 1 phase detected, need to make 1 more restart of ESP to make visible all 3 phases, can you please advise how i can resolve this ? thanks!

image

Strange, made few restarts, working fine Before phases was without power for few hours, ESP board was working some time on UPS and then powered off and powered on with phases up state. In same time local interface was showing only 1 phase parameters without even slashes "/"

1random commented 4 years ago

Hi all, Assembled 3 phase PZEM-004T, changed addresses everything working fine except one note: After device restart, the only 1 phase detected, need to make 1 more restart of ESP to make visible all 3 phases, can you please advise how i can resolve this ? thanks! image

Strange, made few restarts, working fine Before phases was without power for few hours, ESP board was working some time on UPS and then powered off and powered on with phases up state. In same time local interface was showing only 1 phase parameters without even slashes "/"

Finally understood what happened, there are 3 PZEM-004T connected to 220V to 3 different Electric Phase ESP board which controls all 3 PZEM was powered via UPS Battery, on time of power outage all 3 PZEMs was powered off from 220V and probably was lost for ESP visibility, after power on back (all 3 Phases at once) device became alive but ESP board identified only 1 PZEM. After restart all 3 appeared again

Any suggestions ?

TrDA-hab commented 4 years ago

Now I'm starting to test this PZEM x3 phases ... PZEM v2 and PZEM v3 - cannot work simultaneously! For PZEM-004 v3 # 1 - to work, it must be connected to the same phase together with ESP8266! And PZEM-004 v3 # 1 - must always be connected or you will get the values 0/0/0!

Why is it necessary to use PZEM-016 for PZEM-004 v3 operation?

20200823_180740 20200828_181256 1 x3_PZEM-1 x3_PZEM-2

arendst commented 4 years ago

Why is it necessary to use PZEM-016 for PZEM-004 v3 operation?

Simply because PZEM-004 pre v3 is NOT using modbus but serial only. Therefore needing a different driver than PZEM-016 and PZEM-004 v3 (which seems to use modbus).

ASL07 commented 4 years ago

Why is it necessary to use PZEM-016 for PZEM-004 v3 operation?

Simply because PZEM-004 pre v3 is NOT using modbus but serial only. Therefore needing a different driver than PZEM-016 and PZEM-004 v3 (which seems to use modbus).

That is it, v3 uses modbus over UART, pre v3 uses a propietary protocol over UART, different than modbus

@TrDA-hab I like your ESP8266 adapter board, with power supply. Where did you get it?

TrDA-hab commented 4 years ago

@ASL07

Where did you get it?

I created this )

PZEM004-2 PZEM004-3

And i made this project 100% open to all. https://github.com/TrDA-hab/Projects/tree/master/PZEM%2BESP-01S

rt400 commented 4 years ago

I bought this module And it turns out that you can not connect more than one, at least for me it did not work. I tried with diodes and also without and it did not help he just reads the first one. Anyone have experience with this model?

TrDA-hab commented 4 years ago

@rt400 It works for me (and not only), if you need advice, please contact the Tasmota Discord chat room for a discussion: https://discordapp.com/invite/Ks2Kzd4