Author Topic: Cannot execute Lua code in Scene  (Read 516 times)

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Cannot execute Lua code in Scene
« on: November 24, 2018, 06:35:38 pm »
Trying to add a custom scene with Lua code and cannot get anything to execute.  I get this in the log:
Code: [Select]
01      11/24/18 18:18:57.236   JobHandler_LuaUPnP::AlarmCallback EXECUTE_GLOBAL_LUA failed:
function scene_3()
print ("Hello World")
end

And when I run the scene I get:
Code: [Select]
08      11/24/18 18:10:31.249   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x755ab520>
08      11/24/18 18:10:31.249   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x755ab520>
08      11/24/18 18:10:31.250   JobHandler_LuaUPnP::HandleActionRequest argument action=RunScene <0x755ab520>
08      11/24/18 18:10:31.250   JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=3 <0x755ab520>
08      11/24/18 18:10:31.251   JobHandler_LuaUPnP::HandleActionRequest argument rand=0.6310190950530556 <0x755ab520>
08      11/24/18 18:10:31.251   Scene::RunScene running 3 Test02 <0x755ab520>
01      11/24/18 18:10:31.252   LuaInterface::CallFunction_Scene Scene  3 failed attempt to call a nil value <0x755ab520>

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #1 on: November 26, 2018, 06:46:09 pm »
No idea from the Vera experts here on why my scene scripts are not working? Do I have a cripple device?

Offline jswim788

  • Hero Member
  • *****
  • Posts: 805
  • Karma: +58/-2
Re: Cannot execute Lua code in Scene
« Reply #2 on: November 26, 2018, 07:57:03 pm »
Can you post the exact scene code you are trying to use?

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #3 on: November 27, 2018, 06:35:27 am »
None of the script I tried work, so I deleted all my existing scenes and simply trying to run a print statement.

Code: [Select]
print ("Hello World")

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1030
  • Karma: +166/-1
Re: Cannot execute Lua code in Scene
« Reply #4 on: November 27, 2018, 07:04:22 am »
I have occasionally seen the error you are reporting. It is not consistent, and may center around the fact that Vera doesn't do anything useful with print() in its environment--it does not write the string to the log, and I'm not sure what it does with it (it would have been a simple matter for them to override it and provide a useful implementation, but oh well). Most of the time, it is a completely benign no-op, but occasionally, I can get that odd "can't call a nil value" error as well. Try using luup.log("Hello world") instead.

Also, as is being discussed in other threads right now, scene Lua must return a boolean true or false at whatever exit(s) it takes. Returning false stops the scene execution, and true allows it to continue. So your complete test code might look like this:
Code: [Select]
luup.log("Hello world",2)
return true

The second (optional) argument to luup.log is a message level, which defaults to 50 if not given as in the first paragraph's example. In the code above, I've set it to 2, which outputs the message in yellow (warning) to the Vera log file and makes it easier to find. Also note that the log file is buffered, so the "chunk" may not be written to "disk" and accessible to you until other messages have come sufficient to fill the buffer and cause a write/flush of the block. Running your test scene several times will often produce that result.
« Last Edit: November 27, 2018, 07:10:39 am by rigpapa »
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #5 on: November 27, 2018, 12:35:42 pm »
rigpapa,
Thanks for the insight into the print function.

I copied your exact code and still no go. The message is not sent to the logs. I am starting to think there is an issue with my veraedge.
Code: [Select]
08      11/27/18 11:54:07.426   JobHandler_LuaUPnP::HandleActionRequest device: 0 se
rvice: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x7627
d520>
08      11/27/18 11:54:07.427   JobHandler_LuaUPnP::HandleActionRequest argument ser
viceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x7627d520>
08      11/27/18 11:54:07.427   JobHandler_LuaUPnP::HandleActionRequest argument act
ion=RunScene <0x7627d520>
08      11/27/18 11:54:07.428   JobHandler_LuaUPnP::HandleActionRequest argument Sce
neNum=3 <0x7627d520>
08      11/27/18 11:54:07.428   JobHandler_LuaUPnP::HandleActionRequest argument ran
d=0.5230174351797819 <0x7627d520>
08      11/27/18 11:54:07.428   Scene::RunScene running 3 Test02 <0x7627d520>
01      11/27/18 11:54:07.429   LuaInterface::CallFunction_Scene Scene  3 failed att
empt to call a nil

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1030
  • Karma: +166/-1
