Hi,
I had the requirement for a very simple scheduler. The code below is a stripped down version of @Sankotronic Main Scene code and just contains the Scene Scheduler. Thanks to @Sankotronic for his permission to post this.
-- SIMPLE SCHEDULER.
-- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC
--[[
%% autostart
%% properties
%% globals
--]]
if (fibaro:countScenes() > 1) then fibaro:abort(); end
local jT = json.decode(fibaro:getGlobalValue("HomeTable")); -- comment out if you don't use a hometable
local currenttime = os.date('*t');
local currentwday = currenttime['wday'];
local TimeCurrent = os.date("%H:%M", os.time());
-- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma)
local runSceneSchedName = {"Test Scene 1", "Test Scene 2"}; -- Add scene names
local runSceneSchedID = {641, jT.scene.Wakeup}; -- add scene ID's or references
local runSceneSchedHour = {{"21:47"}, {"07:30"}}; -- Add times to run the scenes
local runSceneSchedWeek = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array
function doSceneSched()
if #runSceneSchedID > 0 then
for i = 1, #runSceneSchedID do
if runSceneSchedWeek[i][currentwday] == 1 then
for t = 1, #runSceneSchedHour[i] do
if runSceneSchedHour[i][t] == TimeCurrent then
fibaro:startScene(runSceneSchedID[i]); end
end
end
end
end
end
-- MAIN LOOP
while true do
currenttime = os.date('*t');
currentwday = currenttime['wday'];
TimeCurrent = os.date("%H:%M", os.time());
doSceneSched();
fibaro:sleep(59700);
end
The full Main Scene code can be found at https://forum.fibaro.com/index.php?/topic/23510-scene-main-scene-for-time-based-events-control-v-125/
I thought this many be useful for some new users starting out or those like me that need a simple yet well written scheduler and may even be a stepping stone for some to the full Main Scene.
-f