Aller au contenu

Messages recommandés

Posté(e)

Bonjour,

 

Je me suis inspiré d'un code LUA permettant de gérer des radiateurs comprenant un mode AUto/ manuel et gérant les 4 ordres du fil pilote.

Il n'y a pas de scenes mais que des modules virtuels

Cela semble fonctionner correctement car mes radiateurs se declenche bien en fonction de la programmation mais une chose m'interpelle et je me demande si c'est bien normal.

 

Il semble qu'un ordre est envoyé toutes 2/3 secondes a mes FGS221 car je vois dans la console de la HC2 :"transfert ok" sur tout mes FGS! 

 

Est ce normal?

 

Merci pour vos avis

Posté(e)

Si tu as mis le code dans la main loop d'un module virtuel, c'est normal, car c'est une boucle avec un sleep(3000) automatiquement.

Après àvoir comment tu as codé ton script.

Posté(e)

en effet, j'ai mis le code dans le mainloop de chaque module virtuel.

ca correspond donc a un fonctionnement "normal" en correspondance avec la manière dont le code est implanté.

 

je débute sur HC2 et LUA et je pense que mon code (enfin celui que j'ai adapté) est trop simpliste et surtout pas optimisé

 

il existe donc une mainloop générale a la HC2 et pas seulement a chaque module virtuelle/scène?

 

J'avoue que j'ai du mal a piger la logique de fonctionnement de la box.

 

les modules virtuels (enfin leur mainloop) sont comme des programmes qui fonctionnent en permanence? 

Posté(e)

La boucle n'est pas générale à  la HC2, mais propre à  chaque module virtuel.

 

En fait (et pour te paraphraser partiellement) :

- Les mainloop des modules virtuels sont des programmes qui fonctionnent en permanence.... jusqu'à  ce qu'ils plantent (ce qui peut arriver). En cas de plantage, seul un redémarrage de la box ou une sauvegarde du module virtuel permet de les redémarrer

- Par défaut, il y a un délai de 3s entre chaque intération de la main loop.

- les boutons des modules virtuels ne sont exécutés qu'une seule fois

=> de manière générale, on conseille de mettre le code complexe dans des boutons, et la mainloop se charge de "cliquer" sur les boutons à  intervale régulier. Le plus souvent on ne conserve par les 3s de base, et on ajoute un délai en fonction de l'application voulue (par exemple 60s, ou plus, ça dépend)

 

En ce qui concerne les scènes, son code n'est appelé qu'une seule fois (comme les boutons de modules virtuels).

Donc pour une scène qui doit fonctionner non-stop, à  nous de mettre une boucle "while true do" avec le sleep() qui va bien. Un bon exemple est le script GEA bien connu sur ce forum.

Posté(e)

oui justement, je lorgne sur GEA en ce moment. J'essaye de comprendre comment il fonctionne. 

 

Pour le code que j'utilise, voici ce qui se trouve dans la mainloop d'un module qui sert de thermostat pour une zone donnée avec la gestion d'un programme1 et d'un programme2 (en gros prog1 = semaine et prog2= weekend)


--[[
%% properties
%% globals
--]]
-- LUA - heat Engine V2.0.0
--
--
--variables globales à  déclarer: zbas_heat_engine = Auto, Prog1, Prog2, Confort, Eco, Hors-gel, Arret.
--variables globales à  déclarer: zbas_heat_mode = Confort, Eco, Hors-gel, Arret.

-------------------------------------------------------------------------------------------------------------
-- USER SETTINGS : --
-------------------------------------------------------------------------------------------------------------
---------------------
-- Paramètres généraux:
---------------------

local debug = true; --activer le mode debug
local ID_virtual_module = "38";


-----------------------------------
-- Definir les différents programmes:
-----------------------------------
local zbas_time_1 = "06:00";
local zbas_heat_mode_1_2_prog1 = "Confort";
local zbas_heat_mode_1_2_prog2 = "Eco";
local zbas_time_2 = "07:30";
local zbas_heat_mode_2_3_prog1 = "Eco";
local zbas_heat_mode_2_3_prog2 = "Confort";
local zbas_time_3 = "14:00";
local zbas_heat_mode_3_4_prog1 = "Eco";
local zbas_heat_mode_3_4_prog2 = "Confort";
local zbas_time_4 = "18:00";
local zbas_heat_mode_4_5_prog1 = "Confort";
local zbas_heat_mode_4_5_prog2 = "Confort";
local zbas_time_5 = "22:00";
local zbas_heat_mode_5_6_prog1 = "Eco";
local zbas_heat_mode_5_6_prog2 = "Confort";
local zbas_time_6 = "23:59";
local zbas_heat_mode_6_1_prog1 = "Eco";
local zbas_heat_mode_6_1_prog2 = "Eco";


-----------------------------------------------------------------------------------------
--Définition du programme automatique de la semaine: un mode au choix pour chaque jour (Prog1, Prog2, Confort, Eco, Hors-gel, Arret):
-----------------------------------------------------------------------------------------
local zbas_Monday_auto = "Prog1";
local zbas_Tuesday_auto = "Prog1";
local zbas_Wednesday_auto = "Prog1";
local zbas_Thursday_auto = "Prog1";
local zbas_Friday_auto = "Prog1";
local zbas_Saturday_auto = "Prog2";
local zbas_Sunday_auto = "Prog2";




-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-- -- DO NOT EDIT THE CODE BELOW (except to suit your needs) -- --
-------------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------------------


heatEngine = {
version = "1.0.0"
};


local zbas_heat_engine = fibaro:getGlobal("zbas_heat_engine");




local minute = 60000 --in milliseconds
local currentDate = os.date("*t");
local currentTime = string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min);
local zbas_heat_mode = fibaro:getGlobal("zbas_heat_mode");




--wday=1 is Sunday
--wday=2 is Monday
--wday=3 is Tuesday
--wday=4 is Wednesday
--wday=5 is Thursday
--wday=6 is Friday
--wday=7 is Saturday


if (zbas_heat_engine == "Confort") then
zbas_heat_mode= "Confort";
end


if (zbas_heat_engine == "Eco") then
zbas_heat_mode= "Eco";
end


if (zbas_heat_engine == "Hors-gel") then
zbas_heat_mode= "Hors-gel";
end


if (zbas_heat_engine == "Arret") then
zbas_heat_mode= "Arret";
end


if (zbas_heat_engine == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end


if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end


if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end


if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end


if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end


if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end


end




if (zbas_heat_engine == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end


if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end


if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end


if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end


if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end


if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end


end




if (zbas_heat_engine == "Auto") then
if (currentDate.wday == 1 ) then
if zbas_Sunday_auto == "Confort" or zbas_Sunday_auto == "Eco" or zbas_Sunday_auto == "Hors-gel" or zbas_Sunday_auto == "Arret" then
zbas_heat_mode = zbas_Sunday_auto;
end
if (zbas_Sunday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end


if (zbas_Sunday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 2 ) then
if zbas_Monday_auto == "Confort" or zbas_Monday_auto == "Eco" or zbas_Monday_auto == "Hors-gel" or zbas_Monday_auto == "Arret" then
zbas_heat_mode = zbas_Monday_auto;
end
if (zbas_Monday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end


if (zbas_Monday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 3 ) then
if zbas_Tuesday_auto == "Confort" or zbas_Tuesday_auto == "Eco" or zbas_Tuesday_auto == "Hors-gel" or zbas_Tuesday_auto == "Arret" then
zbas_heat_mode = zbas_Tuesday_auto;
end
if (zbas_Tuesday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end


if (zbas_Tuesday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 4 ) then
if zbas_Wednesday_auto == "Confort" or zbas_Wednesday_auto == "Eco" or zbas_Wednesday_auto == "Hors-gel" or zbas_Wednesday_auto == "Arret" then
zbas_heat_mode = zbas_Wednesday_auto;
end
if (zbas_Wednesday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end
if (zbas_Wednesday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 5 ) then
if zbas_Thursday_auto == "Confort" or zbas_Thursday_auto == "Eco" or zbas_Thursday_auto == "Hors-gel" or zbas_Thursday_auto == "Arret" then
zbas_heat_mode = zbas_Thursday_auto;
end
if (zbas_Thursday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end


     if (zbas_Thursday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 6 ) then
if zbas_Friday_auto == "Confort" or zbas_Friday_auto == "Eco" or zbas_Friday_auto == "Hors-gel" or zbas_Friday_auto == "Arret" then
zbas_heat_mode = zbas_Friday_auto;
end
if (zbas_Friday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end


if (zbas_Friday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end


if (currentDate.wday == 7 ) then
if zbas_Saturday_auto == "Confort" or zbas_Saturday_auto == "Eco" or zbas_Saturday_auto == "Hors-gel" or zbas_Saturday_auto == "Arret" then
zbas_heat_mode = zbas_Saturday_auto;
end
if (zbas_Saturday_auto == "Prog1") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog1;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog1;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog1;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog1;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog1;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog1;
end
end
end
if (zbas_Saturday_auto == "Prog2") then
if zbas_time_1 <= zbas_time_2 then
if zbas_time_1 <= currentTime and currentTime <= zbas_time_2 then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
else
if not (zbas_time_2 < currentTime and currentTime < zbas_time_1) then
zbas_heat_mode= zbas_heat_mode_1_2_prog2;
end
end
if zbas_time_2 <= zbas_time_3 then
if zbas_time_2 <= currentTime and currentTime <= zbas_time_3 then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
else
if not (zbas_time_3 < currentTime and currentTime < zbas_time_2) then
zbas_heat_mode= zbas_heat_mode_2_3_prog2;
end
end
if zbas_time_3 <= zbas_time_4 then
if zbas_time_3 <= currentTime and currentTime <= zbas_time_4 then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
else
if not (zbas_time_4 < currentTime and currentTime < zbas_time_3) then
zbas_heat_mode= zbas_heat_mode_3_4_prog2;
end
end
if zbas_time_4 <= zbas_time_5 then
if zbas_time_4 <= currentTime and currentTime <= zbas_time_5 then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
else
if not (zbas_time_5 < currentTime and currentTime < zbas_time_4) then
zbas_heat_mode= zbas_heat_mode_4_5_prog2;
end
end
if zbas_time_5 <= zbas_time_6 then
if zbas_time_5 <= currentTime and currentTime <= zbas_time_6 then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
else
if not (zbas_time_6 < currentTime and currentTime < zbas_time_5) then
zbas_heat_mode= zbas_heat_mode_5_6_prog2;
end
end
if zbas_time_6 <= zbas_time_1 then
if zbas_time_6 <= currentTime and currentTime <= zbas_time_1 then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
else
if not (zbas_time_1 < currentTime and currentTime < zbas_time_6) then
zbas_heat_mode= zbas_heat_mode_6_1_prog2;
end
end
end
end
end


fibaro:sleep(1000);
fibaro:setGlobal("zbas_heat_mode", zbas_heat_mode);


if (debug) then
local mode = "init";
if (currentDate.wday == 1 ) then
mode = zbas_Sunday_auto;
end
if (currentDate.wday == 2 ) then
mode = zbas_Monday_auto;
end
if (currentDate.wday == 3 ) then
mode = zbas_Tuesday_auto;
end
if (currentDate.wday == 4 ) then
mode = zbas_Wednesday_auto;
end
if (currentDate.wday == 5 ) then
mode = zbas_Thursday_auto;
end
if (currentDate.wday == 6 ) then
mode = zbas_Friday_auto;
end
if (currentDate.wday == 7 ) then
mode = zbas_Saturday_auto;
end
if (zbas_heat_engine == "Auto") then
fibaro:debug("Le mode du thermostat est réglé sur: " ..zbas_heat_engine.." . Le mode auto est réglé sur "..mode);
end
if (zbas_heat_engine ~= "Auto") then
fibaro:debug("Le mode du thermostat est réglé sur:" ..zbas_heat_engine);
end


fibaro:debug("Le mode de chauffage est: " ..zbas_heat_mode);
fibaro:call(ID_virtual_module, "setProperty", "ui.Label3.value", zbas_heat_mode)
fibaro:sleep(15000)
end

 

Posté(e)

A quand même y'a du code...

Pour revenir au propo de Laser, en effet le mainloop est pas vraiment top pour certain code qui demande de tourner en boucle!

Je dis peut être une bêtise mais ça fonctionne pour moi:

Je crée dans la mainloop une variable au démarrage a=0

Je mets par la suite un "while true do"

Est la condition qui bloquera la boucle...

a=0

While true do

If a==0 then

fibaro:call(Id, "setValue", Value);

a=1

End

Fibaro:sleep(500)

End

Voilàcomme la variable est passée a 1 elle ne retourne pas dans la condition !

En effet il faut vraiment être aux aguets avec la petite les bleus du zwave!

Sur cette combine je veux bien un retour si je me plante sur la méthode !

Posté(e)

@Xylo, je ne suis pas développeur, mais à  mon avis tu peux faire une méga optimisation. Car copier/coller plusieurs fois le même code en changeant juste quelques paramètres, ce n'est pas très joli...

 

@turlututu74, si je comprends bien, ta variable permet de faire comme si tu passais une seule fois dans la main loop.

Mais dans ce cas, pourquoi ne pas faire un fibaro:abort() qui l'arrêtera immédiatement ?

Posté(e)

@Lazer, je suis plus que d'accord avec toi! :-)

il résulte de ce code une latence certaine. Comme je le disais, ce n'est qu'une adaptation d'un code repris. Je l'ai "posé" ainsi pour dans un premier temps comprendre le mode de fonctionnement de la box.

 

Sachant que je souhaite par la suite gérer des variables comme la période de l'année (les saisons), mes capteurs de température intérieur, un capteur de température extérieure, tout cela indexé sur google calendar.... autant dire que je n'en suis qu'au début de la tache! :-) Par chance, j'ai un développeur a mon taf qui songe a s'équiper d'une box, je vais lui soumettre l'idée! :-P

 

GEA peut être un bon commencement a mon projet.

Posté(e)

@ Laser, fibaro:abort() m'arrête le script tout simplement quoi que dans un mainloop je sais pas comment il gère cette commande ! je vais tester.

Avec ma variable local je suis sur qu'il ne refera pas un nouveau passage sur la commande.

 

j’intègre dans le mainloop un "while true do" !!!

J'ai ce type de méthode qui fonctionne bien pour mon inter tactile, en plus je boost le "while true do" avec un Fibaro:sleep(200) et toujours dans le mainloop.

Je n'ai pas de plantage pour le moment, et en plus la fonction de Krikroff pour récupérer les valeurs des modules rgbw fonctionne en permanence dans cette boucle et après plusieurs essai c'est plus réactif que dans une scène !!!

Posté(e)

OK, mais alors avec un si petit sleep (ne pas rire) tu fais bosser la main loop non-stop, ça ne surcharge pas le CPU de la box ?

  • Upvote 2
Posté(e)

Vous êtes grave les gars...

J ai pas mal de choses dans le sleep au niveau du mainloop. Mais je dois dire que ça fonctionne pas mal pas de plantage. J ai pourtant quelques requêtes et appels pour mon inter tactile...

Ça fonctionne bien!

Pour le sleep on en restera la sinon ça va jaser!

×
×
  • Créer...