Di seguto un esempio di programmazione in LUA per accendere e spegnere ad orari programmati uno o più disposistivi
se l'ora e il giorno della settimana sono quelli indicati nei cicli IF mi esegue l'azione in questo accende alle 9.30 (prima if) o spegne alle 21,30 (seconda if) tutti i giorni il dispositivo con ID 201
il dispositivo identificato con ID 201 potrebbe essere ad esempio questo:
e questo è il suo schema
ed ecco il codice:
--[[
%% 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 ((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) == "09:30") )then
fibaro:call(201, "turnOn");
fibaro:debug("ON");
-- qui posso inserire altre if con tempi diversi e dispositivi diversi....
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) == "21:30") )then
fibaro:call(201, "turnOff");
fibaro:debug("OFF");
-- qui posso inserire altre if con tempi diversi e dispositivi diversi....
end
setTimeout(tempFunc, 60*1000);
end