Aller au contenu
robisette

allumage temporisé

Recommended Posts

Bonjour a tous,
Je dois allumer les lumières dès qu'il fait noir et s'éteindre à 23h30, j'ai déjà une scène qui varie une variable du jour au soir, et j'ai créé la scène ci-dessous, malheureusement la nuit je trouve les lumières allumées, quelle erreur ?

"

--[[
%% autostart
%% properties
%% globals
--]]

 -- check script instance count in memory 
if (fibaro:countScenes() > 1) then 
    fibaro:debug("Script already running."); 
    fibaro:abort(); 
end 

fibaro:debug(os.date() .. " - Script start");

function tempFunc()

    local currentDate = os.date("*t");
    
    if fibaro:getGlobalValue("Giorno_Notte") == "Notte"
    and
    ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) < "23:30") )
    then
      fibaro:call(316, "turnOn");
      fibaro:call(47, "turnOn");
      fibaro:call(49, "turnOn");
      fibaro:debug("ON");
    -- MULTIPE MORE THINGS AT DIFFERENT TIMES....
    end
    if ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "23:30") )
    then
      fibaro:call(316, "turnOff");
      fibaro:call(47, "turnOff");
      fibaro:call(49, "turnOff");
      fibaro:debug("OFF");
    -- MULTIPE MORE THINGS AT DIFFERENT TIMES....
    end
    setTimeout(tempFunc, 60*1000);
    
end

tempFunc() -- initial start when the scence is started

"

 

 

Partager ce message


Lien à poster
Partager sur d’autres sites

Perso, je ferais ainsi :

 

- Allumage des lumières lorsque la variable Giorno_Notte passe à "Notte"

- Déclenchement du setTimeout

- Si >= 23:30 alors on éteint.

 

--[[
%% properties
%% globals
Giorno_Notte
--]]

 -- check script instance count in memory 
if (fibaro:countScenes() > 1) then 
    fibaro:debug("Script already running."); 
    fibaro:abort(); 
end 

fibaro:debug(os.date() .. " - Script start");

function tempFunc()

    local currentDate = os.date("*t");

    if (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) >= "23:30") then
      fibaro:call(316, "turnOff");
      fibaro:call(47, "turnOff");
      fibaro:call(49, "turnOff");
      fibaro:debug("OFF");
    -- MULTIPE MORE THINGS AT DIFFERENT TIMES....
    end
    setTimeout(tempFunc, 60*1000);
    
end

if (fibaro:getGlobalValue("Giorno_Notte") == "Notte") then
  fibaro:call(316, "turnOn");
  fibaro:call(47, "turnOn");
  fibaro:call(49, "turnOn");
  fibaro:debug("ON");
-- MULTIPE MORE THINGS AT DIFFERENT TIMES....

  tempFunc();
end

 

Partager ce message


Lien à poster
Partager sur d’autres sites

×