Hello
Some times i need to use switches or sockets to command lights or want to check witch window is open (excluding sensors on door).
For that i make simple scene witch can serach and control devices with have same string in the name.
To use it i for Light i rename all devices (switches, dimmers ... ) to have "Light" in the name etc.
You need to create 3 variables with is using to call scene.
Before you execute the scene you sholud ti set them.
--[[
%% properties
%% globals
--]]
local sdevice = fibaro:getGlobalValue("TypeDevice"); -- Device with what string in the name are you search.
local state = tonumber(fibaro:getGlobalValue("Dstate")); -- What value should be device.
local state = fibaro:getGlobalValue("Action"); -- What action you want to go. "turnOn", "close".. etc.
local MaxDevice = 1000; -- How many device do you have in your Home.
fibaro:debug("Start");
repeat
deviceID = u ;
s = fibaro:getName(deviceID) ;
if s ~= nil
then
i, j = string.find(s, sdevice);
if i ~= nil and tonumber(fibaro:getValue(u, "value")) ~= state
then
fibaro:debug("Device N: "..u.." Name: "..s.." Room: "..fibaro:getRoomNameByDeviceID(deviceID));
fibaro:setValue(u,Action);
-- Send a push notification when something happens - for exapmple Window is open
-- fibaro:call(notificationID, 'sendPush', 'Open : '..s..' Room: '..fibaro:getRoomNameByDeviceID(deviceID));
end
end
u = u + 1;
until u > MaxDevice
fibaro:debug("End");
How i use it when alarm system is arm:
--[[
%% properties
542 value
%% globals
--]]
if fibaro:getValue(542, "armed") == 1 then
-- Curtains
fibaro:setGlobal("TypeDevice", "curtains");
fibaro:setGlobal("Dstate", "1");
fibaro:setGlobal("Action", "close");
fibaro:startScene(569);
fibaro:sleep(10x1000);
-- Lights
fibaro:setGlobal("TypeDevice", "Light");
fibaro:setGlobal("Dstate", "1");
fibaro:setGlobal("Action", "turnOff");
fibaro:startScene(569);
end