Dimmer control logic puzzle

So this will probably be fairly easy to answer and while I looked through the common example scripts I couldn’t find something that applied to my question. I don’t really have trouble with the scripting part, I just can’t figure out the logic of what I’m trying to accomplish, so here goes.

I’ve dumbed this way down to a very basic version of what I’m trying to do, but once I figure this out I should be able to figure out the rest as well.

I have 4 components - 2 lights (L1 & L2), 1 dimmer (DIM) and 1 scene controller (SC).

DIM is directly connected to L1 and turns it on or off regardless of scenes.

SC and L2 are not directly connected to any devices.

When I press DIM (ON/OFF) it triggers a scene that turns L2 ON/OFF (in addition to L1 which is directly connected)
When I press SC, I WANT it to turn OFF L1 while keeping L2 ON (or if L1/L2 is off, just turn on L2)

The problem = When I press SC, it turns OFF L1, which triggers the scene to turn OFF L2.

I obviously need to reconfigure my scenes and probably add some LuuP code, i’m just having a hard time with how that should happen and what conditions are needed.

My initial thoughts are this:
Create two scenes, one for DIM and one for SC
On DIM scene - IF L2 = off then run scene
On SC scene - IF L1 = on then run scene

I still feel like I have a loop in there though.

Any help?

Yeah, you need to add some Luup code to trigger your scenes or switches based on the state of the device. Here is a couple toggle examples you can muck around with.

[code]–Scene Control based on single device state
– ID of Device in Question
local device = 7
– ID of Scene used of On State
local sceneOn = 5
– ID of Scene used for Off State
local sceneOff = 6

local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)

if (switchOnOff == “1”) then

luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = sceneOff}, 0)
else

luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = sceneOn}, 0)
end


–Device Control based on device state
–ID of Device in Question
local device = 7
luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “ToggleState”, {}, device)
local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)

if (switchOnOff == “1”) then

luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, device)
else

luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, device)
end[/code]