Triggers of multiple switches

Hi guys

Been thinking through this case of scene.

Ok basically this scene is suggested by my wife. She suggested that our home, if we were about to go to bed, we will need to off all the lights in the living room before going into the bedroom, but normally, when the lights are turn off, the whole house will be in total darkness before we reach our room to on the light.

This scene will check all the switches in the house if they are off, if all the switch is off and you proceed to switch off the last switch, it should trigger a on scene for the light in the bedroom.

Been coming up with luup codes to check the status of the switches and only turning on them when all switches are switch off. Managed to make the check run every seconds but that will be straining on the switches or vera.

my codes are as follows :

local dev_id = 10 – DEVICE ID OF LIGHT YOU WANT TO TURN ON

local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight
local min_time_in_seconds = 19 * 3600 + 00 * 60 – 19:00
local max_time_in_seconds = 23 * 3600 + 59 * 60 – 23:59

if (current_second > min_time_in_seconds) and (current_second < max_time_in_seconds) then

local switch2 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 15)
local switch3 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 16)
local switch5 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 17)
local switch6 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)

if (switch2 == “0” and switch3 == “0” and switch5 == “0” and switch6 == “0”) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, dev_id)
end
function restartScene()
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{ SceneNum=19 }, 0)
end
luup.call_delay(“restartScene”,1,nil,true)
else
return false
end

PS: anyone has better idea to create this scene?

I would create four triggers for this scene. Each trigger should be LightX is turned off. So each trigger is for one of your four switches. Now the scene will be run whenever one of the switches is turned off so you don’t need to run it once per second. You can then remove the code that reruns the scene.

[code]local dev_id = 10 – DEVICE ID OF LIGHT YOU WANT TO TURN ON

local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight
local min_time_in_seconds = 19 * 3600 + 00 * 60 – 19:00
local max_time_in_seconds = 23 * 3600 + 59 * 60 – 23:59

if (current_second > min_time_in_seconds) and (current_second < max_time_in_seconds) then

local switch2 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 15)
local switch3 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 16)
local switch5 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 17)
local switch6 = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)

if (switch2 == “0” and switch3 == “0” and switch5 == “0” and switch6 == “0”) then
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, dev_id)
end
end
[/code]

wow cool, thanks, didnt see the logic clearly there.

Thanks RexBeckett!