forked from budda/hc2-scenes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnight_time.lua
27 lines (20 loc) · 870 Bytes
/
night_time.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
--[[
%% autostart
%% properties
%% globals
--]]
while true do
local currentDate = os.date("*t");
local sunriseHour = fibaro:getValue(1, 'sunriseHour');
local sunsetHour = fibaro:getValue(1, 'sunsetHour');
local currentSec = tonumber(currentDate.hour) * 60 + tonumber(currentDate.min);
local sunriseSec = tonumber(string.sub(sunriseHour, 1, 2)) * 60 + tonumber(string.sub(sunriseHour, 4));
local sunsetSec = tonumber(string.sub(sunsetHour, 1, 2)) * 60 + tonumber(string.sub(sunsetHour, 4));
if (currentSec>sunriseSec and currentSec<sunsetSec) then
fibaro:setGlobal("NightTime", "0");
else
fibaro:setGlobal("NightTime", "1");
end
fibaro:debug('Now: ' .. currentSec .. '; Sunrise: ' .. sunriseSec .. '; Sunset: ' .. sunsetSec .. '; Night: ' .. fibaro:getGlobal("NightTime") .. ';');
fibaro:sleep(60000*10);
end