Maybe I should pin a thread about the quotes problem to the top of the forum.
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.
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!
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!
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
… And yes - The lowercase “n” made the difference!!
SO - I have NO IDEA why my device thinks literally every command is ‘unsafe’ but at least I can get it to work. Hopefully the rest of my network is otherwise protected well enough to not worry about it!
Thanks for all the help everyone!!
Thanks again… Now that I have this solved, your code for toggle worked great… Changed it for my device type:
local device=29
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:SwitchPower1","SetTarget", {newTargetValue = "0"}, device)
else
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget", {newTargetValue = "1"}, device)
end
Just to close the loop on this… the above command will change the variable, but have no effect whatsoever on the device. The only way to make a real (ZWave, etc.) device change is through luup.call_action()
.
Indeed, and there is already an action to toggle a switch, so you don’t have to write your own, see:
http://wiki.micasaverde.com/index.php/Luup_UPnP_Variables_and_Actions#HaDevice1
ServiceId is "urn:micasaverde-com:serviceId:HomeAutomationGateway1"
Action is ToggleState
Yes the inbuilt “ToggleState” works for most Z-Wave devices. It does not work for my Philips Hue devices / AltHue plugin.
So I had to write the toggle Lua code to toggle Hue lamps in a scene.
However it is recommended to try the “ToggleState” function first in the Advanced Editor of a Vera scene.