Support for PZEM 004T Energy monitor

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for PZEM 004T Energy monitor

#151 Post by TD-er » 30 Nov 2019, 23:25

Can you make a pull request for it on GitHub?
That's easier to discuss compared to downloading ZIP and looking at separate files.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#152 Post by djelau » 01 Dec 2019, 00:04

Why not. But unfortunately, I ve no knowlege about how to work with github! As said I'm a beginner.

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for PZEM 004T Energy monitor

#153 Post by TD-er » 01 Dec 2019, 01:37

djelau wrote:
01 Dec 2019, 00:04
[..] As said I'm a beginner.
Well, we all start as a beginner. :)

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#154 Post by djelau » 01 Dec 2019, 21:17

I try to do something in "Pull requests" of ESPEasyPluginPlayground. Don't know if I'm in right way ...

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for PZEM 004T Energy monitor

#155 Post by TD-er » 01 Dec 2019, 21:57

I have seen your PR and already commented on it :)

NiCOOLaS
Normal user
Posts: 5
Joined: 17 Jan 2020, 17:45

Re: Support for PZEM 004T Energy monitor

#156 Post by NiCOOLaS » 17 Jan 2020, 19:04

djelau wrote:
30 Nov 2019, 23:05
...
If you want to use several PZEM, you need to add several occurence of the pluggin.
First occurence of pluggin allows to configure serial interface and modify address of PZEM.
Next occurence of the pluggin only allows to read an adress and reset energy
...
Hello, thanks for plugin.
What kind of sensor to choose in domoticz to display data?
I have a pzem-004(V3.0) sensors, it can transmit more data than V1, can you add this data (VA, VAr, PF...) to the plugin?
Here's how, for example, in tasmota, this data is transferred:
pzemtasmota.png
pzemtasmota.png (29.1 KiB) Viewed 1065 times

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#157 Post by djelau » 20 Jan 2020, 13:55

I don't know about domoticz, because I use Jeedom.
But what I know is in Espeasy, it's not possible to have more than 4 data in a pluggin.

To bypass this, you can create a second occurence of this plugin with the same PZEM address than the first occurence. In this second occurence, you can select the other missing data that are not in the first occurence.

By the way, PZEMv3 only measures 6 parameters: Voltage, Current, Active power, Active energy, Frequency, Power factor. Other parameters that you can find in Tasmota (Apparent power, Reactive power, Today and yesterday energy) are calculated by Tasmota. It can be done with a dummy device in espeasy if you really need this information

NiCOOLaS
Normal user
Posts: 5
Joined: 17 Jan 2020, 17:45

Re: Support for PZEM 004T Energy monitor

#158 Post by NiCOOLaS » 22 Jan 2020, 11:18

djelau wrote:
30 Nov 2019, 23:05
...
Known restriction:
Don't use HW serial when several PZEM connected in series. Over 2 PZEM, frames conflict occurs and I don't know why. The solution is to use SW serial with GPIO1 as TX and GPIO3 as RX (or to use other pins with software serial)
...

Djelau

I had difficulties with connecting 2 devices at the same time.
I connect both devices in parallel and if I connect load to one of it, then the data is displayed, and if I connect the load to both devices, then NAN.
I changed the GPIO. turned on / off Serial port.
Сan you write instructions for beginners. so that in steps from 0 to configure 2 devices on your firmware :oops: :roll:


Here are the pictures assembled diagram and settings, what needs to be changed in them?
shema.jpg
shema.jpg (198.33 KiB) Viewed 981 times
pz1.jpg
pz1.jpg (141.7 KiB) Viewed 981 times
pz2.jpg
pz2.jpg (123.25 KiB) Viewed 981 times

RobertM
Normal user
Posts: 16
Joined: 22 Oct 2017, 15:23

Re: Support for PZEM 004T Energy monitor

#159 Post by RobertM » 22 Jan 2020, 13:22

djelau wrote:
30 Nov 2019, 23:05

First occurence of pluggin allows to configure serial interface and modify address of PZEM.

Djelau

NiCOOLaS
Normal user
Posts: 5
Joined: 17 Jan 2020, 17:45

Re: Support for PZEM 004T Energy monitor

#160 Post by NiCOOLaS » 22 Jan 2020, 14:35

RobertM wrote:
22 Jan 2020, 13:22
djelau wrote:
30 Nov 2019, 23:05

First occurence of pluggin allows to configure serial interface and modify address of PZEM.

Djelau

If this post is for me, then I first assigned the devices different numbers 1 and 2, respectively.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#161 Post by djelau » 22 Jan 2020, 22:59

Hi,

