Re: Repartition Consommation HC / HP...
Publié : 07 août 2020, 17:22
C'est DomoticZ qui gère les deux usages jours/nuit nativement dans le device de compteur (ce n'est pas celui de puissance)
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/

Code : Tout sélectionner
-- script de type DEVICE
local capteurKWH = 'OWL_Intuition' -- nom du capteur remontant des kwh
local capteurW = 'OWL1' -- nom du capteur remontant des watt
local memo = 'CONSO_LAST' -- nom de la variable utilisateur de type chaîne pour mémo
local CptHP = 'Compteur Electrique HP' -- nom du capteur virtuel de type intant+compter pour les heures pleines
local CptHC = 'Compteur Electrique HC' -- nom du capteur virtuel de type intant+compter pour les heures creuse
local debutHP = '07:00' -- heure au format '00:00' de début de la plage heures pleines
local finHP = '22:00' -- heure au format '00:00' de fin de la plage heures pleines
-- initialisation
local init = true -- true = mettre les capteurs virtuels à zero
-- false = fonctionnement normal du script
-- fin de la partie modifiable
commandArray = {}
-- initialisation
if init then
commandArray['Variable:'..memo] = 'HP;0'
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHP] .. "|0|0;0"}
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHC] .. "|0|0;0"}
print("script HP HC initialisé")
print("penser à passer init à false")
do return end
end
-- récupère l'heure actuelle au format '00:00'
local heure = string.sub(os.date("%X"), 1, 5)
-- lancement du script sur détection maj compteur
if devicechanged[capteurW] then
-- extraction valeurs compteurs physiques
val_1, val_2 = otherdevices_svalues[capteurW]:match("([^;]+);([^;]+)")
local watt = tonumber(val_1)
val_1, val_2 = otherdevices_svalues[capteurKWH]:match("([^;]+);([^;]+)")
local kwh = tonumber(val_2)
-- lecture memo
val_1, val_2 = uservariables[memo]:match("([^;]+);([^;]+)")
local cycle_last = val_1
local kwh_last = tonumber(val_2)
-- en HP
if heure > debutHP and heure < finHP then
-- détection changement de cycle
if cycle_last == 'HC' then
-- écriture memo
commandArray['Variable:'..memo] = 'HP;'..kwh
end
-- calcul écart
if kwh >= kwh_last then
kwh = kwh - kwh_last
end
-- maj compteur HP
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHP] .. "|0|" .. watt .. ";" .. kwh}
-- maj compteur HC
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHC] .. "|0|0;" .. kwh_last}
-- en HC
else
-- détection changement de cycle
if cycle_last == 'HP' then
-- écriture memo
commandArray['Variable:'..memo] = 'HC;'..kwh
end
-- calcul écart
if kwh >= kwh_last then
kwh = kwh - kwh_last
end
-- maj compteur HP
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHP] .. "|0|0;" .. kwh_last}
-- maj compteur HC
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[CptHC] .. "|0|" .. watt .. ";" .. kwh}
end
end
return commandArray
Code : Tout sélectionner
commandArray['Variable:'..memo] = 'HP;0'
attempt to index a nil value (global 'commandArray')
Code : Tout sélectionner
commandArray = {}
Code : Tout sélectionner
-- fin de la partie modifiable
Code : Tout sélectionner
-- extraction valeurs compteurs physiques
val_1, val_2 = otherdevices_svalues[capteurW]:match("([^;]+);([^;]+)")
local watt = tonumber(val_1)
val_1, val_2 = otherdevices_svalues[capteurKWH]:match("([^;]+);([^;]+)")
local kwh = tonumber(val_2)
-- lecture memo
val_1, val_2 = uservariables[memo]:match("([^;]+);([^;]+)")Code : Tout sélectionner
print(otherdevices_svalues['OWL_Intuition'])
print(otherdevices_svalues['OWL1'])
2020-08-07 15:16:09.564 Status: LUA: 0.000;18882.000
2020-08-07 15:16:09.564 Status: LUA: 640.000;0.000
Code : Tout sélectionner
-- extraction valeurs compteurs physiques
--val_1, val_2 = otherdevices_svalues[capteurW]:match("([^;]+);([^;]+)")
val_1 = otherdevices_svalues[capteurW]:match("([^;]+)")
val_2 = otherdevices_svalues[capteurW]:match("([^;]+)")
local watt = tonumber(val_1)
--val_1, val_2 = otherdevices_svalues[capteurKWH]:match("([^;]+);([^;]+)")
val_0, val_1 = otherdevices_svalues[capteurKWH]:match("([^;]+);([^;]+)")
val_0, val_2 = otherdevices_svalues[capteurKWH]:match("([^;]+);([^;]+)")
local kwh = tonumber(val_2)Code : Tout sélectionner
val_1, val_2 = uservariables[memo]:match("([^;]+);([^;]+)")
attempt to index a nil value (field '?')
Code : Tout sélectionner
local memo = 'CONSO_LAST'
-- nom de la variable utilisateur de type chaîne pour mémo

Code : Tout sélectionner
Nom de la variable:
memo
Type de variable:
Chaîne
Valeur de la variable:
CONSO_LAST
Code : Tout sélectionner
val_1, val_2 = uservariables[memo]:match("([^;]+);([^;]+)")Code : Tout sélectionner
attempt to index a nil value (field '?')