Hi,
I was tidying up my light scenes where I turn on of off batches of lights (at night, going away, etc) and I wanted something simpler and more reliable.
I created a very simple scene that stores the light ID's (or HomeTable references, as I have) in a table and you pass the action (turnOn or tunrOff) in the startScene call so no need to use a global variable
The scene code is not really mean to be a solution like Smart message Hub but more of a case of sharing what I put together.
It a small amount of error handling and warnings should ID's be incorrect and should be easy enough to pick through as a learningexercise
The scene call is simple
-- turn off group of lights
fibaro:startScene(jT.scene.upLights, {"turnOff"}) -- using a hometable reference
-- or
fibaro:startScene(694, {"turnOff"}) -- using a scene ID
-- turn on group of lights
fibaro:startScene(jT.scene.upLights, {"turnOn"}) -- using a hometable reference
-- or
fibaro:startScene(694, {"turnOn"}) -- using a scene ID
I included just two options
deBug : set to true to see lights as they are checked
delay : this will set a sleep or delay between each light if you find that switching them off too fast is causing some to be missed
Comment out the reference to HomeTable (line 10) is you don't use this method
Scene Code is below
--[[
%% properties
%% events
%% globals
--]]
local deBug = true
local delay = ""
local jT = json.decode(fibaro:getGlobalValue("HomeTable"))
upLights = { jT.frank_bedroom.Light, jT.lau_eth_bedroom.Light, jT.master_bedroom.Light, jT.master_bedroom.LEDLight,
jT.guest_bedroom.Light, jT.master_bedroom.BathLight, jT.guest_bedroom.BathLight, jT.bathroom.Light,
jT.Landing_Stairs.landingLight, jT.Landing_Stairs.stairsLight, jT.hotpress.Light }
function main()
if fibaro:args() == nil then
fibaro:debug("Warning: No action included in Scene call, scene aborted")
return
else
local args = fibaro:args()
for k,v in pairs(upLights) do
if deBug then fibaro:debug("checking light.. "..v) end
if fibaro:getValue(v, "value") == nil then
fibaro:debug("Warning: "..v.." (table position: "..k..") is an invalid reference, Stopping Scene")
return
end
if args[1] == "turnOff" and tonumber(fibaro:getValue(v, "value")) >= 1 then
if deBug then fibaro:debug(v.." : "..args[1]) end
fibaro:call(v, args[1])
end
if args[1] == "turnOn" and tonumber(fibaro:getValue(v, "value")) == 0 then
if deBug then fibaro:debug(v.." : "..args[1]) end
fibaro:call(v, args[1])
end
if delay ~= "" then fibaro:sleep(delay) end
end
end
end
main()
PS - This approach could easily be expanded to store a number of groups (table) of lights in the the scene and pass 2 parameters in the startScene call, one parameter could be used to decide which group of lights and the second could be used to selection the action (turnOn, turnOn)
Enjoy - Happy Coding
-f