Re: Cannot execute Lua code in Scene
« Reply #6 on: November 27, 2018, 03:14:04 pm »
OK. Let's try this. Run the request below (change the IP address to that of your Vera where indicated), and post the output. Let's see if a broad view exposes anything interesting.

http://your-vera-ip/port_3480/data_request?id=lua
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #7 on: November 27, 2018, 10:53:44 pm »
Here goes:

Code: [Select]
--Devices with UPNP implementations:
-lu_lua&DeviceNum=1


--GLOBAL LUA CODE:
function scene_4()
luup.log("Hello world",2)
return true
end

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #8 on: November 27, 2018, 10:55:58 pm »
Ran Hello World from Test Luup code (Lua) under Apps->Develop Apps and got the below in the log:

Code: [Select]
08      11/27/18 22:51:43.853   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x75c59520>
08      11/27/18 22:51:43.853   JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x75c59520>
08      11/27/18 22:51:43.854   JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x75c59520>
08      11/27/18 22:51:43.854   JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x75c59520>
08      11/27/18 22:51:43.855   JobHandler_LuaUPnP::HandleActionRequest argument Code=luup.log("Hello world",2)
return true <0x75c59520>
02      11/27/18 22:51:43.856   luup_log:0: Hello world <0x75c59520>

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1030
  • Karma: +166/-1
Re: Cannot execute Lua code in Scene
« Reply #9 on: November 28, 2018, 10:19:54 am »
OK. The scene number in the request output is different from the scene number you've reported up until reply #7. Did you attempt to delete the scene and recreate it? If not, please do these:

http://your-vera-ip/port_3480/data_request?id=scene&action=list&scene=3

http://your-vera-ip/port_3480/data_request?id=scene&action=list&scene=4

If you did recreate the scene, then, well, I'm at a loss. I see no reason for the scene to take a nil error.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #10 on: November 28, 2018, 06:29:22 pm »
Quote
If you did recreate the scene, then, well, I'm at a loss. I see no reason for the scene to take a nil error.
Was hoping you wouldn't say that. I did delete a recreate a new scene to make sure I didn't foobar anything. But for shits and giggles, I check the url you provided.

http://your-vera-ip/port_3480/data_request?id=scene&action=list&scene=3
Code: [Select]
ERROR
http://your-vera-ip/port_3480/data_request?id=scene&action=list&scene=4
Code: [Select]
{ "name": "NewTest01", "triggers_operator": "OR", "groups": [ ], "triggers": [ ], "timers": [ ], "users": "", "modeStatus": "0", "lua": "bHV1cC5sb2coIkhlbGxvIHdvcmxkIiwyKQpyZXR1cm4gdHJ1ZQ==", "encoded_lua": 1, "id": 4, "room": 0, "Timestamp": 1543341318 }

Offline veraedge

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Cannot execute Lua code in Scene
« Reply #11 on: November 28, 2018, 06:33:06 pm »
Not sure if this is related, but while messing with the scene (deleting and recreating), now all the names for my smart lock has changed to "Code #" (# matching the index number). Anyway to restore the names that are associated with each PIN code?
« Last Edit: November 28, 2018, 11:11:28 pm by veraedge »

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1030
  • Karma: +166/-1
Re: Cannot execute Lua code in Scene
« Reply #12 on: November 28, 2018, 07:38:16 pm »
I think it's time you open a ticket with support.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3, Lite. Hassio, Slapdash.