Hi,
I fix this one for my bathroom and it is working fine.
It turn on my fan only when the light is on for 2 min, and the fan stops after 5 min.
--[[
%% autostart
%% properties
469 value
%% globals
--]]
---------------------------------Generic Scene Code------------------------------
local trigger = fibaro:getSourceTrigger();
local currentDate = os.date("*t")
local now = string.format("%02u",currentDate.day).. "-" ..
string.format("%02u", currentDate.month) .. ": Started by ";
if (trigger['type'] == 'property') then fibaro:debug(now .. 'device ' .. trigger['deviceID']);
elseif (trigger['type'] == 'global') then fibaro:debug(now .. 'global variable ' .. trigger['name'])
elseif (trigger['type'] == 'autostart') then fibaro:debug(now .. 'autostart configuration');
elseif (trigger['type'] == 'other') then fibaro:debug(now .. 'other source');
else fibaro:debug(now .. 'unknown source:' .. trigger['type']);
end
local csc = fibaro:countScenes();
if csc > 1 then fibaro:debug(csc .. " scenes running, abort this instance..."); fibaro:abort() end
---------------------------------------------------------------------------------
local scene = 209 -- ID dieser Szene
local Vent = fibaro:getGlobalValue("VentToilet");
local switch = fibaro:getGlobalValue("LampToilet");
local sensor = fibaro:getGlobalValue("SensorToilet");
local starttimer = 40
local runtimer = 125
local venttimer = 300
--if (fibaro:countScenes()>1) then
--fibaro:debug('Kill second scene!');
--fibaro:abort();
--end
if (tonumber(fibaro:getValue(sensor, "value")) > 0 ) then
fibaro:call(switch, "turnOn");
fibaro:debug("Licht is aan")
timer = os.time();
VentTimer = os.time()
while os.time() - timer < starttimer do
fibaro:sleep(1000);
if (tonumber(fibaro:getValue(sensor, "value"))) > 0 then
timer = os.time();
end
--local calc = timer - VentTimer
--print(calc)
if timer - VentTimer > runtimer then
fibaro:call(Vent, "turnOn");
end
end
fibaro:call(switch, "turnOff");
end