Stupid scripting question

I posted something about this earlier, but decided to go a different way.

I can send a wget command to execute a scene so all I need is working code to do what I want. I looked at existing code samples and also referenced the code I have used in the past. Basically all I want to do is when I run a scene if the lamp is on (1) turn it off (0) and if it is off (0) turn it on (1).

I wrote code and it didn’t work so I decided to go back to what works and build from there.

I started with this code:

local device = 7 -- Switch on device 7: luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device) luup.call_delay( 'switch_off',2) -- Call the switch off function after a delay of 2 seconds function switch_off() luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device) end

Worked fine. It switched the light on, waited two seconds and turned it off. Then I removed the second part of the code and it fails. That code looks like this:

local device = 7 -- Switch on device 7: luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device) end

This code doesn’t contain anything new, why isn’t it valid?

My goal was to have something like this:

local device = 7 -- Switch on device 7: local lul_tmp = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device) if (lul_tmp == "0") then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device) if (lul_tmp == "0") then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device) end

But even the simple part isn’t working. What am I missing?

Code: [Select] local device = 7 -- Switch on device 7: luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device) end

This code doesn’t contain anything new, why isn’t it valid?

You need to remove the end statement. It was part of the function block.

Code: [Select] local device = 7 -- Switch on device 7: local lul_tmp = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device) if (lul_tmp == "0") then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device) if (lul_tmp == "0") then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },device) end

But even the simple part isn’t working. What am I missing?

Now you are missing an end statement for the first if. Also both ifs have the same condition - try this:

local device = 7 -- Switch on device 7: local lul_tmp = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device) if (lul_tmp == "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

Worked perfectly. Thanks!

hi my intermatic switch CA3000 (device #112 as indicated in the luup code below) is directly associated with 3 other GE switches so that turning on/off the intermatic switch will do the same for the 3 GE switches in the backyard. i have another new CA3000 switch that i just installed in the garage - i tried to associate this with the parent CA3000 many times but to no avail. i know that we can do this association for 5 devices but so far i have only 4 but the last one will not turn on/off when turning on/off the first (parent) CA3000. my guess is that it is not in “line of sight” since it is in the garage. therefore, i found the following luup code somewhere in this forum but still did not work. can someone tell me what is wrong with the following luup code. thanks in advance.

[code]local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 112)
if (lul_tmp == “1”) then

return true
else
return false
end[/code]

Where is this code located (i.e. what does the scene its in do)? How is the above code or scene being invoked?

Remember that GE devices are not “instant status” devices, so turning off the plug will not cause a scene that is triggered by the off to be immediately executed.

[quote=“aa6vh, post:5, topic:182833”]Where is this code located (i.e. what does the scene its in do)? How is the above code or scene being invoked?

Remember that GE devices are not “instant status” devices, so turning off the plug will not cause a scene that is triggered by the off to be immediately executed.[/quote]

good question. the code was in the luup tab. i just moved it to “trigger” - “luup event”. will let you know if it works. what i am trying to do is when i turn on the light device #112, i want to turn the other light with it since i cannot directly associate the new light using the “device option” tab. thanks for your input.