реальный пример только включение по моушину. т.е. вместо моушина проверяешь Lux-ы
елси не нужно автоотклуючение по времени - скрипт не добавляй.
--[[
%% autostart
%% properties
8 value
%% events
%% globals
--]]
local startSource = fibaro:getSourceTrigger();
if (
( tonumber(fibaro:getValue(8, "value")) > 0 )
or
startSource["type"] == "other"
)
then
dayMode = fibaro:getGlobal("DayMode", "Day");
fibaro:debug(dayMode)
if (dayMode == "Night" ) then
fibaro:call(19, "setValue", "25");
else
fibaro:call(19, "setValue", "99");
end
end
--[[
%% autostart
%% properties
8 value
%% events
%% globals
--]]
local startSource = fibaro:getSourceTrigger();
if(startSource["type"] == "other") then
fibaro:call(19, "turnOff");
else
if (( tonumber(fibaro:getValue(8, "value")) == 0 )) then
setTimeout(function()
local delayedCheck0 = false;
local tempDeviceState0, deviceLastModification0 = fibaro:get(8, "value");
if (( tonumber(fibaro:getValue(8, "value")) == 0 ) and (os.time() - deviceLastModification0) >= 60) then
delayedCheck0 = true;
end
local startSource = fibaro:getSourceTrigger();
if (
( delayedCheck0 == true )
or
startSource["type"] == "other"
)
then
fibaro:call(19, "turnOff");
end
end, 60000)
end
end
--[[
%% autostart
%% properties
%% globals
--]]
function DayMode(sunriseHour, sunsetHour)
--fibaro:debug(sunriseHour);
--fibaro:debug(sunsetHour);
time = os.date("*t")
result = "Day"
if (time.hour >= sunriseHour) and (time.hour < 12) then
result = "Morning"
-- print("Time set to Morning")
elseif (time.hour >= 12) and (time.hour < sunsetHour) then
result = "Afternoon"
-- print("Time set to Afternoon")
elseif (time.hour >= sunsetHour) and (time.hour < 23) then
result = "Evening"
-- print("Time set to Evening")
else
result = "Night"
-- print("Time set to Night")
end
return result
end
while true do
local currentDate = os.date("*t");
local sunriseHour = fibaro:getValue(1, 'sunriseHour');
local sunsetHour = fibaro:getValue(1, 'sunsetHour');
local currentSec = tonumber(currentDate.hour) * 60 + tonumber(currentDate.min);
local sunriseSec = tonumber(string.sub(sunriseHour, 1, 2)) * 60 + tonumber(string.sub(sunriseHour, 4));
local sunsetSec = tonumber(string.sub(sunsetHour, 1, 2)) * 60 + tonumber(string.sub(sunsetHour, 4));
if (currentSec>sunriseSec and currentSec<sunsetSec) then
fibaro:setGlobal("NightTime", "0");
fibaro:debug("NightTime: NO");
else
fibaro:setGlobal("NightTime", "1");
fibaro:debug("NightTime: YES");
end
dayMode = DayMode(tonumber(string.sub(sunriseHour, 1, 2)), tonumber(string.sub(sunsetHour, 1, 2)) );
fibaro:setGlobal("DayMode", dayMode);
fibaro:debug(fibaro:getGlobal("DayMode", "Day"));
--fibaro:debug(fibaro:getGlobal("NightTime", "0"));
--fibaro:debug(currentSec);
--ibaro:debug(sunriseSec);
--fibaro:debug(sunsetSec);
fibaro:sleep(60000*10);
end