-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdimmer.lua
80 lines (59 loc) · 1.63 KB
/
dimmer.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--[[
%% autostart
%% properties
%% weather
%% events
%% globals
--]]
if (fibaro:countScenes() > 1) then
fibaro:abort();
end
--your dimmer ID
local dimmerDeviceId = 109;
while true do
sunrise = fibaro:getValue(1, "sunriseHour");
sunset = fibaro:getValue(1, "sunsetHour");
for token in string.gmatch(sunrise, "([^:]*)") do
if(tonumber(token)) then
if(sunriseHours and (not sunriseMin)) then
sunriseMin=tonumber(token);
end
if(not sunriseHours) then
sunriseHours=tonumber(token);
end
end
end
for token in string.gmatch(sunset, "([^:]*)") do
if(tonumber(token)) then
if(sunsetHours and (not sunsetMin)) then
sunsetMin=tonumber(token);
end
if(not sunsetHours) then
sunsetHours=tonumber(token);
end
end
end
--fibaro:debug('Sunrise: ' .. sunriseHours .. ':' .. sunriseMin);
--fibaro:debug('Sunset: ' .. sunsetHours .. ':' .. sunsetMin);
hours = tonumber(os.date("%H"));
mins = tonumber(os.date("%M"));
if((hours>sunriseHours and hours<sunsetHours) or (hours==sunriseHours and sunriseMin<mins) or (hours==sunsetHours and sunsetMin>mins)) then
state = fibaro:getValue(dimmerDeviceId, 'value');
if(state == "99") then
fibaro:call(dimmerDeviceId, "turnOff");
--fibaro:debug('day, turning off');
else
--fibaro:debug('day, turned off');
end
else
state = fibaro:getValue(dimmerDeviceId, 'value');
if(state == "0") then
fibaro:call(dimmerDeviceId, "turnOn");
--fibaro:debug('night, turning on');
else
--fibaro:debug('night, turned off');
end
end
--run every minute
fibaro:sleep(60000);
end