Get multiple pzem-004t data identified by pzem id

256 views
Skip to first unread message

Khurram

unread,
Aug 6, 2024, 10:43:53 AM8/6/24
to TasmotaUsers
Is it possible to get data from 2 or more pzem-004t indexed by its id (such as the data returned by multiple INA219s which is identified by the I2C address). I would like to connect 1 pzem to the a UPS input and the other on the UPS output. I get data by "STATUS 10" command. The data in the form of an array; so I have 1 array for voltages, 1 array for currents, etc. This makes it almost impossible to detect which pzem has blown in case of a failure in the pzems. Is it possible to get the data indexed by the pzem id?

Thanks

Philip Knowles

unread,
Aug 6, 2024, 11:53:08 PM8/6/24
to Khurram, TasmotaUsers
This was answered years ago. Put PZEM into the search box on the Tasmota site.


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Khurram <kfha...@gmail.com>
Sent: Tuesday, August 6, 2024 3:43:53 PM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Get multiple pzem-004t data identified by pzem id
 
Is it possible to get data from 2 or more pzem-004t indexed by its id (such as the data returned by multiple INA219s which is identified by the I2C address). I would like to connect 1 pzem to the a UPS input and the other on the UPS output. I get data by "STATUS 10" command. The data in the form of an array; so I have 1 array for voltages, 1 array for currents, etc. This makes it almost impossible to detect which pzem has blown in case of a failure in the pzems. Is it possible to get the data indexed by the pzem id?

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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/e4957c46-08bc-4688-96e6-5fa0f68846bfn%40googlegroups.com.

Khurram

unread,
Aug 7, 2024, 2:28:17 AM8/7/24
to TasmotaUsers
I think you are referring to multiple pzem-004t via modbus. I will try it out. Btw, using multiple pzem-004t requires some additional circuitry as mentioned here

Thanks

Philip Knowles

unread,
Aug 7, 2024, 3:58:47 AM8/7/24
to Khurram, TasmotaUsers
No, look in the Smart Meter Interface page. You need to set the ID of each device individually using the ModuleAddress command
Sent: Wednesday, August 7, 2024 7:28:17 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Get multiple pzem-004t data identified by pzem id
 

Khurram

unread,
Aug 7, 2024, 4:13:57 AM8/7/24
to TasmotaUsers
The 1st link is from the Smart Meter Interface page :) It just points to the script for using multiple pzems on that page. You are right about setting the different ids on the pzems. You also need to add a few components as pointed out in the 2nd link in my post above.

Thanks

Philip Knowles

unread,
Aug 7, 2024, 9:09:16 AM8/7/24
to Khurram, TasmotaUsers
No you don't you just need a TTL to RS485 board such as 


Sent: 07 August 2024 09:13

Khurram

unread,
Aug 9, 2024, 1:13:00 PM8/9/24
to TasmotaUsers
Do you mean I need the TTL-RS485 adapter to change the pzem-004t address? I thought the RS485-TTL conversion was already done on the pzem-004t board it and that is why you can hook up the tx/rx lines directly to the gpio pins on the esp8266/32.

Philip Knowles

unread,
Aug 10, 2024, 2:18:49 AM8/10/24
to Khurram, TasmotaUsers
If you are wanting to 'multidrop' RS485 reliably you are better using a TTL to RS485 adaptor. Working at 3.3V is close to the minimum +/- 1.5V and, with more than one device (with a termination resistor), might not be reliable 
Sent: Friday, August 9, 2024 6:13:00 PM
To: TasmotaUsers <sonof...@googlegroups.com>

Khurram

unread,
Aug 10, 2024, 2:44:37 PM8/10/24
to TasmotaUsers
I am getting confused here. The controller communication side of the pzem-004t is not RS485; its already TTL. So how would I connect the RS485-TTL adapter to the pzem-004t?

Btw, I have already changed the address on the pzems using an arduino and the changeaddress progam on the pzem-004t library on github.

Justin Adie

unread,
Aug 10, 2024, 2:52:47 PM8/10/24
to Khurram, TasmotaUsers
Rs485 is a serial protocol using uart.  I think Pzem 0004t uses uart for external comms. Not TTL.  And expects rs485.  



Khurram

unread,
Aug 10, 2024, 3:02:24 PM8/10/24
to TasmotaUsers
Thanks for the clarification. Can I just connect the RXs and TXs of the pzems together to the gpios or do I need to connect them with some components as described here?

Justin Adie

unread,
Aug 10, 2024, 3:12:44 PM8/10/24
to Khurram, TasmotaUsers
You can bit-bang rs485 but it is not advisable if you are daisy chaining multiple devices as the terminating resistors will/may drop the voltage too much for there to be enough distinction between a true high and true low. 

Best to use an rs485 module at 5-12v. They are cheap and reliable.  





Khurram

