Page 3 of 4

Re: Energy measurement with espeasy and pzem-004t

Posted: Monday 27 January 2020 18:00
by Sherco49
Hi !
i am trying to connect 2 PZEM-004t V3 on a Wemos D1 mini pro with ESP Easy then link them to Domoticz. The purpose is to monitor consuption and solar production.
I read many posts here and on "Let's Control it" forum, but i get lost now, like "papperone" wrote on the Let's control forum

-many different solutions, but not in the same unique post, so i can't understand wich software comes with wich wiring !
All of the authors are great to share their work, and i feel ashame not understanding all their explanations

I tried multi softwareserial solution from aleph0 (ESPEasy-2.0.0-dev12_test_4096.bin.zip), with two modules: the system polls (i see the same led on PZEM flashing 12 times on each PZEM one after the other ( i suppose it is espeasy request to the PZEM) without any reponse.
The same happens when swapping RX and TX, just the led flashing is different.
By the way, i can't be sure which is the right Rx/Tx wiring as i don't understand the comment under Software serial gpios field.
I didn't made any 5v to 3.3V conversion, but i have an ESP32 is working like that with HW serial, but could it be a direction ?

Does the pins in Espeasy hardware has to be set (input or output)?

I loaded "firmware_PZEM004T multiple.bin" wich looks like a sequential polling of the PZEM 5V, but hardly imagine the wiring

So if someone could kindly link or post a working solution (software and wiring) ?

Re: Energy measurement with espeasy and pzem-004t

Posted: Monday 27 January 2020 18:26
by aleph0
Did you put 220v on the pzem while trying ? Mine does not respond without 220v :-(

Edit : I just read again the thread on let's control it and they say the protocol have changed for pzem v3 ; my precompiled firmware won't work with those ones, sorry :-(

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 28 January 2020 8:45
by Sherco49
OK,thanks for your answer
Yes i tried it with 220v, but if the protocol has changed, i can understand the lack of answers ( library pzemt30v30 ?).
just have to find a 3.0 solution

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 28 January 2020 16:17
by Sherco49
So i solved my problem abandoning Espeasy and using multi instances of Software serial, it works even if it not the most elegant way

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 28 January 2020 20:07
by salvacalatayud
Sherco49 wrote:So i solved my problem abandoning Espeasy and using multi instances of Software serial, it works even if it not the most elegant way
Tasmota is suposed to work, i'll test in a few days

Enviado desde mi Mi A2 mediante Tapatalk


Re: Energy measurement with espeasy and pzem-004t

Posted: Monday 10 February 2020 15:34
by ABCArt
Hi, pzem users!
Is there any way to calclate day/night power consumption with esp and pzem004 connected to it?
I have already four virtual counters in my Domoticz system for: Voltage, Current, Energy and Power (delivered by espeasy rules from WeMos D1 mini).
The problem is in that Power is counted continiously as increasing value, and i need to divide it into two dummy counters: increasing day power consumtion (kWh) and the samre thing for the night time (kWh). Is it possible to do using some variables/scripts?
And for pzem-004 we have another problem - it drops power usage counter when it reaches 9999 value.

Re: Energy measurement with espeasy and pzem-004t

Posted: Monday 10 February 2020 16:32
by aleph0
Hi !

This is the function I use for this usage

Code: Select all

function pzem_read(pzem,HC,dev_V,dev_A,dev_W,dev_CP)
    --[[Read measures from a pzem in a 3Amps device
    and dispatch measures for voltage, current and power in corresponding devices
    Input :
    pzem : type 3phase current
    HC : switch "On"=night time
    
    Output :
    dev_V : type voltage
    dev_A : type current
    dev_W : type P1 smart counter
    dev_CP : type custom, for cos phi
    
    Variable : you need to create a variable with the same name as the pzem device followed by _idx to store the index
    ]]--

    local u1, u2, p1, p2
    local val_V,val_A,val_W,val_Wh
    local local_dbg=0

    old_Wh=uservariables[pzem.."_idx"]

    u1, u2, p1, p2 = string.match(otherdevices_svalues[dev_W],"(.-);(.-);(.-);(.-);.*")
    -- Usefull for newly created counters
    u1=u1 or 0
    u2=u2 or 0
    p1=p1 or 0
    p2=p2 or 0

    val_V,val_A,val_W,val_Wh=string.match(otherdevices_svalues[pzem],"(.-);(.-);(%d*);(%d*)")
    if local_dbg==1 then
        print(otherdevices_svalues[pzem])
        print("V "..val_V)
        print("A "..val_A)
        print("W "..val_W)
        print("Wh "..val_Wh)
        print("Old Wh "..old_Wh)
        print("------")
    end
    
    if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V) end
    UpdateDev(dev_A,0,val_A)
    
    if tonumber(val_A)>0 and tonumber(val_W)>0 then
        -- If we don't have a measurement for voltage, we take previous one
        if tonumber(val_V)==0 then val_V=otherdevices[dev_V] end
        val_CP=val_W/val_V/val_A
        
        if local_dbg==1 then 
            print("V "..val_V)        
            print("A "..val_A)
            print("W "..val_W)
            print("CP "..val_CP)
        end
        if val_CP>=0 and val_CP<=1 then UpdateDev(dev_CP,0,round(val_CP,2)) end
    end
    
    if tonumber(val_Wh)>=tonumber(old_Wh) then 
        if otherdevices[HC] == 'Off' then
            -- svalue=USAGE1;USAGE2;RETURN1;RETURN2;CONS;PROD
            UpdateDev(dev_W,0,tostring(u1+val_Wh-old_Wh)..';'..tostring(u2)..';0;0;'..tostring(val_W)..';0')
        else
            UpdateDev(dev_W,0,tostring(u1)..';'..tostring(u2+val_Wh-old_Wh)..';0;0;'..tostring(val_W)..';0')
        end    
    end
    if val_Wh>0 then UpdateVar(pzem.."_idx",val_Wh) end
end

Re: Energy measurement with espeasy and pzem-004t

Posted: Wednesday 19 February 2020 13:32
by djelau
Hi,

the solution to work with Espeasy on WEMOS and PZEM-004tv30 (modbus) can be found here

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 03 March 2020 12:03
by yo3hjv
NiCOOLaS wrote: Thursday 23 January 2020 14:08
yo3hjv wrote: Thursday 25 April 2019 4:22 Hello and thank you for the nice "How to".
I did it and it is working.
Seems to work properly, I also included the ">0" mod.

I have only one observation: the "Current" value is showing the last maximum current.
I wonder if someone can help me with LUA script to make the "Current" show the "now" value of the current.

Thank you and please forgive my stupidity.

LE. I think I got it like this:

if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V)
UpdateDev(dev_A,0,val_A) end
-- if tonumber(val_A)>0 then UpdateDev(dev_A,0,val_A) end--
Can you please show full script and how it's run :oops:

Sorry for late answer!

Here is the code:

Code: Select all

--[[Script to read infos from espeasy/pzem-004t and disptach it in correct devices

]]--





-- Edit the dummies name below to match yours

local dev_HC      ="Elec happy hours"

local dev_pzem1   ="pzem1" 

local dev_V1      ="Retea"

local dev_A1      ="Curent_Instant"

local dev_W1      ="Consum"

-- End of user-edit part



function UpdateVar(variable,valeur)

    --Update une variable Domoticz

    commandArray[#commandArray+1] = {['Variable:'..variable] = tostring(valeur)}

end



function UpdateDev(device,nvalue,svalues)

    --Met à jour un device numérique Domoticz

    commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[device]..'|'..tostring(nvalue)..'|'..tostring(svalues)}

end



function pzem_read(pzem,HC,dev_V,dev_A,dev_W)

    --[[Read values from a 3ph-amp dummies and dispatch them in sensor for voltage, current, and power

    

    Input :

    pzem : type 3ph amp, updated by espeasy

    HC : switch "On"=happy hours for electricity

    

    Output :

    dev_V : type voltage

    dev_A : type current

    dev_W : P1 smart counter

    ]]--



    local u1, u2, p1, p2

    local val_V,val_A,val_W,val_Wh

    local local_dbg=0



    old_Wh=uservariables[pzem.."_idx"]



    u1, u2, p1, p2 = string.match(otherdevices_svalues[dev_W],"(.-);(.-);(.-);(.-);.*")

    -- Usefull for newly created counters

    u1=u1 or 0

    u2=u2 or 0

    p1=p1 or 0

    p2=p2 or 0



    val_V,val_A,val_W,val_Wh=string.match(otherdevices_svalues[pzem],"(.-);(.-);(%d*);(%d*)")

    if local_dbg==1 then

        print(otherdevices_svalues[pzem])

        print(val_V)

        print(val_A)

        print(val_W)

        print(val_Wh)

    end

    

    if tonumber(val_V)>1 then UpdateDev(dev_V,0,val_V) 

                              UpdateDev(dev_A,0,val_A) end

  --  if tonumber(val_A)>0 then UpdateDev(dev_A,0,val_A) end--

    if tonumber(val_Wh)>=tonumber(old_Wh) then 

        if otherdevices[HC] == 'Off' then

            -- svalue=USAGE1;USAGE2;RETURN1;RETURN2;CONS;PROD

            UpdateDev(dev_W,0,tostring(u1+val_Wh-old_Wh)..';'..tostring(u2)..';0;0;'..tostring(val_W)..';0')

        else

            UpdateDev(dev_W,0,tostring(u1)..';'..tostring(u2+val_Wh-old_Wh)..';0;0;'..tostring(val_W)..';0')

        end

        UpdateVar(pzem.."_idx",val_Wh)

    end

end



commandArray = {}



if devicechanged[dev_pzem1] then pzem_read(dev_pzem1,dev_HC,dev_V1,dev_A1,dev_W1) end



return commandArray
Image
I monitor the instant current even when there is no consumption. I like to see when it's starting and when it's stopping.
Best regards, Adrian

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 30 May 2020 8:59
by Dane01000
Bonjour, je suis ce fil depuis quelques jours et n'arrive pas à m'en sortir seul.
J'ai un seul PZEM-004T V30 sur WEMOS D1 Mini et tourne sur un firmware perso ESPEASY.
J'ai bien mes valeurs dans ESPEASY, je n'arrive à envoyer que Voltage dans Domoticz.
J'ai essayé avec Rules par plusieurs moyens dans Domoticz (capteurs virtuels....) mais je ne reçoit rien

Rules Espeasy

on PZEM#Current do

SendToHTTP 192.168.1.151,8080,/json.htm?type=command&param=udevice&idx=1402&nvalue=0&svalue=[PZEM#Voltage]
SendToHTTP 192.168.1.151,8080,/json.htm?type=command&param=udevice&idx=1403&nvalue=0&svalue=[PZEM#Current]
SendToHTTP 192.168.1.151,8080,/json.htm?type=command&param=udevice&idx=1404&nvalue=0&svalue=[PZEM#Power]
SendToHTTP 192.168.1.151,8080,/json.htm?type=command&param=udevice&idx=1405&nvalue=0&svalue=[PZEM#Energy]

endon
Capture1.JPG
Capture1.JPG (82.03 KiB) Viewed 13226 times
Capture2.JPG
Capture2.JPG (121.23 KiB) Viewed 13226 times
Capture3.JPG
Capture3.JPG (222.72 KiB) Viewed 13226 times

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 30 May 2020 9:02
by Dane01000
Capture4.JPG
Capture4.JPG (115.19 KiB) Viewed 13225 times
Capture5.JPG
Capture5.JPG (110.05 KiB) Viewed 13225 times
Pouvez-vous m'aider je ne suis que débutant en script,
Je ne sais pas ce que j'ai oublié dans Domoticz ou ESPEASY.

Merci de m'aider

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 23 June 2020 14:25
by Vladio
hi

Re: Energy measurement with espeasy and pzem-004t

Posted: Sunday 14 February 2021 14:14
by spike318
can some please help me with this subject or renew it i can't see the pictures,

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 20 February 2021 9:45
by tontze
spike318 wrote: Sunday 14 February 2021 14:14 can some please help me with this subject or renew it i can't see the pictures,
All pictures are there :)

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 12 February 2022 19:36
by eremuson
Hi,
Are you able to share the original pictures of the beginning of this tread ?
I can not see its...
Sorry
Eric

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 12 February 2022 20:38
by waltervl
eremuson wrote: Saturday 12 February 2022 19:36 Hi,
Are you able to share the original pictures of the beginning of this tread ?
I can not see its...
Sorry
Eric
Please reload the page. Something's the webserver acts strange.I can see all the images.

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 12 February 2022 20:51
by jvdz
waltervl wrote: Saturday 12 February 2022 20:38
eremuson wrote: Saturday 12 February 2022 19:36 Hi,
Are you able to share the original pictures of the beginning of this tread ?
I can not see its...
Sorry
Eric
Please reload the page. Something's the webserver acts strange.I can see all the images.
That means you allow to show external links that have an invalid certificate! ;)
SO... those images are stored on server with a different domainname than the link contains ...hence the CERT error and them not being displayed.

Re: Energy measurement with espeasy and pzem-004t

Posted: Tuesday 15 March 2022 13:07
by mojso
Thanks, it works great for now. only kWh need to be converted to Wh P1 meter ( Domoticz)

Re: Energy measurement with espeasy and pzem-004t

Posted: Thursday 21 December 2023 11:48
by psubiaco
Maybe you can try the new PZEM plugin that permits to connect up to 51 PZEM meters to the same bus, using a cheap RS485/USB adapter or RS485/net/wifi module: https://github.com/CreasolTech/domoticz-pzem-016

Actually it was tested with PZEM-004T, PZEM-014 and PZEM-016.

Device names can be translated in your preferred language: if you write here the translated device names and language code, I can add that language in the plugin.

Many thanks for any feedback / suggestion / translation !
domoticz-pzem-016-screenshot.jpg
domoticz-pzem-016-screenshot.jpg (85.45 KiB) Viewed 9658 times
domoticz-pzem-016-hardware.png
domoticz-pzem-016-hardware.png (71.65 KiB) Viewed 9658 times

Re: Energy measurement with espeasy and pzem-004t

Posted: Saturday 06 January 2024 3:32
by mrfunk
psubiaco wrote: Thursday 21 December 2023 11:48 Maybe you can try the new PZEM plugin that permits to connect up to 51 PZEM meters to the same bus, using a cheap RS485/USB adapter or RS485/net/wifi module:

Actually it was tested with PZEM-004T, PZEM-014 and PZEM-016.

Device names can be translated in your preferred language: if you write here the translated device names and language code, I can add that language in the plugin.

Many thanks for any feedback / suggestion / translation !
Thanks for making this!!!!

Unfortunately I just can't read data 😭😭 my PZEM-004T has both tx,/Rx LEDs flashing, and if I flip the polarity of the rs 485 they stop. I'm using a pi with a usb 2wire 485:adapter as shown on the GitHub tutorial. I installed plugin via the plugin manager. I'm not sure if this is an issue with pyserial or the other module? I've tried installing pyserial bit get thrown an error.. is this installed as part of the plugin? Same with the other file.
I'm selecting USB0 from the drop-down

Any help obviously appreciated.