First I update my code since last month. Updated files are viewtopic.php?f=5&t=2595&start=100#p41093. Perhaps it can help.
Sources are now https://github.com/djelau/ESPEasyPluginPlayground

Otherwise, you use GPIO1 as TX and GPIO3 as RX. I said "don't use HW serial" => You should invert these wires only on Node MCU side:
Capture2.JPG
Capture2.JPG (22.67 KiB) Viewed 922 times
Then, in the first occurence of the plugin, select "Software serial" as serial port. And configure like that (take care that data acquisisiton interval is more that 1sec also):
Capture.JPG
Capture.JPG (56.08 KiB) Viewed 923 times

NiCOOLaS
Normal user
Posts: 5
Joined: 17 Jan 2020, 17:45

Re: Support for PZEM 004T Energy monitor

#162 Post by NiCOOLaS » 23 Jan 2020, 14:28

djelau wrote:
22 Jan 2020, 22:59
...And configure like that ...
Thank you very much !
Everything works

p.s.
How to do, when the load is disconnected, the values changed to - 0, not NAN
Can this be done in the rules?

1. ESP:
1.jpg
1.jpg (103.28 KiB) Viewed 900 times
2. Domoticz:
Add rules:

Code: Select all

on PZ1#Voltage_(V) do
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=95&nvalue=0&svalue=[PZ1#Voltage_(V)] 
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=96&nvalue=0&svalue=[PZ1#Current_(A)] 
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=97&nvalue=0&svalue=[PZ1#Power_(W)];[PZ1#Energy_(WH)]
endon

on PZ2#Voltage_(V) do
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=99&nvalue=0&svalue=[PZ2#Voltage_(V)] 
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=100&nvalue=0&svalue=[PZ2#Current_(A)] 
SendToHTTP 10.0.0.131,8080,/json.htm?type=command&param=udevice&idx=101&nvalue=0&svalue=[PZ2#Power_(W)];[PZ2#Energy_(WH)]
endon
2.jpg
2.jpg (93.49 KiB) Viewed 900 times
3. Made a case :D
Energo.jpg
Energo.jpg (353.01 KiB) Viewed 900 times

jack2222
Normal user
Posts: 2
Joined: 02 Feb 2020, 09:49

Re: Support for PZEM 004T Energy monitor

#163 Post by jack2222 » 02 Feb 2020, 10:00

Dear all,

I am trying to use Djelau binaires on a NoceMCU. I have try to follow the guideline in this thread but whatever I've tried I kept with a "NaN" value display on the espeasy. Any idea why ? I have tried software serial and hardware serial with the same results.

I see the led on the PZEM blinking at the frequency of the request but kept with a NaN displayed. Any idea what's wrong ? :idea:

Annotation 2020-02-02 101540-3.png
Annotation 2020-02-02 101540-3.png (54.45 KiB) Viewed 747 times
Annotation 2020-02-02 101320-2.png
Annotation 2020-02-02 101320-2.png (52.49 KiB) Viewed 747 times
Annotation 2020-02-02 101320.png
Annotation 2020-02-02 101320.png (92.72 KiB) Viewed 747 times
And the physical wiring :
IMG_0758.jpg
IMG_0758.jpg (2.67 MiB) Viewed 746 times
but I am getting crazy in reading the "NaN" :
Capture.PNG
Capture.PNG (25.42 KiB) Viewed 744 times
I am sure I miss Something,... The question, is what part did I miss ?

NiCOOLaS
Normal user
Posts: 5
Joined: 17 Jan 2020, 17:45

Re: Support for PZEM 004T Energy monitor

#164 Post by NiCOOLaS » 02 Feb 2020, 11:04

If only one PZEM, then try select HW default, not SW serial.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#165 Post by djelau » 03 Feb 2020, 08:14

Hello everyone,

Something to clarify for everyone: it's really not mandatory to use RX/TX pin of your WEMOS/nodeMCU => Any pin can be used with the solution of "software serial". Then, if you have trouble, first try to change for other pins. As an example, for my 5 PZEM on a WEMOS, here is the configuration:
Capture1.JPG
Capture1.JPG (24.71 KiB) Viewed 701 times
The first line means that TX of the PZEM is connected to GPIO 4 of te WEMOS.
The second line means that RX of the PZEM is connected to GPIO 5 of te WEMOS

To Jack2222:
Your hardware configuration seems to be OK:
The purple wire from TX PZEM is connected to GPIO 1 (don't care if named TX0 in espeasy)
On the other side the orange wire to RX PZEM is connected from GPIO 3 (don't care if named RX0 in espeasy)
Capture.JPG
Capture.JPG (27.24 KiB) Viewed 701 times
But I think the problem is your configuration of serial port in the general settings:
Capture3.JPG
Capture3.JPG (21.86 KiB) Viewed 701 times
Indeed, here TX is used to transmit whereas in the plugin PZEM you declare it to receive. Then you ve got trouble ....

Tell me if it solves your problem (otherwise don't use GPIO1 and GPIO3).

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#166 Post by djelau » 03 Feb 2020, 08:32

NiCOOLaS wrote:
02 Feb 2020, 11:04
If only one PZEM, then try select HW default, not SW serial.
Yes but orange and pink purple must be inverted to connect PZEM TX to Node RX / Node TX to PZEM RX

jack2222
Normal user
Posts: 2
Joined: 02 Feb 2020, 09:49

Re: Support for PZEM 004T Energy monitor

#167 Post by jack2222 » 03 Feb 2020, 22:01

Dear all, a great support from the Community…

I have to confess, my only issue was about the power of the PZEM. The nodeMCU was not delivering the expected 5V I've tried with an other ESP (Wemos D1) and it worked directly… Now everything is working perfectly ! Thank you all !

User avatar
dynamicdave
Normal user
Posts: 198
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Support for PZEM 004T Energy monitor

#168 Post by dynamicdave » 04 Feb 2020, 13:31

I've just ordered a PZEM-004 v3 from China (with the external split CT sensor) - this particular version is housed in a plastic box for safety.

I'm a bit confused as to the correct connection for AC mains as they seem to vary between photos.

On the function diagram (screenshot-090) it shows 'Live' on the bottom terminal, while on the wiring diagram (screenshot-091) it shows it on the second from the bottom terminal.

I don't suppose it matters as it's AC mains - just thought I'd ask.

What is also confusing is the choice of colours.
Here in the UK we use 'brown' as 'live' and 'blue' as 'neutral' (no red wires at all) - but maybe in China it's different ??
Attachments
ScreenShot092.png
ScreenShot092.png (1.04 MiB) Viewed 626 times
ScreenShot091.png
ScreenShot091.png (401.25 KiB) Viewed 626 times
ScreenShot090.png
ScreenShot090.png (132.76 KiB) Viewed 626 times

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for PZEM 004T Energy monitor

#169 Post by TD-er » 04 Feb 2020, 17:41

If you swap live and neutral, I can imagine it will give a 180 degree phase difference between measured current and voltage, so if supported by the sensor, you could get a negative reading on the current.

The current is measured via a coil right?
So I expect there will be some issues with regards to determine the cos-phi or power factor as a coil will smooth out the current measurement anyway.
Not sure if that's a bad thing though, as some appliances do draw a really non-sinus current, which makes it hard to determine a proper apparent and real power consumption.
But it will give quite an incorrect power measurement on highly inductive loads or some dimming circuits that switch on and off during the period.

User avatar
dynamicdave
Normal user
Posts: 198
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Support for PZEM 004T Energy monitor

#170 Post by dynamicdave » 04 Feb 2020, 18:39

Thanks for the feedback.
Yes the current is measured using a coil clamped around one of the mains cables.

My question was... does it matter which way round the L and N wires are connect in respect of destroying the PZEM-004 ?

From your response I think it doesn't - just might affect the reading.

David.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#171 Post by djelau » 05 Feb 2020, 16:07

I don't have clear answer about how to connect L and N. But I made so many test when I developped the plugin without taking care of the direction of L/N. And I never noticed that the measurements was negative (cos phi or current). Thus I can deduce that PZEM internal component detects the direction of the current.

User avatar
dynamicdave
Normal user
Posts: 198
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Support for PZEM 004T Energy monitor

#172 Post by dynamicdave » 06 Feb 2020, 07:37

Hi @djelau
Thanks for your response.

The only thing I was concerned about was damaging (i.e. KILLING) the PZEM-004 by connecting the AC connections the wrong-way round.

I can't wait for the energy sensor to arrive so I can get the system up and running - sounds like a lot of fun.

PS: I've ordered the version that comes in a plastic box as I thought that would be safer !!!!!

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#173 Post by djelau » 06 Feb 2020, 09:15

There is no wrong way as it is AC. It can be connected in any direction.
dynamicdave wrote:
04 Feb 2020, 13:31
What is also confusing is the choice of colours.
Here in the UK we use 'brown' as 'live' and 'blue' as 'neutral' (no red wires at all) - but maybe in China it's different ??
And about wires color, neutral shall be blue. Line can be any color except blue, green/yellow (common colors are red, brown, black). This is the norm in France.

TD-er
Core team member
Posts: 2099
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Support for PZEM 004T Energy monitor

#174 Post by TD-er » 06 Feb 2020, 14:34

djelau wrote:
06 Feb 2020, 09:15
[...]
And about wires color, neutral shall be blue. Line can be any color except blue, green/yellow (common colors are red, brown, black). This is the norm in France.
Here in the Netherlands we used to have "red" and "green" as wire colours until the '70s I guess.
Those were rather bad chosen colors for several reasons:
- Red was neutral, green was "live". That's counter intuitive.
- Red / Green is the most common form of color blindness.

So we now have:
- Blue for neutral
- Brown for "live"
- Black for "live" to switch something on/off (e.g. from a wall switch to a light bulb)
- Yellow/Green for earth/ground.

There is also a grey one possible, but that was for 3-phase if I'm not mistaken. (0-line???)

User avatar
dynamicdave
Normal user
Posts: 198
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Support for PZEM 004T Energy monitor

#175 Post by dynamicdave » 06 Feb 2020, 16:39

Well I'm sort of hoping that now we have left the EU (I live in the UK) we'll be able to change the colour of our wires back to the scheme we had when I was a lad.

Red was Live
Black was Neutral
Green was Earth

Ha, ha, ha - wishful thinking.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#176 Post by djelau » 06 Feb 2020, 16:43

So, you have your answer about the connection of phase and neutral: do the opposite of me and it will work (I am from France). :D

White_SinSay
Normal user
Posts: 1
Joined: 13 Feb 2020, 03:24

Re: Support for PZEM 004T Energy monitor

#177 Post by White_SinSay » 13 Feb 2020, 03:29

djelau wrote:
30 Nov 2019, 23:05
Hi guys,

This is my first post, so keep cool. I'm a great fan of ESPeasy; So I try to contribute with this code for PZEM004Tv30. I'm not a software expert so please be tolerant with me.

Hardware part:
PZEM004Tv30 can be wired in parallel without any aditionnal component: simply connect RX of PZEM together and Tx of PZEM together.
However, if programming the address, only one PZEM must be connected at once during address setting.

Software part:
If you want to use several PZEM, you need to add several occurence of the pluggin.
First occurence of pluggin allows to configure serial interface and modify address of PZEM.
Next occurence of the pluggin only allows to read an adress and reset energy
Energy can also be reset with command : http://<espeasyip>/control?cmd=resetenergy,<PZEM address> (example: "http://192.168.0.1/control?cmd=resetenergy,2" => Reset energy of the PZEM with address #2)

I modify PZEM004Tv30.h and PZEM004Tv30.cpp in order to be compatible with espeay serial. Please use it rather than official PZEM004Tv30.h and PZEM004Tv30.cpp from PZEM github.

Known restriction:
Don't use HW serial when several PZEM connected in series. Over 2 PZEM, frames conflict occurs and I don't know why. The solution is to use SW serial with GPIO3 as TX and GPIO1 as RX (or to use other pins with software serial)
I try only with WEMOS D1mini. So I compile 1M bin, but I don't test it. 4M is OK
Don't hesitate to give me your feedback. And feel free to improve my code.

Djelau
NodeMcu + PZEM-004Tv30 (2pcs), works fine
I requested "ESP_Easy_mega-20191003_PZEM_core_ESP8266_4M1M.bin"

But it does not work DS18B20
It works on the original firmware

pmalvino
Normal user
Posts: 14
Joined: 03 Aug 2016, 22:34

Re: Support for PZEM 004T Energy monitor

#178 Post by pmalvino » 18 Feb 2020, 11:50

Hello, i install the firmware pzem-004 v30 multiple, but only use one pzem, the problem is that the energy shown on espeasy is not correct. I use this firmware because it work better with a display oled ssd1306. Is there a way to fix this?

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#179 Post by djelau » 18 Feb 2020, 12:52

White_SinSay wrote:
13 Feb 2020, 03:29
NodeMcu + PZEM-004Tv30 (2pcs), works fine
I requested "ESP_Easy_mega-20191003_PZEM_core_ESP8266_4M1M.bin"

But it does not work DS18B20
It works on the original firmware
I don't test this configuration. Normally, plugins are independant so my plugin shouldn't have any impact on the DS18B20. But I'll check anyway.

djelau
Normal user
Posts: 12
Joined: 08 Nov 2019, 15:33
Location: France

Re: Support for PZEM 004T Energy monitor

#180 Post by djelau » 18 Feb 2020, 13:36

pmalvino wrote:
18 Feb 2020, 11:50
Hello, i install the firmware pzem-004 v30 multiple, but only use one pzem, the problem is that the energy shown on espeasy is not correct.
I tested on 1 PZEM with sucess. What do you mean by not correct ? Stucked? alway 0?
Have in mind that the vealue is in kWh thus I could take a couple of hours to change.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests