Je souhaite mettre a jour un device virtuel avec le cout de la recharge de mon véhicule électrique
Je récupère bien les valeurs de conso instantané ainsi que la donnée contenant le comptage depuis la création du device, mais....
impossible de recevoir le compteur du jour !
data_day = domoticz.devices('Compteur_Conso_VE').counterToday
ne fonctionne pas...
Auriez vous une idée pour me sortir de cette impasse ?
LOG
2024-11-02 15:20:33.081 Error: EventSystem: in Cout_Charge_VE: [string "local idx = 2714 --idx du device virtual tari..."]:24: attempt to index a nil value (global 'domoticz')
2024-11-02 15:20:38.069 Error: EventSystem: in Cout_Charge_VE: [string "local idx = 2714 --idx du device virtual tari..."]:24: attempt to index a nil value (global 'domoticz')
2024-11-02 15:20:47.089 Error: EventSystem: in Cout_Charge_VE: [string "local idx = 2714 --idx du device virtual tari..."]:24: attempt to index a nil value (global 'domoticz')
2024-11-02 15:20:47.930 Error: EventSystem: in Cout_Charge_VE: [string "local idx = 2714 --idx du device virtual tari..."]:24: attempt to index a nil value (global 'domoticz')
2024-11-02 15:20:52.089 Error: EventSystem: in Cout_Charge_VE: [string "local idx = 2714 --idx du device virtual tari..."]:24: attempt to index a nil value (global 'domoticz')
Code : Tout sélectionner
local idx = 2714 --idx du device virtual tarif charge VE
local compteur_elec = 'Compteur_Conso_VE' --nom du compteur_elec
local prix_kwh = '0.188237'
function round(num, dec)
if num == 0 then
return 0
else
local mult = 10^(dec or 2)
return math.floor(num * mult + 0.5) / mult
end
end
commandArray = {}
if (devicechanged[compteur_elec]) then
-- Récupération des valeurs du compteur
p1, p2 = string.match(otherdevices_svalues[compteur_elec], "(%d+.%d*);(%d+.%d*)")
----------------------------------------------------------------------
-- LA EST MON PROBLEME
data_day = domoticz.devices('Compteur_Conso_VE').counterToday
-- POK data_day = domoticz.devices([compteur_elec]).counterToday
-- POK data_day = domoticz.devices(2674).counterToday
------------------------------------------------------------------------
print('P1', p1 )
print('P2', p2 )
print('Conso du jour', data_day )
-- Calcul du coût en euros
prix_charge_VE = data_day * prix_kwh / 1000
-- Arrondir le prix à 2 chiffres après la virgule
prix_charge_VE = round(prix_charge_VE, 2)
-- Affichage du tarif pour vérification
print('Tarif jour : ', prix_charge_VE)
-- Mise à jour du dispositif virtuel
commandArray[#commandArray+1]={['UpdateDevice'] = idx..'|0|'..prix_charge_VE} ---- mise a jour du device virtuel
end
return commandArray