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.71k stars 4.72k 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

rt400 commented 5 years ago

@0x3333 why not ? its looks that we can change the variable names ...no ?

0x3333 commented 5 years ago

@rt400 thats not the problem, the problem is that it takes to much time waiting... anyway, give it a try...

rt400 commented 5 years ago

@0x3333 i wish iknow how to do . i dont have any problem to check it.. but a dont know how to recoding the driver for that

rt400 commented 5 years ago

i seems now that in tasmota have only 1 TX and many RX..

0x3333 commented 5 years ago

Hi everyone. I implemented this feature in Espurna Firmware, but probably easy to implement in Tasmota.

I didn't created a PR yet, but will create soon. Here is the Espurna version.

https://github.com/0x3333/espurna/blob/multipzem/code/espurna/sensors/PZEM004TSensor.h

0x3333 commented 5 years ago

The sensor reads constantly the devices and cache the readings, when the firmware asks for a reading it returns the last one.

Probably there is a difference in reading, but no more than 20miliseconds. I do the same magnitudes at once, all voltages, then all currents and so on...

rt400 commented 5 years ago

@0x3333 hi.. i try your code but still no work.. i don't like espurna..so conflity.. there is chance for implement in Tasmota.?

0x3333 commented 5 years ago

Well, I don't use Tasmota anymore... Don't have the time to implement, the energy driver is so complex, with several devices in the same file that the time to understand it doesn't worth.

rt400 commented 5 years ago

@0x3333 ok.. can you explain he how to make espurna firmware bin file for the 3 phaze ? because i didnt undertsatnd how it is work..

0x3333 commented 5 years ago

Just build it, https://github.com/xoseperez/espurna/wiki/Build-and-update-from-Visual-Studio-Code-using-PlatformIO

andrethomas2 commented 5 years ago

Closing this one for now until one of the dev's have time to work on it.

adityama commented 5 years ago

I mean plugging all the 3 PZEM in the same hardware/soft serial, like this:

smms_ttl

The diode can be a BAT45, the pullup resistor can be a 10K to 5V.

But you need to program the PZEM address before using this method, the address can be sequential, like 0.0.0.1,0.0.0.2,0.0.0.3, it is not really a IP address.

But the tasmota must be changed to accommodate multiple meters, you can test using an arduino.

I was struggling to find a way to do the same. Finally I found a simple solution to poll 3 pzem004Ts with Tasmota (without changing anything to the code).

I am using PZEM004T v3.0 modules that are using Modbus-RTU. I connected 3 pzem004 modules to ESP01 UART as per your diagram. In the ESP01 generic module (18) configuration I used serialBridge TX, RX (not PZEMxxx). I set all three modules to different addresses 01, 02, 03.

Then I used SerialSend5 to send read request to module 01. It returned hex data with all the values (in hex) voltage, current and so on. Same data is send over mqtt. I configured my node-red to poll each pzem004 every 6 seconds and processed received hex data to extract required values. Currently I am using it for 3 phases with three pzem modules. However I believe I could add more modules to it.

I have few pzem004T v1.0 modules lying around. Next thing I will use same method to read them. This needs different reading methods. The only drawback with this method is that you don't get the Tasmota Web UI to display the readings.

clifforddw commented 4 years ago

@adityama could you share your node red flow with us, trying to do something very similar.

adityama commented 4 years ago

@adityama could you share your node red flow with us, trying to do something very similar.

Yeah sure. Use the attached flows. Just note, I am using PZEM004T v3.0 MODBUS-RTU modules.

let me know if you have any questions regarding the node-red flows. 3ph-mains-flows.zip

adityama commented 4 years ago

@clifforddw I hope the node-red sample was useful for you.

klotzma commented 4 years ago

I mean plugging all the 3 PZEM in the same hardware/soft serial, like this: smms_ttl The diode can be a BAT45, the pullup resistor can be a 10K to 5V. But you need to program the PZEM address before using this method, the address can be sequential, like 0.0.0.1,0.0.0.2,0.0.0.3, it is not really a IP address. But the tasmota must be changed to accommodate multiple meters, you can test using an arduino.

I was struggling to find a way to do the same. Finally I found a simple solution to poll 3 pzem004Ts with Tasmota (without changing anything to the code).

I am using PZEM004T v3.0 modules that are using Modbus-RTU. I connected 3 pzem004 modules to ESP01 UART as per your diagram. In the ESP01 generic module (18) configuration I used serialBridge TX, RX (not PZEMxxx). I set all three modules to different addresses 01, 02, 03.

Then I used SerialSend5 to send read request to module 01. It returned hex data with all the values (in hex) voltage, current and so on. Same data is send over mqtt. I configured my node-red to poll each pzem004 every 6 seconds and processed received hex data to extract required values. Currently I am using it for 3 phases with three pzem modules. However I believe I could add more modules to it.

I have few pzem004T v1.0 modules lying around. Next thing I will use same method to read them. This needs different reading methods. The only drawback with this method is that you don't get the Tasmota Web UI to display the readings.

Sure you did that with version 3, because that's a Modbus protocol. In my manual of PZEM 004t V3 are commands such as 0x0000, 0x0001 and so on ... I did it the way you tried with for example "SerialSend5 B0 C0 A8 01 01 00 1A" but he does not answer.

adityama commented 4 years ago

I am not sure if I understood why you have used different serial commands with v3. If your pzem module has white color opto couplers, you surely have same module as mine.

klotzma commented 4 years ago

Yes I have the ones with the white optocouplers. How did you send the commands via SerialSend5? Do you have examples? Maybe I typed it wrong

adityama commented 4 years ago

Try step by step. Connect only one PZEM (considering this has default address) and send following string - 01040000000A700D You can use Inject node as I have done in my flow that I shared earlier. If you get response, the method works. Next you need to change address of the other two PZEM modules and use the respective strings as in my node-red flows. I have shared my node-red flows in an earlier post in the same thread.

rt400 commented 4 years ago

Yes I have the ones with the white optocouplers. How did you send the commands via SerialSend5? Do you have examples? Maybe I typed it wrong

you should send command : SSerialSend5 not SerialSend5 cause you use with software serial

adityama commented 4 years ago

Since I was using HW serial, I used SerialSend5. This works from the consoele as well.

rt400 commented 4 years ago

Since I was using HW serial, I used SerialSend5. This works from the consoele as well.

OK. for me the SSerialSend5 work. can you tell me how you config the ip for each model ?

adityama commented 4 years ago

I used console to send hex string to program each module one by one. I picked it from the manual that comes with the module. This should be easy to create string for each module, just be careful while calculating modbus checksum.

adityama commented 4 years ago

even better - I found my notes - use these to change the address of modules - read the device 01

SerialSend5 01040000000A700D 15:04:17 MQT: tele/upsPW/RESULT = {"SerialReceived":"010414096600000000000000000005000001f500000000ed0d"}

set address of device 01 to 02

SerialSend5 010600020002A9CB

response -- 15:17:07 MQT: tele/upsPW/RESULT = {"SerialReceived":"010600020002a9cb"}

read device 02 SerialSend5 02040000000A703E

set address of device 02 to 01 SerialSend5 020600020001E9F9

response - - 15:19:35 MQT: tele/upsPW/RESULT = {"SerialReceived":"020600020001e9f9"}

set address of device 01 to 03 SerialSend5 010600020003680B

read device 03 SerialSend5 03040000000A71EF

let me know if these work for you.

rt400 commented 4 years ago

even better - I found my notes - use these to change the address of modules - read the device 01

SerialSend5 01040000000A700D 15:04:17 MQT: tele/upsPW/RESULT = {"SerialReceived":"010414096600000000000000000005000001f500000000ed0d"}

set address of device 01 to 02

SerialSend5 010600020002A9CB

response -- 15:17:07 MQT: tele/upsPW/RESULT = {"SerialReceived":"010600020002a9cb"}

read device 02 SerialSend5 02040000000A703E

set address of device 02 to 01 SerialSend5 020600020001E9F9

response - - 15:19:35 MQT: tele/upsPW/RESULT = {"SerialReceived":"020600020001e9f9"}

set address of device 01 to 03 SerialSend5 010600020003680B

read device 03 SerialSend5 03040000000A71EF

let me know if these work for you.

i dont understand "set address of device 01 to 02" ? and after you set "set address of device 02 to 01" ?

adityama commented 4 years ago

each module that comes from factory has default address 01. In my notes i have mentioned what hex string you need to send to the module to change address from 01 to 02 or 03. Similarly I have noted the hex string to revert back address from 02 to 01 - you dont have to do this - this was just part of my notes as did this operation as an experiment. Key point is you need 3 modules with different address - 01, 02, 03. Each one will be polled using unique hex string.

rt400 commented 4 years ago

@adityama thanks. now its working.. now i try to understand the electric schema , i see that i need to connect a ressitor to TX with 5V? what about the VCC , no need to connect ?

adityama commented 4 years ago

Actually, I just let it run with 5v rather than 3.3v. since over 3 months my setup is working fine. If you to run it on 3.3v, you will need to add 1k resister.

Cheers Aditya

On Mon, 9 Sep, 2019, 3:30 PM Yuval, notifications@github.com wrote:

@adityama https://github.com/adityama thanks. now its working.. now i try to understand the electric schema , i see that i need to connect a ressitor to TX with 5V? what about the VCC , no need to connect ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arendst/Sonoff-Tasmota/issues/2315?email_source=notifications&email_token=ACEHVVOS5K4OTX6ZOQANXSLQIYNFHA5CNFSM4EYK56K2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6G635Q#issuecomment-529395190, or mute the thread https://github.com/notifications/unsubscribe-auth/ACEHVVNB5CSLPTC4HWFUIF3QIYNFHANCNFSM4EYK56KQ .

rt400 commented 4 years ago

@adityama but he connect 10K to TX not to VCC... i try this without the resistor VCC got 5v and the TX connect with IN4007 Diode but its seems that the received data wont come . i see the TX led flash so i think the model send data.. other issue , tasmota send this before the received data :

stat/upsPW/RESULT = {"SSerialSend":"Done"}

maybe that the problem ?

meingraham commented 4 years ago

Note that there is the PZEM-004T V1 version and the V3 version. The V3 is MODBUS. The V1 is not. Perhaps this is causing some of the difference in behavior regarding the received data?

rt400 commented 4 years ago

@meingraham i know the different between them. its looks that the diode that i use not work with this. he said to use with BAT45 and i used with IN4007 , i don't know what the diffrents. i going to remove the diodes and connect the TX together directly and see whats happen

rt400 commented 4 years ago

ok i got it works ..its work without the diodes.. When it runs with the connected diodes I would see the TX LED flash every time on somewhere else and never together, when I connect without the diodes then the TX LEDs light flashing together when transmitting information which suspects me that the information may be incorrect or only from one module. now i need to work to send it to HA.. many thanks @adityama

meingraham commented 4 years ago

@rt400

Great to hear.

Would you mind summarizing the (successful) steps you took to get it to work. List your parts, the connections, the configuration, etc. I'd like to add an article to the Tasmota wiki.

Regards.

Mike

roguestreak commented 4 years ago

@rt400, did your issue perhaps have something to do with the following note from the manufacturer, PeaceFair?

Special note: The TTL interface of this module is a passive interface, which requires external 5V power supply. That is to say, all four ports must be connected (5V, TX, TX, GND) when communicating, otherwise they cannot communicate.

PS. great work @adityama ! I'm about to order a new V3 with split CT to do some testing, if it works out I might retrofit to each of the circuits in my house. Big test will be whether or not it can detect, when installed on the main link to the grid, whether I'm actually importing or exporting power; "supposedly" hacking into pin 51 of the main chip (SDIC SD3004) will flag when current and voltage are greater than 90 degrees out of phase, which "supposedly" will indicate you are exporting power to the grid. Such info seems EXTREMELY hard to verify via google, some say exports will be 180 degrees out of phase but I'm yet to find a verified technical explanation of how exactly you export back into the grid to confirm this is the case! Unfortunately my digital meter doesn't have any indicator LED for "export", the IMP LED simply flashes the same per kW whether it's importing or exporting.

Pin 51 hack detailed: https://github.com/apreb/eNode

adityama commented 4 years ago

I doubt if IN4007 will work in this application. You need a fast switching diode with small forwarding voltage drop. BAT45/85 will work here. You can give a shot with IN4148 too, it is faster than 4007 but fwd drop is more.

Cheers Aditya

On Mon, 9 Sep, 2019, 10:09 PM Yuval, notifications@github.com wrote:

@meingraham https://github.com/meingraham i know the different between them. its looks that the diode that i use not work with this. he said to use with BAT45 and i used with IN4007 , i don't know what the diffrents. i going to remove the diodes and connect the TX together directly and see whats happen

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arendst/Sonoff-Tasmota/issues/2315?email_source=notifications&email_token=ACEHVVKWKO33H3KW7XXG7ATQIZ347A5CNFSM4EYK56K2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6IIFEA#issuecomment-529564304, or mute the thread https://github.com/notifications/unsubscribe-auth/ACEHVVMIRUHR6GOHVNCTHMDQIZ347ANCNFSM4EYK56KQ .

rt400 commented 4 years ago

@adityama OK now i understand why with this diode i didn't get the info.. i will buy bat85/45 and check with it

rt400 commented 4 years ago

@rt400

Great to hear.

Would you mind summarizing the (successful) steps you took to get it to work. List your parts, the connections, the configuration, etc. I'd like to add an article to the Tasmota wiki.

Regards.

Mike

well when i finish amd it will be run good i will share it . do you know that it run with NODERED flow that filtered the data? maybe tasmota can do it on there code also..

zfubar86 commented 4 years ago

Hey, i'm also in the process of wiring up 3 pzem004t to monitor a 3phase circuit. I have a few questions if you guys could help.

  1. If i'm monitoring 3 phases, do I need each phase to power 1 pzem? Or can i power all 3 and a wemos from the same phase?
  2. How are you protecting your circuits? Do the pzem have incorporated fuses? Should i have an external fuse?

Thanks!

klotzma commented 4 years ago
  1. Since all 3 phases have voltage fluctuations and frequency fluctuations, depending on which phase you want to measure, you must also connect the voltage from this phase. Otherwise the measurement is too inaccurate.

  2. you should install a fuse for the PZEM modules, as far as I know have no protection installed.

Furthermore, as a further safety notice, you should always short-circuit the current transformers if you have not connected them to the pzem module yet.

arendst commented 4 years ago

For all of you triple PZEM users I finally made the energy monitoring ready for three phase/channel support.

All I have to do now is update the PZEM drivers with ability to monitor up to three PZEMs on ONE serial/modbus connection.

From the discussion here I understand you managed to do that already using SerialSend.

As a test I'll update the PzemAc (modbus) driver with fixed addresses 01, 02 and 03 to let you test it's functionality.

rt400 commented 4 years ago

@arendst wow!!! finally.. i am ready to test it!! just let me know

arendst commented 4 years ago

Give it a try!

jziolkowski commented 4 years ago

Which versions of -004T are supported?

arendst commented 4 years ago

I changed both -004T and modbus versions so all should be supported.

jziolkowski commented 4 years ago

Fantastic. How to configure the .2 and .3 address for the extra devices? I haven't been able to d/l the latest firmware yet...

arendst commented 4 years ago

Not supported by Tasmota directly but using the SerialSend commands as documented in this issue thread.

jziolkowski commented 4 years ago

Oh that's great. Will give it a shot, as I've been waiting for this feature for a LONG time.

rt400 commented 4 years ago

@arendst can you tell me how did you connect the 3 modules? and what ip need it for them ?

jziolkowski commented 4 years ago

@rt400 see Theo's comment above. 0.0.0.1, 0.0.0.2, 0.0.0.3, you need to install the PZEM one by one and configure their addresses (for device 2 and 3, because by default PZEM has 0.0.0.1)

Jason2866 commented 4 years ago

Wiring https://github.com/arendst/Sonoff-Tasmota/issues/2315#issuecomment-384643624 How to set address is explained here https://github.com/arendst/Sonoff-Tasmota/issues/2315#issuecomment-527894673