Может кому пригодится для FIbaro HC2 LUA.
Сцена включает свет и отправляет PUSH при открытии двери.
Свет поддерживается во включенном состоянии по датчику движения который стоит над входной дверью.
Уже все работает, но функционал буду допиливать.
--[[
%% autostart
%% properties
111 value
119 value
%% weather
%% events
%% globals
--]]
local startSource = fibaro:getSourceTrigger();
local doorID = 111; -- ID датчика двери
local sensorID = 119; -- ID датчика движения
local lightID = 125; -- ID света
local pushNoteID = 159; -- ID push сообщения
local DoorOpenTime = fibaro:getModificationTime(doorID, 'value');
local SensorTime = fibaro:getModificationTime(sensorID, 'value');
local endTimer = 180;
local debug = true;
--Функция отладки
----------------------------------------------------------------------------------
Debug = function ( color, message, level)
fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
end
--Функция таймера
----------------------------------------------------------------------------------
startTimer = function ()
if debug then
Debug( "green", "Запущен таймер отключения на: "..endTimer.."сек.");
end
local counter = endTimer;
while(counter > 0)
do
counter = counter - 1
fibaro:sleep(1000)
if tonumber(fibaro:getValue(sensorID, "value")) > 0 then
--if debug then
-- Debug( "green", "Обновляю таймер!");
--end
counter = endTimer;
end
end
if debug then
Debug( "green", "Выключаю свет!");
end
fibaro:call(lightID, "turnOff");
end
--Функция включения света
----------------------------------------------------------------------------------
turnOnLight = function()
Debug( "green", "Включаю свет в прихожей!");
fibaro:call(lightID, "turnOn");
end
--Функция счетчика сцен
----------------------------------------------------------------------------------
if (fibaro:countScenes() > 1) then
Debug( "red", "Отмена, много экземпляров сцены = "..fibaro:countScenes());
fibaro:abort();
end
----------------------------------------------------------------------------------
SceneTriggered = function()
--checkLights();
turnOnLight();
startTimer();
end
--Запуск сцены
----------------------------------------------------------------------------------
if ( startSource["type"] == "other" ) then
SceneTriggered();
--elseif ( startSource["type"] == "property" ) then
-- SceneTriggered();
elseif (tonumber(fibaro:getValue(doorID, "value")) > 0 ) then
if debug then
Debug( "green", "Открыта входная дверь!");
end
fibaro:call(38, "sendDefinedPushNotification", pushNoteID);
SceneTriggered();
end
-- If it's been at least 10 seconds since the value was last modified
--if ((os.time() - lastModified) >= 10) then
-- fibaro:debug('It has been 10 seconds or more')
--else
-- fibaro:debug('It has been less than 10 seconds')
--end