-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path154. Set Sunset variable
66 lines (56 loc) · 1.99 KB
/
154. Set Sunset variable
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
--[[
%% autostart
%% properties
%% events
%% globals
RunClock
--]]
local startSource = fibaro:getSourceTrigger();
if (
( fibaro:getGlobalValue("RunClock") == "Ja" )
or
startSource["type"] == "other"
)
then
-- Script to set sun to set/risen
-- Remi Bergsma github@remi.nl
-- Inspired by posts on the Fibaro forum http://forum.fibaro.com
-- Note: This script needs a virtual device (id=90 in example) with two buttons. One to set the sun to 'Risen' and one to 'Set'. They should update the global var 'Sun'.
-- The file Sun.vfib contains the export of this device.
-- local vars
local sunriseHour = fibaro:getValue(1,'sunriseHour')
local sunsetHour = fibaro:getValue(1,'sunsetHour')
local BeforeSunset = 0
local AfterSunrise = 0
local debug = 0
if fibaro:countScenes() > 1 then fibaro:abort() end
while fibaro:getGlobalValue("RunClock") == "Ja" do
sunriseHour = fibaro:getValue(1,'sunriseHour')
sunsetHour = fibaro:getValue(1,'sunsetHour')
if debug ==1 then fibaro:debug("Today, sunrise is at " .. sunriseHour .. " and sunset at " .. sunsetHour) end
if (os.date("%H:%M", os.time()+BeforeSunset*60) >= sunsetHour)
or (os.date("%H:%M", os.time()-AfterSunrise*60) < sunriseHour)
then
-- sun is set
if (fibaro:getGlobalValue("SunSet") ~= "Ja")
then
-- fibaro:call(90, "pressButton", "2")
fibaro:call(137, "setProperty", "ui.SunSet.value", "Yes");
fibaro:setGlobal("SunSet", "Ja")
if debug ==1 then fibaro:debug("Changed sunset var to Set") end
end
else
-- sun is risen
if (fibaro:getGlobalValue("SunSet") ~= "Nei")
then
-- fibaro:call(90, "pressButton", "1")
fibaro:call(137, "setProperty", "ui.SunSet.value", "No")
fibaro:setGlobal("SunSet", "Nei")
if debug ==1 then fibaro:debug("Changed sunset var to Risen") end
end
end
if fibaro:countScenes() > 1 then fibaro:abort() end
-- running once a minute is enough
fibaro:sleep(60000)
end
end