Triggering a Scene with only Luup code

I’m trying to create a scene using LuuP code only with no events, timers, or commands. I’m new to scene programming and trying to see if this Luup code works. The plan is to be able to have the Luup code test if a certain light is on then turn a different light on. Essentially, when the first light is turned on (by some other action - manual or programmed), then I want the other light to be turned on.

I tried triggering the scene by manually turning device 58 on from the UI, it turns on as expected, but the scene/code doesn’t seem to run as device 59 never comes on.

The first light (device #58) is an X-10 appliance module (I have the Insteon 2413U working fine to control some older X10 devices that I have not upgraded yet). The second light is an X10 Dimmable module.

I tried putting the code in the Test LuuP Code dialog box per the wiki instructions and after hitting Go, it said that the code was sent successfully.

the Luup code I am using is:

local rope_light = luup.variable_get("urn:schemas-upnp-org:device:BinaryLight1","Status",58) if (rope_light == "1" ) then luup.call_action("urn:schemas-upnp-org:device:DimmableLight1","SetLoadLevelTarget",{LoadLevelTarget = "80"}, 59) end

Device 58 has the following variables from the Advanced tab: LoadLevelTarget, LoadLevelStatus, Status and Target, and has device_type=urn:schemas-upnp-org:device:BinaryLight:1

Device 59 has the following same varaibles as the appliance module. It has a devie_type = urn:schemas-upnp-org:device:DimmableLight:1

Is the code correct for what I am trying to do?

You’ll have to use serviceId’s (like: urn:upnp-org:serviceId:SwitchPower1).

I made the changes as you mentioned.

I am trying to have this code (modified with serviceId’s) in a scene. I can get the functionality I want by defining commands and events in the scene. When event #58 goes on, then command #59 executes. That works - but not with the LuuP code.

What I’d like to do is to have no commands specifically defined in the scene - I’d like all the logic to be done with LuuP code.

I’m trying to simply define an Event - when device #58 turns on. Then I was expecting that the LuuP code would get executed. Do I need to schedule the scene to run with a timer (minimum frequency of 1 minute)?

Or can I have a truly event based approach - without a timer and having to wait for the time to fire (could be up to a minute from the time the event happens)?

The new code is:

local rope_light = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",58) if (rope_light == "1" ) then luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{LoadLevelTarget = "60"}, 59) end

Please don’t hold me to this, (I’m still very new to all this) but would luup.variable_watch work here?

Hi bobemorgan,

You’re on the right track. The most recent code you’ve posted should work, once. It’s then just a matter of arranging for it to happen repeatedly.

If you search the forum for luup.call_delay then you’ll find sample code where it schedules itself to be called again in a minute. Lots of plugins do this (examples: Weather; Countdown Timer) so you can mine them for code too.

Or, as parkerc says, you can register a callback function that will be called if the variable you are watching changes state. There has been a little talk about luup.variable_watch on the forum, and scant sample code. You can also see it in action in some plugins (Home Care; Combination Switch).

It’s hard to offer more specific advice without knowing more about the context that your code is going to be running in.

futzle - thanks for the hint on scheduling the function call. I’ve got the code working now. I encountered a different problem with trying to control the device #59 (dimmable x10 lamp module). I’ve copied the code here, with the Dimming call_action commented out. If I treat device #59 as an appliance module then it works.

[code]local ropeDeviceNo = 58
local cabinetDeviceNo = 59
local period = 15
local ROPE_SID = “urn:upnp-org:serviceId:SwitchPower1”
local CAB_SID_D = “urn:upnp-org:serviceId:Dimming1”
local CAB_SID_A = “urn:upnp-org:serviceId:SwitchPower1”

function CheckRopeLight()
local rope_light = luup.variable_get(ROPE_SID,“Status”,ropeDeviceNo)

if (rope_light == "1" ) then

– luup.call_action(CAB_SID_D,“SetLoadLevelTarget”,{newLoadLevelTarget = “1”}, cabinetDeviceNo)

   luup.call_action(CAB_SID_A,"SetTarget",{newTargetValue = "1"}, cabinetDeviceNo)




When I was using the Dimmable code (action=SetLoadLevelTarget), it wouldn’t work and the Vera log file showed an error of:

InsteonNode::ReceivedX10Message serv urn:upnp-org:serviceId:Dimming1 action SetLoadLevelTarget unhandled <0x402>

Also in the log file for the X10 devices in question, I see entries to the effect of
“ReceiveData skipping unknown 0x63” and some other values like 0xb2, etc… It seems that the Insteon device is getting data back that it doesn’t understand.