Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DC meter from Peacefair with RS485 #3694

Closed
eazuka opened this issue Sep 4, 2018 · 111 comments
Closed

DC meter from Peacefair with RS485 #3694

eazuka opened this issue Sep 4, 2018 · 111 comments
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended

Comments

@eazuka
Copy link

eazuka commented Sep 4, 2018

Having just read about the support for PZEM004T Energy Monitor from Peacefair. I'm just wondering if it will be possible to add support for PZEM-003 and PZEM-017 DC meter with RS485 from same manufacturer (Peacefair). I have use cases where Sonoff 4CH Pro, Sonoff SV & Shelly 1 will be used with PZEM-017 DC meter for DC (Solar) power metering and switching?

The PZEM-003 and PZEM-017 DC meter uses RS485 to communicate.

@arendst i can donate the PZEM-003 or PZEM-017 DC meter from Peacefair if you don't already have but think its possible to support it.

@ascillato2 ascillato2 added the enhancement Type - Enhancement that will be worked on label Sep 4, 2018
@arendst
Copy link
Owner

arendst commented Sep 6, 2018

I have a PZEM-014 and a PZEM-017 on order. They both use Modbus communication using the serial interface as did the PZEM-004T. The default interface is 5V. Hopefully it can be adjusted to 3V3 as I used on the PZEM-004T.

Let's see.

arendst added a commit that referenced this issue Sep 6, 2018
Add experimental support for PZEM-003,014,016,017 Energy monitoring (#3694)
@arendst
Copy link
Owner

arendst commented Sep 6, 2018

Just release experimental support for PZEM-003,014,016,017.

If you manage to connect the PZEM device to a esp8266 device then configure the GPIOs as below

image

Pay attention to the correct numbers: 99 PZEM Rx and 98 PZEM Tx. Do not select 63 PZEM Rx and 62 PZEM Tx as they will service the PZEM-004T. This naming scheme may change in the future but I also may want to incorporate all PZEM devices in one driver. Time will tell.

If you have connected the device try to gather some debug information using the web console (do not use a serial connection as that is being used by the PZEM unless you configure other GPIOs but that may lead to timeouts). Pls provide some output here (if any ;-))

This is experimental as I do not own a device yet but the info is from the documentation available from PeaceFair.

@arendst arendst added the awaiting feedback Action - Waiting for response or more information label Sep 6, 2018
@eazuka
Copy link
Author

eazuka commented Sep 6, 2018

@arendst you are awesome, i truly appreciate you and all you have done with Tasmota. Thanks alot.
My PZEMs are on there way also. not gotton to me yet but hopefully i receive mine before your arrive.

Thanks

@mkosta74
Copy link

Hi, can I test this release? I got PZEM-016 with TTL to RS485 converter.

where I can download this release?

Regards.

@ascillato
Copy link
Contributor

http://thehackbox.org/tasmota/

@mkosta74
Copy link

Hi, I install this version and try to get communication on modbus but keep getting errors.
after hour of troubleshooting I notice strange clicking sound from PZEM-016. When I open the case and connect it to mains I notice sparks on one resistor https://photos.app.goo.gl/BgPtHNuFHiBLsbvz7
😄

Looks my PZEM device is broken...

@arendst
Copy link
Owner

arendst commented Sep 26, 2018

Still waiting for my RS485toTTL converters…

rs485tottl

@mkosta74
Copy link

I use this one

MAX3485 Module TTL To RS485 Module MCU Development Accessories
https://s.click.aliexpress.com/e/hKziY1K

But as I post earlyer my PZEM is broken.

@arendst, is it normal that tasmota gets errors from this TTL2RS485 even if there is nothing connected to 485 terminal?

@arendst
Copy link
Owner

arendst commented Sep 29, 2018

As noted here (#2694 (comment)) I'm not sure if your module will function correctly.

I don't know what errors you receive but as I still have to tune the comms between Tasmota and the PZEMs I guess it's picking up noise that Tasmota currently does not process.

@vicfergar
Copy link

vicfergar commented Oct 3, 2018

Hi! I ordered a Pzem-016 too. I would like to connect the ESP directly to the serial TTL lines on-board. Have someone tried it?

arendst added a commit that referenced this issue Oct 15, 2018
6.2.1.16 20181015
 * Add TasmotaModbus library for very basic modbus wrapper for TasmotaSerial
 * Change xsns_17_senseair.ino to use TasmotaModbus library
 * Fix xnrg_05_pzem2.ino for PZEM-014/016 support using TasmotaModbus library (#3694)
@arendst
Copy link
Owner

arendst commented Oct 15, 2018

With the latest release the PZEM-014/016 works when connected to the esp8266 using the interface below:

image

image

image

Notice the correct GPIO naming (98 PZEM TX and 99 PZEM Rx).

@vicfergar
Copy link

Hi! I finally got it working without the RS485 interface!

Here are the modifications that I made:

  1. Desolder the TX pin from the MAX485 to avoid interferences. (The whole chip can be removed, but I want to reduce the necessary modifications)
    image

  2. Put two pull-down resistor of 2K ohm one for RX and other to TX. This is needed to reduce the voltage to 3.3v (Simulation circuit)
    image

  3. Solder wires for the RX and TX lines.

Here is the final assembly adding a ESP8266 board inside the case:
image
image

I use the hardware serial with the latest release and it works like a charm. Thanks @arendst for your amazing work 👍

@ascillato2
Copy link
Collaborator

Hi,

Closing issue as now it is implemented in Tasmota.

Thanks all for sharing their work and ideas.

arendst added a commit that referenced this issue Oct 17, 2018
6.2.1.17 20181017
 * Enable updated non-blocking PubSubClient as default MQTT client
 * Update TasmotaModbus and TasmotaSerial libraries for support of serial 8N2 communication
 * Add support for Pzem-003/017 DC Energy monitoring module (#3694)
 * Change support for Pzem-014/016 AC Energy monitoring module (#3694)
@arendst
Copy link
Owner

arendst commented Oct 17, 2018

Important PZEM module configuration change as of version 6.2.1.17:

To distinguish between the PZEM-014/016 (AC) and PZEM-003/017 (DC) I had to split the drivers and redesign the pin configuration for all supported PZEM modules.

For PZEM-004T use PZEM0XX Tx and PZEM004 Rx
For PZEM-014/016 use PZEM0XX Tx and PZEM016 Rx
For PZEM-003/017 use PZEM0XX Tx and PZEM017 Rx

Example:
image

@arendst arendst added fixed Result - The work on the issue has ended and removed awaiting feedback Action - Waiting for response or more information labels Oct 17, 2018
@SiliconAvatar
Copy link

I just got my converter in and tried it with the PZEM-016 I have, and it seems to work great! (Using 98 & 61)

I do have a feature request though:

Would it be possible to talk to more than one? Since I have a split phase power system, I need 2 modules to monitor total power consumption, and these are modbus devices so their meant to have many devices on one bus.

The PZEM-016 manual says the node address is selectable in register 0x0002, and is selectable from 1-127, so there should be no technical limitation to having multiple PZEM devices on one bus.

As to setting the device node address within tasmota, if it's not the simplest thing to do, or not desirable for tasmota to modify the devices' node address, could it be selectable to either read a single device at the default address, or to select how many devices are on the bus and choose which address they are at, to allow for more advanced multi-node configurations?

@arendst
Copy link
Owner

arendst commented Oct 25, 2018

It's not only a matter of connecting but also of representation either thru GUI or JSON. Currently only ONE energy monitoring module is supported.

@SiliconAvatar
Copy link

I understand that displaying the data would be difficult, and I don't have a good solution to that; but having to configure it over the command interface and just reporting the data over MQTT would be plenty satisfactory.

@mkosta74
Copy link

How can I reset kWh couter to 0?

@arendst
Copy link
Owner

arendst commented Nov 17, 2018

Search wiki for command EnergyReset

@mkosta74
Copy link

@arendst, thanks

I was trying to do it over serial bridge using "SerialSend5 01421180"

Is it possble to comunicate with PZEM 016 like that?

@hteggi
Copy link

hteggi commented Dec 2, 2018

Hi! I finally got it working without the RS485 interface!

Here are the modifications that I made:

  1. Desolder the TX pin from the MAX485 to avoid interferences. (The whole chip can be removed, but I want to reduce the necessary modifications)
    image
  2. Put two pull-down resistor of 2K ohm one for RX and other to TX. This is needed to reduce the voltage to 3.3v (Simulation circuit)
    image
  3. Solder wires for the RX and TX lines.

Here is the final assembly adding a ESP8266 board inside the case:
image
image

I use the hardware serial with the latest release and it works like a charm. Thanks @arendst for your amazing work 👍

Hello @vicfergar.

Thanks for the nice instructions and pictures. I will recive my PZEM 016 in a few days and will do the same any chance you could add some more pictures of the soldered resistors? From the picture I can only see one solder on the board but your illustration shows two.

@vicfergar
Copy link

vicfergar commented Dec 2, 2018

Hi @hteggi!

I'm glad that this work helps you. You are right, 2 resistors are needed both with the same value of 2K ohms. Because of the distance between the pads, I used one through hole and another SMD. That last one is visible in the second picture, you can see an small SMD resistor labeled with 202 between the pads of the TX optocoupler.

Hope it works for you too!

@ukewea
Copy link

ukewea commented Aug 13, 2021

Thank you @vicfergar for the original idea and @ukewea for follow-up. Very helpful!
I got my 017 connected and looks like all good. I did disconnect only TX pin of MAX485 (was too lazy to remove the chip).
I wonder, is it ok if I'm feeding the data side from ESP's 3V3 pin? Tested and it's working. Or shall I rather go with proper 5V from usb and 2k pulldowns?
(power side will be 12V, just in case)

If someone's having similar question, a 3-month testing tells me that it's ok to feed the data directly from ESP, without pulldowns or anything else in between, and it's reporting data to my Home Assistant server nicely.

Also, I didn't put a resister between the TX of PZEM017 and ESP's RX.

@KNXfriend
Copy link

Thank you all for this great ideas and work!

I am currently prepring to monitor my boat´s batteries with this solution in the winterstock, while some systems stay up and online there. This is possible because of energy harvesting by solar panels and wind generator. But this includes the neccessarity to count not only one way. The batteries are charged over the day, while in the night the consumption typically is higher. So far I understand, that the PZEM 017 can only measure one way. That´s why I am thinking to take simply two, connect them to the same shunt, but one other way round connected. Since the PZEMs did not arrive so far, I cannot test it, but generally it should work. The only thing is - I don´t want to use an ESP for each.

Is there a way to enable the Tasmota software of one ESP to ask up to 4 different PZEMs over different modbus adresses?
To give the different adresses to the PZEMs I found out so far.

The calculations about the energy balance sheet and taking Peukert factor into account would be calculated externally in the RasPI.

Target is a complete battery monitoring of service and starter batteries and the ability to manage the systems on the boat in dependency of the availability of energy.

@Oleg-Sob
Copy link

PZEM 017 measures the current in two directions, when there is a charge and the discharge, it counts everything with a + sign. Therefore, it will not be clear how much has been discharged, how much has been charged. Therefore, using two pieces will be useless.

@Oleg-Sob
Copy link

You can use INA 219, it measures in two directions with positive and negative readings.

@KNXfriend
Copy link

Thank you for this information. Now I will be aware, that this is possible. But from where you got this information?
Because I find contradictory information in german forums. There it is described, that negative currents are floored to zero.
Ina 219 looks promising beside that I liked the already hardened hardware for rough environment and the isolation over RS485, which can of course been realized with Ina 219 as well.

@barbudor
Copy link
Contributor

You can have up to 3 PZEM max per tasmota.
Also pzem and ina219 are very different things
PZEM are for AC high voltage
INA219 is for DC low voltage (max 30V)

@Oleg-Sob
Copy link

Oleg-Sob commented Nov 18, 2021

As for the PZEM 017, I also thought to put 2 pcs. in two directions, but it did not work out since they measure the negative current as positive. And I connected INA219 to a shunt of 100A and I measure the voltage 60V through a resistor divider 1/3, 20V comes to INA219, and in fact 60 and I adjust it with the formula.

@KNXfriend
Copy link

I understand, that my original plan might not work, like expected.
I am still interested to understand, how to connect more than 1 PZEM to tasmota.

barbudor, can you enlighten me, how to connect up to 3?

I only understand to configure two GPIOs as serial interface for modbus PZEM communication. As far as I have seen, it seems that the modbus address for PZEM is hardcoded to 1 in the source code of tasmota. How to arrange, that tasmota is asking other adresses over the same bus?
And why this is limited to 3?

@barbudor
Copy link
Contributor

Searching a bit and you would have found
#10567

Up to know Tasmota has been designed for monitoring a single point of power. 3 is the maximum number of phases that you will encounter in real life.

@KNXfriend
Copy link

Ok.
Then we are talking about different things.
I am about battery monitoring, not about any ac or 3 phase applications.

Thank you for your fast answer.

That tasmota is currently designed for one connection to a PZEM corresponds to my still very little understanding of current solution.

I just wandered, if someone has ideas, how to use modbus as a real bus with tasmota and just ask several of this PZEM devices then only one.

I found a first hook in the source code, where tasmota communicates with exact this one PZEM adress and I might be able to extend this. But since I not really understand the whole tasmota architecture yet, I am afraid, I need some help.

@barbudor
Copy link
Contributor

You asked about 3 PZEM, I told you:

  • how to do that using 'ModuleAddress'. No need to extend Tasmota code as it is already supported
  • what PZEM are meant for : AC, I'm 80% sure it won't work correctly for DC
  • what is tasmota use case

To monitor batteries / DC, look at INA219/226 but be careful about ground management
As fas as I remember only 1 of those is supported by ESP
I know that someone on Discord is working on ina3221 driver which is a 3 channels. If it doesn't come quickly, I can do it too

@Oleg-Sob
Copy link

Oleg-Sob commented Nov 19, 2021

I have 2 pieces of PZEM 017 working. They work fine, I have not tried 3 pieces, but I think they will work.

667

@barbudor
Copy link
Contributor

@Oleg-Sob
Is that on AC or DC?
If DC do you have to tell the PZEM about it (and how)?

@barbudor
Copy link
Contributor

OK pzem017 is for dc
My experience is with pzem004 which is ac

@Oleg-Sob
Copy link

PZEM 004 4 pieces work for me on one ESP 8266, though EspEasy firmware.
111

@grappini
Copy link

I have 2 pieces of PZEM 017 working. They work fine, I have not tried 3 pieces, but I think they will work.

667

What is the wiring diagram of the 2 pzem's with ESP 8266 ? Did you add the 2 pzem's to tasmota with ModuleAddress x command ?

@KNXfriend
Copy link

KNXfriend commented Nov 19, 2021

Ok. Seams that the feature is already existing up to 3 PZEMs.
But your question grappini shows me, that not only I have problems to find this information.

I can still only guess, bcause I can not try, due to missing PZEMS. From the information what I think to understand now, there is the
ModuleAddress 1/2/3 command, which probably sets the modbus adress to the PZEM device, which is currently on the bus.

When there are adress 1 and 2 or 1, 2 and 3 the tasmota automatically reads them all and represents them in the homescreen like seen above.(?)

That seams to be partially described in change log to 6.6.0.12 20190910 for me.

Thank you all, so activly helping here!

@ortegafernando
Copy link
Contributor

I use PZEM-17 to measure the charge of batteries, if used to measure charge and discharge, it summarizes everything as positive and it is not clear how much charge, how much discharge.

Hi @Oleg-Sob @seliku what do you think about this option to "know" negative or positive values ?
#13733
Thanks

@Oleg-Sob
Copy link

Pzem 017 does not show negative currents, I use ina 226.

@SvenAarts
Copy link

Hey guys, Maybe not right place but i hope someone can help me with an answer or point me to the right topic... i am using a PZEM 17, an arduino mega and a MAX 485 to read it out. since i am using it to measure the voltage of solarpanels my measuring voltage drops below 7 volts at night. I saw a hack for the PZEM 04 to change it so you can use an external power supply so it keeps measuring in the night. Does anyone know if there is a hack for the PZEM 017 to or a way to work around the problem that my PZEM 017 starts measuring in the morning? When i try to recreate this exact problem with lab bench power supply (turn the voltage to 0 wait a couple minutes and then turn it up to 7 volts) the problem does not exist but with the solar panels it just doesnt start measuring in the morning. Thanks in advance!

@raslr6
Copy link

raslr6 commented Sep 26, 2022

Hola chicos, tal vez no sea el lugar correcto, pero espero que alguien pueda ayudarme con una respuesta o señalarme el tema correcto... estoy usando un PZEM 17, un arduino mega y un MAX 485 para leerlo. Como lo estoy usando para medir el voltaje de los paneles solares, mi voltaje de medición cae por debajo de los 7 voltios por la noche. Vi un truco para cambiar el PZEM 04 para que pueda usar una fuente de alimentación externa para que siga midiendo durante la noche. ¿Alguien sabe si hay un truco para el PZEM 017 o una forma de solucionar el problema que mi PZEM 017 comienza a medir por la mañana? Cuando trato de recrear este problema exacto con la fuente de alimentación del banco de laboratorio (cambie el voltaje a 0, espere un par de minutos y luego súbalo a 7 voltios), el problema no existe, pero con los paneles solares simplemente no comienza a medir por la mañana. . ¡Gracias por adelantado!

In the documentation it says that if the voltage drops below 7v it can be powered through the usb port but taking into account not to do it from a pc because it could be damaged, I would use a smartphone charger.
I had not thought of using it to measure the panels but it would be useful, I understand that you have connected it the same as if it were the batteries, is that correct?

@Dlzensolar
Copy link

Tôi có 2 chiếc PZEM 017 đang hoạt động. Chúng hoạt động tốt, tôi chưa thử 3 miếng, nhưng tôi nghĩ chúng sẽ hoạt động.
667

Sơ đồ nối dây của 2 pzem với ESP 8266 là gì? Bạn đã thêm 2 pzem vào tasmota bằng lệnh ModuleAddress x chưa?

How to put 2 pzem 017 into 1 esp8266. Thanks

@Dlzensolar
Copy link

Tôi m using pzem 017 with a 200A shunt(peacefair). The current readings shows only half of what itphải làm vậy. Làm cách nào để thay đổi độ phân giải hiện tại?

I encountered the same situation. Have you solved it yet? help me. Thanks

@Oleg-Sob
Copy link

I have 3 pieces of PZEM 17 working on one ESP 8266. In order for them to work, first set different addresses through the PZEM003-Master application, 1, 2, 3

@Dlzensolar
Copy link

I have 3 pieces of PZEM 17 working on one ESP 8266. In order for them to work, first set different addresses through the PZEM003-Master application, 1, 2, 3

Can you help me share more specifically? Thanks.

@barbudor
Copy link
Contributor

You can do it from tasmota
They all come with factory address 1
You need to connect 1 only and use the command Module Address to change the address
Then disconnect and connect the next one and set another address
Continue until all are configured with a different address
Then you can have all connected
You can have up to 3 on an esp8266 and up to 8 on ESP32
Address must start from 1 and increase by 1

@Dlzensolar
Copy link

On esp8266 there is only (tx + rx). How do I get (tx+rx)1 + (tx+rx)2 + (tx+rx)3. Every time I disconnect a pzem 017, I plug it into one pin (tx+rx) of the esp8266? and it automatically recognizes as below.pzem017-1 type "Module Address 1" to(tx+rx) to disconnect. then pzem017-2 type "Module Address 2" to(tx+rx). Similar to pzem 017-3. Thank you very much. Have a good day.

@barbudor
Copy link
Contributor

barbudor commented Oct 18, 2023

PZEM use RS485 which is a bus.
You connect TX/RX of your esp to the RS485 adapter
Connect the 3rd module and use command ModuleAddress 3, Disconnect the 3rd module,
Connetc the 2nd mdoule and use command ModuleAddress 2
Now connect all 3 modules.
Each have it's own address on the bus and Tasmota will find them at boot

You should never use the command ModuleAddress with more than 1 module connected otherwise you will change the address of all connected modules
I strongly advise to put a sticker on each module

@Gosokan
Copy link

Gosokan commented Dec 18, 2023

I'd like to ask about PZEM-016 and Tasmota.
Will "Energy Today" reading be retained when power outage occurs?

@arendst
Copy link
Owner

arendst commented Dec 19, 2023

Will "Energy Today" reading be retained when power outage occurs?

Nope, unless you shutdown Tasmota before the (planned) power outage occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests