Cant even get LUUP code to turn on a switch to work

I am having ZERO luck getting even the most basic LUA/LUUP (what’s the difference?) code to work in a scene, and just can’t figure out what I might be doing wrong?! Ultimately, I’m trying to build a scene that will toggle a switch on if it is off, and off if it is on. Basically creating a push on/push off switch, but I’m starting very basic, and have just built a scene that should simply turn the device on, and even that isn’t working! I feel like I must be missing something so basic, and so fundamental to vera that as soon as I understand, all of this will just fall into place…

SO… Simply, here’s my line of code:

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

From everything I have read, this should simply turn on device 29.
My device 29 is an Aeon heavy duty outdoor switch (Amazon.com) which itself has been working fine for 4 years, and responds properly to scenes where I select the device and on/off status in the normal mode, and I can even control it via Alexa, so the device or it’s registration to Vera isn’t it’s problem…

Using this web query:
http://192.168.1.185:3480/data_request?id=status&output_format=xml&DeviceNum=29

I can see the device and status in the web browser. What I believe is the pertainent information in the response is:
[Device_Num_29 PendingJobs=“0” status=“-1”]
[states]
[state id=“630” service=“urn:upnp-org:serviceId:SwitchPower1” variable=“Target” value=“0”/] [state id=“631” service=“urn:upnp-org:serviceId:SwitchPower1” variable=“Status” value=“0”/]

(replaced greater than/less than with [] brackets because this editor didn’t seem to like them!)

I can turn the device on and off in Vera, and see the target and status variables change to “1” so I KNOW I am on the right device…

I have the scene configured (for testing) for only manual trigger, and it’s basically empty, except the Luup code I posted above in the “Also, execute the following Luup code:” section:

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

I also tried this in case “Target” was actually supposed to be the parameter being set
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {Target = “1”}, 29)

Nothing I do seems to have any effect.

What could I be doing wrong, and is there a better way to troubleshoot this? Is there a LUA "interpreter’ or other interactive window where I can just type in commands and maybe get some context relelvant error messages back?

Thanks in advance… I’ve owned “Vera” for 6 years, and feel like I’ve barely scratched the surface because this LUA is SO frustrating to me…
-Steve

Search for the phrase “pretty quotes” throughout the Forum and all will be revealed.

Actually, Lua is a language, see: Lua: about, which states:

What’s in a name?

“Lua” (pronounced LOO-ah ) means “Moon” in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, “Lua” is a name, the name of the Earth’s moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, “Lua”. Please do not write it as “LUA”, which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write “Lua” right!

Luup is the UPnP module with extensions written to interface to Vera, see: http://wiki.micasaverde.com/index.php/Luup_Lua_extensions.

As LibraSun said your problem is with the quotes.

This new forum uses the wrong quotation marks and likely when you copy and paste code from the forum it won’t work.

Try this code, this is correctly formatted.

luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },29)
1 Like

Here is an example of some toggle code I use for a Philips Hue light, as the “ToggleState” "function in the Advanced Editor of a Vera scene doesn’t seem to work for my Hue bulbs.

So I had to do a toggle in Lua code instead.

local device=379
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", device)
    if (switchOnOff == "1") then
      -- Switch is on
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "0"}, device)
else 
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, device)
end
1 Like

Shame Ezlo wont fix the quote issue, as another inocent victim wastes hours.

2 Likes

Maybe I should pin a thread about the quotes problem to the top of the forum. :astonished:

1 Like

Something needs to be done to warn newcomers that there is an issue. Shame newcomers have to learn the hard way.

It’s now pinned

Edit: and then unpinned by the forum manager.

1 Like

Thanks to all for the hints. I should have mentioned - I did already fix the quotes. I’ve been bitten by that before, with other forums, and in my regular day job where I write a LOT of powershell which also doesn’t like those crazy backward quotes! :slight_smile:

I also re-found the “Test Luup Code” window under the develop apps selection, and pasted it in there, hoping for better results or debug information, but even after backspacing over, and re-inserting normal quotes manually, all I get is a pop-up that says “Failed to test code, please try again”.

So strange!

1 Like

Thanks - That code will be very useful once I get this thing worked out.

Just as a test, I tried to run literally just the first line in my “test Luup code” window:
local device=29

No quotes to worry about, no strange syntax, just setting a variable, and when I click go, I get a pop-up that says “Failed to test code, please try again” so I think there is something way more fundamental going wrong here than just my syntax?

Thanks to all!!

Another datapoint is that I have also NEVER been able to get a NODE-RED MIOS-IN node to log into my Vera… I had posted in another thread (Node-Red & Vera (MIOS) - #14 by parkerc - General Discussions - Ezlo Community) before about it, and I was never able to resolve, and just gave up. I’m wondering if there’s something fundamentally broken / not running on my Vera? I’m not looking to clutter this thread up with the tangent of NodeRed, but only bringing it up in case it triggers someone who may know about a shared component or service which may be stopped or broken on my box?

You can find the error messages logged by that tool in the LuaUPnP log. It takes some digging, and sometimes the error messages are difficult to decode, but it’s better than flying completely blind:

http://your-vera-local-ip/cgi-bin/cmh/log.sh?Device=LuaUPnP

Can you repost your code here, but properly formatted for the forum, so we can get a clear look? The way to post it is to put three “backticks” (```) on a line by themselves, then follow with the code block, and then end with three backticks on a line by themselves again.

Awesome… SO… Thanks for the link to the log file - That’s handy. I was able to see the error:


08	07/01/20 17:33:57.279	JobHandler_LuaUPnP::HandleActionRequest argument Code=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget", {NewTargetValue = "1"}, 29) <0x73095520>
02	07/01/20 17:33:57.280	JobHandler_LuaUPnP::RunLua unsafe disabled <0x73095520>
02	07/01/20 17:33:57.280	JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/No unsafe lua allowed <0x73095520>
08	07/01/20 17:33:57.282	JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua

I had seen that checkbox to enable “unsafe” code, but dont know why this would be considered unsafe (let alone above, when I just set “Local device=29”!

Figuring it was worth a shot, I turned on allow unsafe code, and I can see it trying to run, and it says it sends to the device, but the device isn’t turning on. I suspect that is just because of a variable error/mistype. I’ll keep working at that, but I’m curious - Should I assume that even the most basic commands are considered unsafe and this was to be expected?

Thanks a lot for the continued support!

I do not have the option “Enable potentially unsafe lua code” enabled, its not selected on my Vera, yet I’ve had no problems running any of my Lua codes including wget commands.

Unless I enabled it ages ago and it’s just not showing its enabled in the Web GUI?

Yeah… Seemed strange to me! I’ve never done anything outside of the regular GUI (at least not successfully!) so it looks like mine is just not making good decisions on what “safe” is.

NOW, I think I do have a syntax problem…
Attaching 2 snippets from the log. The first one, I thought I’d capture what gets logged when I press the button manually within the GUI, to see what looks “right”. The second is just me trying to turn it on again, which failed, but I noticed in the log that it had a strange line at the end of the log showing that the “job” has a name including the word “OFF” so I manually turned the switch on, and then re-ran my code, and it DOES turn it off. SOMEHOW, it is not seeing the “1” as a turn-on command, and/or my keywords are wrong. Another difference is that when I press the button, it sees the “action” as an argument along with “NewTargetValue” but when I do it with my code, only the NewTargetValue shows as an argument. Could this be a clue?

Pressing the button in theh GUI Worked:
08	07/01/20 17:51:27.280	JobHandler_LuaUPnP::HandleActionRequest device: 29 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x74532520>
08	07/01/20 17:51:27.281	JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=29 <0x74532520>
08	07/01/20 17:51:27.281	JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:SwitchPower1 <0x74532520>
08	07/01/20 17:51:27.281	JobHandler_LuaUPnP::HandleActionRequest argument action=SetTarget <0x74532520>
08	07/01/20 17:51:27.281	JobHandler_LuaUPnP::HandleActionRequest argument newTargetValue=1 <0x74532520>
08	07/01/20 17:51:27.281	JobHandler_LuaUPnP::HandleActionRequest argument rand=0.4146780359005422 <0x74532520>
06	07/01/20 17:51:27.282	Device_Variable::m_szValue_set device: 29 service: urn:upnp-org:serviceId:SwitchPower1 variable: Target was: 0 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0xc14b60/NONE duplicate:0 <0x74532520>
06	07/01/20 17:51:27.647	Device_Variable::m_szValue_set device: 29 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 0 now: 1 #hooks: 2 upnp: 0 skip: 0 v:0xd2f210/NONE duplicate:0 <0x77132520>


My LUA code - Did not work but I noticed the last line saying "Name=OFF" this time, so I theorized it was really turning the switch OFF, which it is doing:
08	07/01/20 18:22:44.843	JobHandler_LuaUPnP::HandleActionRequest argument Code=luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget", {NewTargetValue ="1"}, 29) <0x72e26520>
08	07/01/20 18:22:44.844	JobHandler_LuaUPnP::HandleActionRequest device: 29 service: urn:upnp-org:serviceId:SwitchPower1 action: SetTarget <0x72e26520>
08	07/01/20 18:22:44.844	JobHandler_LuaUPnP::HandleActionRequest argument NewTargetValue=1 <0x72e26520>
06	07/01/20 18:22:44.844	Device_Variable::m_szValue_set device: 29 service: urn:upnp-org:serviceId:SwitchPower1 variable: Target was: 0 now: 0 #hooks: 0 upnp: 0 skip: 0 v:0x10bdb90/NONE duplicate:1 <0x72e26520>
06	07/01/20 18:22:45.147	Device_Variable::m_szValue_set device: 29 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 0 now: 0 #hooks: 2 upnp: 0 skip: 0 v:0x11d80e0/NONE duplicate:1 <0x76626520>
04	07/01/20 18:22:45.148	<Job ID="33" Name="OFF node 58" Device="29" Created="2020-07-01 18:22:44" Started="2020-07-01 18:22:44" Completed="2020-07-01 18:22:45" Duration="0.302763000" Runtime="0.302364000" Status="Successful" LastNote="SUCCESS! Transmit was OK" Node="58" NodeType="ZWaveNonDimmableLight" NodeDescription="Pool Pump"/> <0x76626520>

another thing possibly of interest… Strange messages in log about templogfilesystemfailure

Is it possible I have some temp partition full?

02	07/01/20 18:48:27.221	UserData::CommitToDatabase data size 166568 166568 <0x76826520>
01	07/01/20 18:48:27.265	UserData::WriteUserData saved--before move File Size: 37880 save size 37880 <0x76826520>
02	07/01/20 18:48:27.265	UserData::TempLogFileSystemFailure start 0 <0x76826520>
02	07/01/20 18:48:27.282	UserData::TempLogFileSystemFailure (not failure, only WriteUserData) 0 <0x76826520>
02	07/01/20 18:48:27.283	UserData::TempLogFileSystemFailure 699 res:1
-rw-r--r--    1 root     root           504 Nov  6  2018 /etc/cmh/user_data.json.luup.lzo
-rw-r--r--    1 root     root         37888 Jul  1 18:42 /etc/cmh/user_data.json.lzo
-rw-r--r--    1 root     root         37891 Jul  1 18:36 /etc/cmh/user_data.json.lzo.1
-rw-r--r--    1 root     root         37962 Jul  1 18:30 /etc/cmh/user_data.json.lzo.2
-rw-r--r--    1 root     root         37901 Jul  1 18:24 /etc/cmh/user_data.json.lzo.3
-rw-r--r--    1 root     root         38009 Jul  1 18:09 /etc/cmh/user_data.json.lzo.4
-rw-r--r--    1 root     root         37946 Jul  1 18:09 /etc/cmh/user_data.json.lzo.5
-rw-r--r--    1 root     root         37880 Jul  1 18:48 /etc/cmh/user_data.json.lzo.new
 <0x76826520>
02	07/01/20 18:48:27.349	UserData::TempLogFileSystemFailure start 0 <0x76826520>
02	07/01/20 18:48:27.365	UserData::TempLogFileSystemFailure (not failure, only WriteUserData) 0 <0x76826520>
02	07/01/20 18:48:27.366	UserData::TempLogFileSystemFailure 610 res:1
-rw-r--r--    1 root     root           504 Nov  6  2018 /etc/cmh/user_data.json.luup.lzo
-rw-r--r--    1 root     root         37880 Jul  1 18:48 /etc/cmh/user_data.json.lzo
-rw-r--r--    1 root     root         37888 Jul  1 18:42 /etc/cmh/user_data.json.lzo.1
-rw-r--r--    1 root     root         37891 Jul  1 18:36 /etc/cmh/user_data.json.lzo.2
-rw-r--r--    1 root     root         37962 Jul  1 18:30 /etc/cmh/user_data.json.lzo.3
-rw-r--r--    1 root     root         37901 Jul  1 18:24 /etc/cmh/user_data.json.lzo.4
-rw-r--r--    1 root     root         38009 Jul  1 18:09 /etc/cmh/user_data.json.lzo.5
 <0x76826520>

Sigh. No, these are normal. Not an error, just a really dumb status/trace message.

The correct name of the parameter for the SetTarget action is newTargetValue not NewTargetValue. The “N” should not be capitalized.

Cool… Thanks!! I’ll try that, BUT I also found reference to another command online, and got this to work:

luup.variable_set("urn:upnp-org:serviceId:SwitchPower1", "Status", 1, 29)

SO, although I want the other command to work just to make sure I’m not crazy, at least I can accomplish what I want!!

Thanks