First try at coding some logic into a scene

I have a scene that I intend to use simply to activate one of two other scenes, based on the current level of a dimmer. Basically, to let me use one scene remote to toggle between two levels. I’m not seeing any response. Can anyone offer a pointer?

When I usually code (not in LUA…), I do a lot of console.log() or var_dump() or similar to help debug a problem. What’s the easiest way within LUUP for a scene to see (visually) the current value of a variable?

My code:

[tt]
local ecON = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”, 53)
local ecLevel = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”, 53)
if (ecON == “1”) then
if ( ecLevel > 40 ) then
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = “45”}, 0)
else
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = “46”}, 0)
end

end
[/tt]

(note: my understanding is that I need the “on” variable as the level will maintain the last level used, even if turned off)

Turned out that I needed to convert the ecLevel (the level of the light) to a number before comparing.

[tt]if ( tonumber(ecLevel) > 40 ) then[/tt]

If anyone has pointers on debugging in general, it’d be appreciated.

Yes, I’ve been caught out by the text vs numbers thing …

I too am finding debugging difficult. The 2 methods I’ve just adopted are:

  1. use Test Luup Code, under Apps/Develop Apps/Test Luup Code (in UI5). Try small chunks to see if they’re right. This does actually execute the code as well, so you can test if devices are activated, etc.

  2. Use logging and read the log in a telnet client logged into the Vera unit. Using a custom logging level you can watch for only your own entries. have a look in http://wiki.micasaverde.com/index.php/Luup_Debugging .

–
Pete