Page 1 sur 1
blocky et comparaison avec time
Publié : 04 oct. 2018, 20:54
par Douns
Bonjour à tous,
Je suis tout nouveau sur domoticz et je suis actuellement en pleine découverte de ce sympathique outil.
Je voulais réaliser un événement en blocky simple qui me compare l'heure en cours à une heure donné et qui change d'état un interrupteur.
Sauf que je ne comprends absolument pas le résultat : on dirait que la comparaison est délirante, dans tous les cas ma condition est valide et mon interrupteur "test" est allumé!
L'interrupteur "mode_vacance_à_la_maison" me sert juste a reset l'interrupteur "test" et à tester ce script.
Quelqu’un a une idée?

- blocky_time.JPG (30.13 Kio) Consulté 2821 fois
Edit : je suis en V4.9700
Re: blocky et comparaison avec time
Publié : 05 oct. 2018, 07:14
par Tonio16
Douns a écrit : 04 oct. 2018, 20:54
Bonjour à tous,
Je suis tout nouveau sur domoticz et je suis actuellement en pleine découverte de ce sympathique outil.
Je voulais réaliser un événement en blocky simple qui me compare l'heure en cours à une heure donné et qui change d'état un interrupteur.
Sauf que je ne comprends absolument pas le résultat : on dirait que la comparaison est délirante, dans tous les cas ma condition est valide et mon interrupteur "test" est allumé!
L'interrupteur "mode_vacance_à_la_maison" me sert juste a reset l'interrupteur "test" et à tester ce script.
Quelqu’un a une idée?
blocky_time.JPG
Edit : je suis en V4.9700
Salut
J'ai abandonné le blocky pour ce type d'usage sous domoticz car cela ne marchait pas.
Cordialement
Antoine
Re: blocky et comparaison avec time
Publié : 05 oct. 2018, 15:08
par Douns
Dommage, j'aimais bien cette programmation visuelle... Et je ne connaissais pas le LUA.
Bon j'ai passé une bonne partie de la nuit dessus, mais j'ai tout réalisé en LUA et cela fonctionne nickel.
pour ceux que cela intéresse en LUA :
Code : Tout sélectionner
local temperature_eco = 18.5
local temperature_normal = 20
local hysteresis = 0.5
local function split(s, delimiter)
local result = {}
for match in (s..delimiter):gmatch('(.-)'..delimiter) do
table.insert(result, match)
end
return result
end
local function compare_heure(heure_courante, heure_min,heure_max)
local tab_heure_courante={}
local tab_heure_min={}
local tab_heure_max={}
local int_heure_courante
local int_heure_min
local int_heure_max
tab_heure_courante=split(tostring(heure_courante), ":")
tab_heure_min=split(tostring(heure_min), ":")
tab_heure_max=split(tostring(heure_max), ":")
int_heure_courante = (tonumber(tab_heure_courante[1]) * 3600) + (tonumber(tab_heure_courante[2]) * 60) + tonumber(tab_heure_courante[3])
int_heure_min = (tonumber(tab_heure_min[1]) * 3600) + (tonumber(tab_heure_min[2]) * 60) + tonumber(tab_heure_min[3])
int_heure_max = (tonumber(tab_heure_max[1]) * 3600) + (tonumber(tab_heure_max[2]) * 60) + tonumber(tab_heure_max[3])
if int_heure_courante>=int_heure_min and int_heure_courante<int_heure_max then
return true
else
return false
end
end
local function test_temperature_chambre(nom_chambre,temperature_chambre,temperature_consigne,hysteresis,type_test)
if type_test=="inf" then
if temperature_chambre<=(temperature_consigne-hysteresis) then
print("Consigne à : "..temperature_consigne)
print("Chambre "..nom_chambre.." trop froide : "..temperature_chambre)
return true
else
return false
end
else
if temperature_chambre>=(temperature_consigne+hysteresis) then
print("Consigne à : "..temperature_consigne)
print("Chambre "..nom_chambre.." trop chaude : "..temperature_chambre)
return true
else
return false
end
end
end
commandArray = {}
local heure_now = os.date("%X")
local jour = tostring(os.date("%A"))
local temperature_chambre_Tim = tonumber(split(otherdevices['Sonde Chambre Tim'],";")[1])
local temperature_consigne
local drapeau_start_chauffage=0
local drapeau_stop_chauffage=1
if jour=="Sunday" or jour=="Saturday" or otherdevices['Mode Vacance']=='On' then
if compare_heure(heure_now,"08:00:00","20:30:00") then
temperature_consigne=temperature_normal
else
temperature_consigne=temperature_eco
end
else
if compare_heure(heure_now,"06:30:00","08:00:00") or compare_heure(heure_now,"17:00:00","20:30:00") then
temperature_consigne=temperature_normal
else
temperature_consigne=temperature_eco
end
end
--condition test temperature froide
if otherdevices['Chaudiere Gaz']=='Off' then
if test_temperature_chambre("Tim",temperature_chambre_Tim,temperature_consigne,hysteresis,"inf") then
drapeau_start_chauffage=1
end
--ajouter autres pièce à tester ici
if drapeau_start_chauffage==1 then
commandArray['Chaudiere Gaz']='On'
print("Démarrage chaudière")
end
end
if drapeau_start_chauffage==0 then
if otherdevices['Chaudiere Gaz']=='On' then
--condition test temperature chaude
if test_temperature_chambre("Tim",temperature_chambre_Tim,temperature_consigne,hysteresis,"sup")==false then
drapeau_stop_chauffage=0
end
--ajouter autres pièce à tester ici
if drapeau_stop_chauffage==1 then
commandArray['Chaudiere Gaz']='Off'
print("Arret chaudière")
end
end
end
return commandArray