Thanks to some guys over at the Fibaro forum and some effort of my own I've been able to use some of their code to build a proper "sunset" and "sunrise" timer and use that to automatically turn on my hallway lighting when the frontdoor is opened.
Here's the code for the NightTime:
Code: Select all
--[[
%% autostart
%% properties
%% globals
--]]
while true do
local sunUp = os.date("%H:%M", os.time()+15*60) --Off 30min before sunrise
local sunDown = os.date("%H:%M", os.time()-15*60) --On 30min after sunset
local currentDate = os.date("*t");
if ( sunUp == fibaro:getValue(1, "sunriseHour") )
then
fibaro:setGlobal("NightTime", "0");
fibaro:debug("Gooooooodmorning Nootjedorp!!1!");
elseif ( sunDown == fibaro:getValue(1, "sunsetHour") )
then
fibaro:setGlobal("NightTime", "1");
fibaro:debug("Fortune, good night; smile once more, turn thy wheel.");
end
fibaro:sleep(60*1000);
end
Second part of the code is the actual door and light code:
Code: Select all
--[[
%% autostart
%% properties
2 value
%% globals
--]]
if tonumber(fibaro:getGlobalValue("NightTime")) == 1 and tonumber(fibaro:getValue(2, "value")) == 1
then
fibaro:call(3, "turnOn");
fibaro:sleep(120000);
fibaro:call(3, "turnOff");
end
In the top bit you see a 2 value declared. The number is the deviceID (not zwave nodeID) of the door sensor. We need to fetch the value before we're able to use it. Specifically from the deviceID number 2 we get the "value" information type and use this to see if the door is opened or not.
In the if statement we check if the NightTIme global variable is set to 1 and the door is opened (value 1) and then we'll call deviceID number 3 to "turnOn" and after a wait period of 120 seconds to "turnOff" automatically again.
Enjoy the code.