1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
-- Ce script permet de remonter la durée de fonctionnement de la chaudière dans un capteur virtuel de type "Counter Incremental"
--------------------------------
------ Variables à éditer ------
--------------------------------
local switch = 'test' -- Nom de l'interrupteur virtuel Chauffage dans Domoticz
local counter = 38 -- Numéro idx du Counter Incremental dans Domoticz
local current_date = (os.date("%d/%m/%Y")) -- Date courante
local current_heure = (os.date("%X")) -- Heure courante
--------------------------------
-- Fin des variables à éditer --
--------------------------------
-------------------
-- Fonction time --
-------------------
time = os.date("*t")
function timedifference(d)
s = otherdevices_lastupdate[d]
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
------------------- --------------------
-- Fonction arrondir à deux décimales --
------------------- --------------------
-- Le chiffre"x" (dec or x) correspond au nombre de décimales à prendre en compte dans le resultat
function arrondir(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 = {}
-----------------------------------------------------------------------------------------------------
--------------------Calcul du temps de fonctionnement de la chaudière -------------------------------
-----------------------------------------------------------------------------------------------------
-- Si chauffage ON incrémentation de la variable Domoticz "Total_compteur" --
if (otherdevices[switch]=='On') then
commandArray['Variable:Total_compteur']= tostring(uservariables["Total_compteur"] +1)
end
-- Envoi de la varaible valeur Total_compteur dans le Custom Counter Valeur_Compteur --
Valeur_Compteur = tostring(uservariables["Total_compteur"])
-- Envoi de la valeur dans le compteur "counter" --
commandArray['UpdateDevice'] = counter .. '|0|' .. tostring(Valeur_Compteur)
-- Envoi des informations dans le LOG si chauffage ON --
if (otherdevices[switch]=='On') then
print("")
print("Cumul du temps de fonctionnement du chauffage "..Valeur_Compteur.." Minutes".." // "..math.floor((Valeur_Compteur/60)).. " Heures")
print("")
end
return commandArray |
Partager