AbsenceTime = Frånvarotid = 40 min
Code: Select all
--[[
%% autostart
%% properties
320 value
321 value
322 value
%% globals
LastSeenSensor
--]]
--kill any extra instances of the same scene
if (fibaro:countScenes() > 1) then fibaro:abort() end;
--Loop
while true do
--Settings
local ExecuteTimer = 30; -- Execute Every N-th second
local AbsenceTime = 40; -- 40 minutes
--Setup local variables
local CurrentDate = os.date("*t");
--Announce start
fibaro:debug(" -|- Start: "..os.date("%Y-%m-%d %H:%M:%S",os.time()))
-- LastSeenXXXXXXXX
if tonumber(fibaro:getValue(320, "value")) > 0 or tonumber(fibaro:getValue(321, "value")) > 0 or tonumber(fibaro:getValue(322, "value")) > 0 then
fibaro:setGlobal("LastSeenSensor",os.time())
end
local LastSeenSensor = 0+fibaro:getGlobal("LastSeenSensor");
fibaro:debug(" -|- LastSeenSensor: "..os.date("%Y-%m-%d %H:%M:%S",LastSeenSensor));
-- Home, anyone ?
AbsenceTime = os.time() - (AbsenceTime * 60);
fibaro:debug(" -|- AbsenceTime: "..os.date("%Y-%m-%d %H:%M:%S",AbsenceTime));
if tonumber(LastSeenSensor) < AbsenceTime then
fibaro:debug(" -|- Home: Nobody is Home!");
-- lägg in släck kod här!
else
fibaro:debug(" -|- Home: Someone is at home!");
end
--Announce end
fibaro:debug(" -|- End: "..os.date("%Y-%m-%d %H:%M:%S",os.time()))
--Sleep XX seconds
fibaro:sleep(ExecuteTimer*1000);
end