unread,
Aug 10, 2024, 3:21:57 PM8/10/24
to TasmotaUsers
The RS485-TTL adapter I have found have A, B and Gnd connections on the RS485 side. How would I connect the pzem-004t Rx and Tx pins to this?

Khurram

unread,
Aug 11, 2024, 2:24:44 PM8/11/24
to TasmotaUsers
I have been thinking about this setup and my above comment does not make any sense. So I got hold of 2 RS458-TTL adapter, connected the Rx/Tx pins of the 1st one to the pzem-004t Rx/Tx pins and connected the Rx/Tx pins of the 2nd one to Rx/Tx pins of the ESP8266; I also connected the RS-485 pins of the two adapters together (A to A, B to B, Gnd to Gnd and also to the ESP8266 Gnd). I am using the script from the Smart Meter page for pzem-004t modified for 1 pzem only (Its address is 2). However, it does not get any data from the pzem-004t. My script is as follows:

>D
>B
->sensor53 r
>M 1
+1,3,m,0,9600,ENERGY,1,1,02040000,02040001,02040003,02040005,02040007,02040008
1,=h<hr/>Sensor-1
1,020404UUuuxxxxxxxx@i0:10,Voltage,V,Sensor-1-V,2
1,020404UUuuUUuusxxxx@i1:1000,Current,A,Sensor-1-A,2
1,020404UUuuUUuusxxxx@i2:10,Power,W,Sensor-1-W,2
1,020404UUuuUUuusxxxx@i3:1000,Energy,kWh,Sensor-1-kWh,4
1,020404UUuuxxxxxxxx@i4:10,Frequency,Hz,Sensor-1-hz,2
1,020404UUuuxxxxxxxx@i5:100,Power Factor,PF,Sensor-1-PF,2

#

The pzem-004t is ok as I have verfied it by connecting to an arduino and checking its address and power measurements. What am I doing wrong?

Justin Adie

unread,
Aug 11, 2024, 5:16:32 PM8/11/24
to Khurram, SonoffUsers
I think that I may have misunderstood the specs as well.  

It does indeed look like these modules are addressed using RS232 serial comms.  Seems a really odd choice and traditionally designers have avoided Modbus RTU over RS232 as it’s too “risky” over anything more than very short distances..  I have also seen that users parallel these devices on to the serial ports, even at 3.3v.  this seems like a really bad idea, not just because RS232 is intended to be point to point but also because of the potential for uncertain high/lows when operating at 3.3v. 

The strategies that I’d consider (if I had to use this module) would be:

1. move to 5v and have a level shifter before the ESP.  or at least a zener diode limiting the voltage to 3.3v (arguably/apochraphally the GPIO are 5v tolerant but I’ve never wanted to trust to that chance for remote devices that I might not be able to service for more than a couple of weeks.)
2. use software serial and three separate pairs of tx/rx.  Do the reads sequentially to avoid sourcing too much current.
3. use (n) separate chips to do the reading and communicate back to the “master” via i2c.  ATMega 328p would be an overkill but possible.  

Having said the above your structure should work ok I’d think, and be much more resilient.  Remember that RX connects to TX and vice-versa.  i.e. RX on ESP connects to TX on the RS485 module.  I’m not sure about the config-script - I avoid those and prefer to use native libraries or write my own.  


Philip Knowles

unread,
Aug 12, 2024, 6:51:59 AM8/12/24
to Khurram, TasmotaUsers
I can't remember how I set mine up but I only used 1 adaptor. The PZEM needs to be connected to mains to function as the mains powers the opto-isolators in the PZEM.

The code looks correct 020404 is to read (04) four (second 04) registers from device 02.

I'm now starting to think that I used a modified LC Technologies relay board to do the comms - converts the Rx/Tx to 5V (and eventually replaced with PZEM-016s) - sorry


Sent: 11 August 2024 19:24

Khurram

unread,
Aug 20, 2024, 4:46:50 AM8/20/24
to TasmotaUsers
An update on this on my test setup with 2 RS485-TTL. If I cross the Rx/Tx pins between the nodemcu and its RS485-TTL adapter and also cross them between the pzem-004t and its RS485-TTL adapter, no data transfers takes place (no blinking light on the pzem-004t or the 2 adapters). I have to wire the Rx/Tx straight on both ends and then the lights start up blinking on the pzem-004t and the adapters. However, tasmota home page shows all readings as 0; very strange. Next, I removed the 2 adapters and connected the Rx/Tx pins to the gpios contained my script and the readings showed up fine.

Next step, connect 2 pzem-004t to the nodemcu using the wiring components mentioned here and see if both readings appear in the script (after changing the script and assigning a different address to the 2nd pzem-004t).

Bart van Seters

unread,
Sep 29, 2024, 5:21:38 AM9/29/24
to Khurram, TasmotaUsers

I use 4 x pzem004t hooked up to one esp8266. every pzem has own address. I flashed the esp with espeasy.


Op di 20 aug 2024 10:46 schreef Khurram <kfha...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages