Hi all,
After a long time, i got it finally working. (my knowlegde go LUA is almost 0)
I would like that the lights only getting on when the house is in evening or night status.
Or maybe even better when also/or the LUX is getting below 60..
This code for updating my house state:
[
%% properties
%% autostart
%% globals
--]]
-- Scene : Time of Day
-- Version : 6.0.3
-- Release Date : 14 January 2016
-- Compatibility : Home Center 2, v4.030 to v4.063 Beta
-- Purpose : Check time of day and Set global variable
-- Trigger : None
-- Contributors : Fibaro Forum - petergebruers, boerremk and many others who have shared bits of scripts in the forum
-------------------- Configuration - Scene Info
sceneName = "Time of Day";
sceneVersion = "6.0.3";
-------------------- Configuration - Time Offsets
-- Set the offset time in minutes
-- Set positive offset value for after Sun-rise/set, negative value for before Sun-rise/set, zero for no offset
offsetSunrise = 0;
offsetSunset = -50;
-------------------- Configuration - Debug Parameters
local dispExtDebug = false;
-------------------- Script Functions
-------------------- Function: Fibaro Debug Message with Color
function fDebug(color, message)
fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
end
-------------------- Function: Fibaro Wait Time
function fSleep(stime)
fibaro:sleep(stime);
end
-------------------- Function: toTimestamp
local function toTimestamp(time, offset)
currDate = os.date("*t");
hours, minutes = time:match("^(%d+)%d+)");
return os.date("%H:%M", os.time({ year=currDate.year, month=currDate.month, day=currDate.day, hour=hours, min=minutes, sec=seconds }) + (offset*60))
end
-------------------- Validate Source Trigger
local sourceTrigger = fibaro:getSourceTrigger()
fDebug("green", "Script started because of: " .. sourceTrigger["type"]);
-------------------- Validate Number of Scene Instance
fSleep(50);
if (fibaro:countScenes()>1) then
if (dispExtDebug) then
fDebug("yellow", "Scene, " .. sceneName .. " is already running with " .. fibre:countScenes() .. " instances!");
fDebug("yellow", "Aborting additional instance(s)!");
end
fibaro:abort();
end
-------------------- Start of Scene Execution
if (sourceTrigger["type"] == "autostart") then
while true do
local currDate = os.date("*t");
local currTime = os.date("%H:%M");
---------------- Time-string Manipulation
---------------- %02u means unsigned int, 2 wide, leading zero
currTimeAsString = string.format("%02u",currDate.hour) .. ":" .. string.format("%02u", currDate.min)
varTimeOfDay = fibaro:getGlobalValue("TimeOfDay")
if (dispExtDebug) then
fDebug("Time of Sunrise: " .. fibaro:getValue(1, "sunriseHour"));
fDebug("green", "Time of Sunset: " .. fibaro:getValue(1, "sunsetHour"));
end
fDebug("green", "Current Time: " .. currTimeAsString);
if (dispExtDebug) then
fDebug("green", "Current Time of Day: " .. varTimeOfDay);
end
if
---------------- Morning
currTime == toTimestamp((fibaro:getValue(1, "sunriseHour")), offsetSunrise) then
if (dispExtDebug) then
fDebug("grey", "Time of Offset Sunrise: " .. toTimestamp((fibaro:getValue(1, "sunriseHour")), offsetSunrise));
end
fDebug("grey", "Setting Time of Day as Morning");
fibaro:setGlobal("TimeOfDay", "Morning");
elseif
---------------- Afternoon
currTime == "11:00" then
fDebug("grey", "Setting Time of Day as Day");
fibaro:setGlobal("TimeOfDay", "Day");
elseif
---------------- Evening
currTime == toTimestamp((fibaro:getValue(1, "sunsetHour")), offsetSunset) then
if (dispExtDebug) then
fDebug("grey", "Time of Offset Sunset: " .. toTimestamp((fibaro:getValue(1, "sunsetHour")), offsetSunset));
end
fDebug("grey", "Setting Time of Day as Evening");
fibaro:setGlobal("TimeOfDay", "Evening");
elseif
---------------- Night
currTime == "23:00" then
fDebug("grey", "Setting Time of Day as Night");
fibaro:setGlobal("TimeOfDay", "Night");
elseif
---------------- Dawn
currTime == "06:00" then
fDebug("grey", "Setting Time of Day as Morning");
fibaro:setGlobal("TimeOfDay", "Morning");
else
---------------- No Match
fDebug("orange", "Current time does not match any scenario.");
end
------------------ Once Per 55 Seconds Wake-up
fSleep(55*1000);
end ---------------- End of Infinite While-loop
fDebug("Scene not started, this is autostart-only!")
end ------------------ End of sourceTrigger["type"] == "autostart"