For my first LUA code I wanted to add a simple toggle switch. Presumably all I need to do is grab an example, paste it into the LUA code page in the scene creation Wizard and away I go…nope doesn’t work. OK lets paste that into the test box. Yep doesn’t work. Unfortunately, there is no feedback from the “Test Code” box other than nope doesn’t work. Well, since it didn’t turn the light on I sort of know that when I execute the scene.
So here is what I put into the test box and into the Scene which “does not work”:
[tt]
function toggle()
local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 38)
if (switchOnOff == “1”) then
– Switch is on
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 38)
else – switch is off
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 38)
end if
end
[/tt]
After making several guesses aka the example is wrong, cut it down to one line etc no matter what I do it doesn’t work in the test box. So there is something missing in my concept set. I tried this with and without the function declaration. The syntax checker in Notepad++ is happy nad device 38 is for sure a binary switch.
Yes that makes sense. Now that I have a basic understanding I can do anything…well we shall see.
The humidifier control is a bit more challenging. I understand how to log to the master log file. The Vera 2-3 documentation says log in and tail a particular file. I understand that concept. Is there a way to view the log file from the browser? Is that the log that pulls down (yellow background) on the Dashboard? Do you have to plug in a USB to view that log?
You can’t stop it scrolling, but you can capture all the previous text by simply selecting all and cutting then pasting into your faviourite word processor.
Thanks to all. The log works pretty much as expected.
By the way this is the working lua code. Just paste into a scene for lua code and you can toggle a light. This demonstrates simple logic, getting information from the device and initiating an action in a device based on the state. If all you want to do is toggle a binary light there is an easier way:
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 38)
if (switchOnOff == "1") then
-- Switch is on
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, 38)
else -- switch is off
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 38)
end
return true
Still gives me the same failed message prompt box for the “Test Window” even with the return true in there.
Maybe you have some weird hidden characters in the string.
The following works for me (Note I used a different device#)
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 9)
if (switchOnOff == "1") then
-- Switch is on
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, 9)
else -- switch is off
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 9)
end
return true
I tested the sample code in “Test luup code” on VeraEdge and Vera 3 with UI7 and it worked. I searched for this bug internally and it was confirmed as fixed at the beginning of this month. Is true that I used an intermediate build for testing, but this means that the fix will be available in our next release.