Je me suis inspiré de ce post https://www.domoticz.com/forum/viewtopi ... 14&t=20820 pour fabriquer mon wattmetre avec un ESPeasy et un pzem-004t
J'utilise le script ci-dessous pour afficher les données du pzem et en extraire la tension, l'intensité, la puissance active et la consommation.
Code : Tout sélectionner
--[[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 ="Heures Creuses"
local dev_pzem1 ="pzem"
local dev_V1 ="Tension"
local dev_A1 ="Intensité"
local dev_W1 ="Puissance"
-- 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) end
if tonumber(val_A)>1 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 commandArrayJe souhaiterai afficher un deuxième compteur de puissance réactive (simplement U x I) en plus de celui de puissance active. J'ai tenté de modifier le script ci-dessus sans succès (mes connaissances en lua étant assez basiques).
Merci d'avance pour votre aide.