Connect pzem-004t and pzem-017 to same controller

725 views
Skip to first unread message

Khurram

unread,
Sep 22, 2023, 7:48:25 AM9/22/23
to TasmotaUsers
At the moment, I don't think it is possible to connect both the pzem-004t and pzem-017 to the same controller (esp8266/esp32 based).  I would like to measure both the DC battery voltage+current and AC voltage+current from an inverter without using 2 esp controllers. I cannot find anything in the web interface as there is just 1 PZEM Tx gpio setting. Is it possible to edit the code to support Tx separately for the 2 pzems?

Thanks

Philip Knowles

unread,
Sep 22, 2023, 8:00:36 AM9/22/23
to Khurram, TasmotaUsers

You may be able to using RS485 (PZEM-016). Someone used it for 3 phase. Try looking in the Projects pages.

 

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/bdd9da84-774f-43c2-b92e-495ee37b8862n%40googlegroups.com.

 

Andrew L

unread,
Sep 23, 2023, 3:30:12 AM9/23/23
to TasmotaUsers
If the PZEM-017 is similar in communication style to the 004, I think you should be able to use scripting and treat each of them as a smart meter.  Or just use the PZEM-004 as a smart meter, and define the 017 traditionally. https://tasmota.github.io/docs/Smart-Meter-Interface/#peacefair-pzem004tv30-modbus

However, worth bringing up on Github as a feature request.  Seems worthy of consideration, but I don't know how much coding would be involved. 

Philip Knowles

unread,
Sep 23, 2023, 4:06:32 AM9/23/23
to Andrew L, TasmotaUsers
The protocols are different 004 uses RS232 016/7 use RS485. In theory there's nothing to stop you using separate GPIOs for each device (but suspect it might not work).
There is a (long) thread of something similar.


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Andrew L <pkkr...@gmail.com>
Sent: Saturday, September 23, 2023 8:30:12 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Connect pzem-004t and pzem-017 to same controller
 
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Khurram

unread,
Sep 28, 2023, 8:00:56 AM9/28/23
to TasmotaUsers
The (very long) tasmota thread mentioned in the previous post holds an answer which works great for my purpose. @adityama suggested using serialbridge in tasmota to poll the pzem (in fact, he is polling 3 pzems for 3 phase AC monitoring) and transform the result in a nodered flow. This is a great solution to my problem. He describes his solution here, the serialbridge commands are here and the nodered flow is here. I could not get software serialbridge commands to work on my esp8266 nodemcu controller, but hardware serialbridge commands work fine.

Thanks

Khurram

unread,
Oct 1, 2023, 6:30:50 AM10/1/23
to TasmotaUsers
I am not able to use these commands on as ESP32. The pzem-017 is on gpio16+17 and its data shows on the homepage. I am trying to get pzem-004t data through serial bridge. I have tried to assign serbr rx/tx on gpio 33/32. But the SerialSend5 (or SSerialSend5) command does not return any data (the command is sent successfully in both cases as indicated by the "SerialSend":"Done" message in the console). How do I tell the ESP32 to send the serial commands through the gpio 33/32 serial port?

Thanks.

Philip Knowles

unread,
Oct 1, 2023, 8:51:03 AM10/1/23
to Khurram, TasmotaUsers

Assign the serial ports to the GPIO in configuration...

 

Sent from Mail for Windows

 

From: Khurram
Sent: 01 October 2023 11:30
To: TasmotaUsers
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

I am not able to use these commands on as ESP32. The pzem-017 is on gpio16+17 and its data shows on the homepage. I am trying to get pzem-004t data through serial bridge. I have tried to assign serbr rx/tx on gpio 33/32. But the SerialSend5 (or SSerialSend5) command does not return any data (the command is sent successfully in both cases as indicated by the "SerialSend":"Done" message in the console). How do I tell the ESP32 to send the serial commands through the gpio 33/32 serial port?

 

Thanks.

 

On Thursday, 28 September 2023 at 17:00:56 UTC+5 Khurram wrote:

The (very long) tasmota thread mentioned in the previous post holds an answer which works great for my purpose. @adityama suggested using serialbridge in tasmota to poll the pzem (in fact, he is polling 3 pzems for 3 phase AC monitoring) and transform the result in a nodered flow. This is a great solution to my problem. He describes his solution here, the serialbridge commands are here and the nodered flow is here. I could not get software serialbridge commands to work on my esp8266 nodemcu controller, but hardware serialbridge commands work fine.

 

Thanks

 

On Saturday, 23 September 2023 at 13:06:32 UTC+5 knowles...@gmail.com wrote:

The protocols are different 004 uses RS232 016/7 use RS485. In theory there's nothing to stop you using separate GPIOs for each device (but suspect it might not work).

There is a (long) thread of something similar.

 

From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Andrew L <pkkr...@gmail.com>
Sent: Saturday, September 23, 2023 8:30:12 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

If the PZEM-017 is similar in communication style to the 004, I think you should be able to use scripting and treat each of them as a smart meter.  Or just use the PZEM-004 as a smart meter, and define the 017 traditionally. https://tasmota.github.io/docs/Smart-Meter-Interface/#peacefair-pzem004tv30-modbus

 

However, worth bringing up on Github as a feature request.  Seems worthy of consideration, but I don't know how much coding would be involved. 

On Friday, September 22, 2023 at 11:48:25 AM UTC Khurram wrote:

At the moment, I don't think it is possible to connect both the pzem-004t and pzem-017 to the same controller (esp8266/esp32 based).  I would like to measure both the DC battery voltage+current and AC voltage+current from an inverter without using 2 esp controllers. I cannot find anything in the web interface as there is just 1 PZEM Tx gpio setting. Is it possible to edit the code to support Tx separately for the 2 pzems?

 

Thanks

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Khurram Hassan

unread,
Oct 1, 2023, 12:57:52 PM10/1/23
to Philip Knowles, TasmotaUsers
I am assigning the gpios as shown in the picture.

image.jpeg

What am I doing wrong?

Thanks
DB24EAF557564A9086253123AD972725.png
Screenshot_20231001_175837_Jump Desktop.jpg

Andrew L

unread,
Oct 1, 2023, 2:53:05 PM10/1/23
to TasmotaUsers

Philip Knowles

unread,
Oct 1, 2023, 4:41:09 PM10/1/23
to Andrew L, TasmotaUsers
Not at home so can't check but Serial Bridge Tx is not the same as Serial Tx
Sent: Sunday, October 1, 2023 7:53:05 PM

Khurram

unread,
Oct 2, 2023, 3:08:16 AM10/2/23
to TasmotaUsers
I have replaced SerBr Tx/Rx with Serial Tx/Rx but I still do not get any response to the SerialSend5 command. I have swapped the gpios between Tx and Rx as well, but still get no result.

On Monday, 2 October 2023 at 01:41:09 UTC+5 knowles...@gmail.com wrote:
Not at home so can't check but Serial Bridge Tx is not the same as Serial Tx

Khurram

unread,
Oct 4, 2023, 7:47:39 AM10/4/23
to TasmotaUsers
Can someone please explain the difference between Serial Rx/Tx and SerBr Rx/Tx for the ESP32?

Thanks

Philip Knowles

unread,
Oct 4, 2023, 7:55:22 AM10/4/23
to Khurram, TasmotaUsers

Commands - Tasmota

 

Serial Bridge sends and receives data strings

From: Khurram
Sent: 02 October 2023 08:08
To: TasmotaUsers
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

I have replaced SerBr Tx/Rx with Serial Tx/Rx but I still do not get any response to the SerialSend5 command. I have swapped the gpios between Tx and Rx as well, but still get no result.

On Monday, 2 October 2023 at 01:41:09 UTC+5 knowles...@gmail.com wrote:

Not at home so can't check but Serial Bridge Tx is not the same as Serial Tx

Sent: Sunday, October 1, 2023 7:53:05 PM


To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Connect pzem-004t and pzem-017 to same controller

On Sunday, October 1, 2023 at 4:57:52 PM UTC Khurram wrote:

I am assigning the gpios as shown in the picture.

 


What am I doing wrong?

 

Thanks

 

On Sun, Oct 1, 2023, 5:50 PM Philip Knowles <knowles...@gmail.com> wrote:

Assign the serial ports to the GPIO in configuration...

 

Sent from Mail for Windows

 

From: Khurram
Sent: 01 October 2023 11:30
To: TasmotaUsers
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

I am not able to use these commands on as ESP32. The pzem-017 is on gpio16+17 and its data shows on the homepage. I am trying to get pzem-004t data through serial bridge. I have tried to assign serbr rx/tx on gpio 33/32. But the SerialSend5 (or SSerialSend5) command does not return any data (the command is sent successfully in both cases as indicated by the "SerialSend":"Done" message in the console). How do I tell the ESP32 to send the serial commands through the gpio 33/32 serial port?

 

Thanks.

 

On Thursday, 28 September 2023 at 17:00:56 UTC+5 Khurram wrote:

The (very long) tasmota thread mentioned in the previous post holds an answer which works great for my purpose. @adityama suggested using serialbridge in tasmota to poll the pzem (in fact, he is polling 3 pzems for 3 phase AC monitoring) and transform the result in a nodered flow. This is a great solution to my problem. He describes his solution here, the serialbridge commands are here and the nodered flow is here. I could not get software serialbridge commands to work on my esp8266 nodemcu controller, but hardware serialbridge commands work fine.

 

Thanks

 

On Saturday, 23 September 2023 at 13:06:32 UTC+5 knowles...@gmail.com wrote:

The protocols are different 004 uses RS232 016/7 use RS485. In theory there's nothing to stop you using separate GPIOs for each device (but suspect it might not work).

There is a (long) thread of something similar.

 


Sent: Saturday, September 23, 2023 8:30:12 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Connect pzem-004t and pzem-017 to same controller

If the PZEM-017 is similar in communication style to the 004, I think you should be able to use scripting and treat each of them as a smart meter.  Or just use the PZEM-004 as a smart meter, and define the 017 traditionally. https://tasmota.github.io/docs/Smart-Meter-Interface/#peacefair-pzem004tv30-modbus

 

However, worth bringing up on Github as a feature request.  Seems worthy of consideration, but I don't know how much coding would be involved. 

On Friday, September 22, 2023 at 11:48:25 AM UTC Khurram wrote:

At the moment, I don't think it is possible to connect both the pzem-004t and pzem-017 to the same controller (esp8266/esp32 based).  I would like to measure both the DC battery voltage+current and AC voltage+current from an inverter without using 2 esp controllers. I cannot find anything in the web interface as there is just 1 PZEM Tx gpio setting. Is it possible to edit the code to support Tx separately for the 2 pzems?

 

Thanks

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/3eaf0257-00ca-42ea-ac04-70cdcc7f16a4n%40googlegroups.com.

 

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Philip Knowles

unread,
Oct 4, 2023, 8:31:56 AM10/4/23
to Khurram, TasmotaUsers

I THINK that the PZEM-004T driver handles the data request trigger and it then comes back into the appropriate driver buffer to handle.

To communicate with the PZEM-017 it uses MODBus but I think you might need to use SSerialSend if not using the hardware ports

 

Sent from Mail for Windows

 

From: Philip Knowles
Sent: 04 October 2023 12:55
To: Khurram; TasmotaUsers
Subject: RE: Connect pzem-004t and pzem-017 to same controller

 

Commands - Tasmota

 

Serial Bridge sends and receives data strings

From: Khurram
Sent: 02 October 2023 08:08
To: TasmotaUsers
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

I have replaced SerBr Tx/Rx with Serial Tx/Rx but I still do not get any response to the SerialSend5 command. I have swapped the gpios between Tx and Rx as well, but still get no result.

Khurram

unread,
Oct 4, 2023, 8:41:44 AM10/4/23
to TasmotaUsers
I have looked at the commands page. Specifically, I have looked at the section with header " Serial Bridge~". There are only 2 places on the page where the word SerBr is mentioned (and it is in this section). This section mentions Serial Tx/Rx and SerBr Tx/Rx in the same sentence but does not make clear the difference. I have read this section again and again but it is not clear to me at all the difference between Serial and SerBr.

Khurram

unread,
Oct 4, 2023, 8:45:27 AM10/4/23
to TasmotaUsers
I am using an ESP32 and I believe it does not support software serial. So SSerialSend should and does not work. I have tried it already.

Philip Knowles

unread,
Oct 4, 2023, 8:45:43 AM10/4/23
to Khurram, TasmotaUsers

Serial is used for just serial comms like when you are flashing and some software is handling the comms

 

Serial Bridge is used for data transfer in packets – the ESP says tell me this and the other device responds with the data

Philip Knowles

unread,
Oct 4, 2023, 10:34:15 AM10/4/23
to Khurram, TasmotaUsers

ESP32 supports TasmotaSerial. ESP32 has 2 hardware serials 1/3 and 17/16. Any other GPIO will most likely need to use software serial

 

What you need to do is

Firstly, get one device to work using 1/3

Secondly, get the other device to work using 1/3 (I think that the stop bits are different)

Once you know that both devices work disconnect the device (and remove the configuration)

Thirdly, get the first device to work on 17/16

Fourthly, put the configuration into 1/3 and check the device on 16/17 still works

Fifthly, connect the second device to 1/3 again.

You can only check what will work once you know that they will work on the other GPIO.

Khurram

unread,
Oct 4, 2023, 12:58:17 PM10/4/23
to TasmotaUsers
This is a good way to go about. I will try the pzem-004t on gpio 1/3.

One more thing. I also tried with the following berry script but it does not return anything either:

ser = serial(33, 32, serial.SERIAL_8N1)
ser.write(bytes(000100000100000000000000000000000000000010100111000000001101))
msg = ser.read()
print(msg.asstring())


I also tried with ser = serial(32, 33, serial.SERIAL_8N1) but it did not work either.

Philip Knowles

unread,
Oct 5, 2023, 2:57:25 AM10/5/23
to Khurram, TasmotaUsers
That's why you need to get it working 'normally'. You don't know whether the issue is hardware, Tasmota or mis-coding

From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Khurram <kfha...@gmail.com>
Sent: Wednesday, October 4, 2023 5:58:17 PM

Khurram

unread,
Oct 8, 2023, 7:17:33 AM10/8/23
to TasmotaUsers
I have given up on using esp32 and have replaced it with a nodemcu. I am using the following configuration and it works great. I don't know what is wrong with the esp32 but nothing seems to work with SerBr Rx/Tx settings (whether assigned to gpio 1/3, 16/17, 21/22 and 32/33).

HomeUPS Configure Module (nodemcu) scra.jpg

Philip Knowles

unread,
Oct 8, 2023, 7:56:32 AM10/8/23
to Khurram, TasmotaUsers

I think I said a while back that the ESP32 should use TasmotaSerial and you may have needed to use SSerial if not using the default Tx/Rx but it’s working...

 

Sent from Mail for Windows

 

From: Khurram
Sent: 08 October 2023 12:17
To: TasmotaUsers
Subject: Re: Connect pzem-004t and pzem-017 to same controller

 

I have given up on using esp32 and have replaced it with a nodemcu. I am using the following configuration and it works great. I don't know what is wrong with the esp32 but nothing seems to work with SerBr Rx/Tx settings (whether assigned to gpio 1/3, 16/17, 21/22 and 32/33).

 

 

On Thursday, 5 October 2023 at 11:57:25 UTC+5 knowles...@gmail.com wrote:

That's why you need to get it working 'normally'. You don't know whether the issue is hardware, Tasmota or mis-coding

To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers..@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Khurram

unread,
Oct 8, 2023, 9:14:32 AM10/8/23
to TasmotaUsers
I tried both SerialSend5 and SSerialSend5 (along with checking the communication parameters with the commands BaudRate, SBaudRate, SerialConfig and SSerialConfig). Nothing works on the ESP32. In fact, ESP32 behavior is extremely unreliable if pzem-004t rx/tx cables are connected to gpio 1/3 or 16/17. Sometimes, it works fine but most of the time, it fails to detect pzem-017 (I had it defined on 16/17 and later on 32/33).
Reply all
Reply to author
Forward
0 new messages