Can't run Lua in scenes or test screen

i have a bunch of Lua code that i load on startup. all my functions seem to function just fine, but when i go to Apps > Develop Apps > Test Luup code (Lua) any time i enter code in there to run something that i’ve written it fails. so, for eaxample, i have a function in my code called setLocation() that i use to set house modes using distance from the phones. i have a variable_watch on the phone distance and that function gets called any time the phones move. in the logs i can see it running just fine, but when i go to test luup code, i get the following error. And yes, i am calling it with the module i used to load it at startup.

01 10/20/18 20:16:44.658 LuaInterface::StartEngine failed run: 0 [string “sebbyCode.setLocatin()”]:1: attempt to call field ‘setLocatin’ (a nil value)

anyone got any ideas?

Good morning,

Please note that we have opened a trouble ticket in our system for this subject, please reply there.

Thank you.

Just to add a bit to this. this is the log of that function running on my vera being called by one of the variable_Watch functions, so i know the function is working correctly.

50 10/21/18 15:30:27.421 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > ###### FUNCTION -> setLocation() <0x751f1520> 50 10/21/18 15:30:27.421 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Current house mode is: 1 = HOME <0x751f1520> 50 10/21/18 15:30:27.421 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Got the distances in the setLocation() function. A's phone status is: 326.46 and B's phone status is: 0.023 <0x751f1520> 50 10/21/18 15:30:27.422 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Checking the overrides, home override is: 0 and away override is :0. 0=off, 1=on <0x751f1520> 50 10/21/18 15:30:27.422 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Checking distances to set the house mode <0x751f1520> 50 10/21/18 15:30:27.422 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > looks like we are home or the HOME override is set. set location to HOME <0x751f1520> 50 10/21/18 15:30:27.423 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > It is daytime hours <0x751f1520> 50 10/21/18 15:30:27.423 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Checking if things changed, if they have, set the new modes. Old House Mode was: HOME, new House Mode is: HOME <0x751f1520> 50 10/21/18 15:30:27.423 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > The mode did not need to change <0x751f1520> 50 10/21/18 15:30:27.424 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > It's summer <0x751f1520> 50 10/21/18 15:30:27.425 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Thermostats need to change <0x751f1520> 50 10/21/18 15:30:27.425 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Manual thermostat was set to 0. 1 = allow manual settings, 0 = automated <0x751f1520> 50 10/21/18 15:30:27.429 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > SUMMER - The inside temp = 74.5 is greter than (set point UP - temp variance) = 68 NORMAL SUMMER OPERATION <0x751f1520> 50 10/21/18 15:30:27.429 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Setting the UPSTAIRS_THERM to mode: CoolOn, and to temperature: 73 <0x751f1520> 50 10/21/18 15:30:27.430 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > SETTING THERMOSTATS FOR :UPSTAIRS_THERM <0x751f1520> 50 10/21/18 15:30:27.430 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > thermMode = CoolOn the passed mode = CoolOn <0x751f1520> 50 10/21/18 15:30:27.430 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > thermSetPoint = 73.5 the passed setPoint = 73 <0x751f1520> 50 10/21/18 15:30:27.430 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > the thermostats were set correctly to CoolOn. No need to change them <0x751f1520> 50 10/21/18 15:30:27.431 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Setting the thermostats temperature to 73 <0x751f1520> 50 10/21/18 15:30:27.435 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > SUMMER - The inside temp = 68 is greter than (set point UP - temp variance) = 68 NORMAL SUMMER OPERATION <0x751f1520> 50 10/21/18 15:30:27.435 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Setting the DOWNSTAIRS_THERM to mode: CoolOn, and to temperature: 73 <0x751f1520> 50 10/21/18 15:30:27.436 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > SETTING THERMOSTATS FOR :DOWNSTAIRS_THERM <0x751f1520> 50 10/21/18 15:30:27.436 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > thermMode = CoolOn the passed mode = CoolOn <0x751f1520> 50 10/21/18 15:30:27.436 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > thermSetPoint = 73 the passed setPoint = 73 <0x751f1520> 50 10/21/18 15:30:27.437 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > the thermostats were set correctly to CoolOn. No need to change them <0x751f1520> 50 10/21/18 15:30:27.437 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > The thermostat temperature were set correctly to 73. No need to change them <0x751f1520> 50 10/21/18 15:30:27.437 luup_log:0: =*=*=*=*=*=>>>> SEB_LOG =*=*=*=*=> > > > > Returning the mode 1, which is: HOME <0x751f1520>

I then tried to run that function via the “Test Luup code (Lua)”. it immediately fails on the UI and i get this in the logs:

08 10/21/18 15:30:35.357 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x70faf520> 08 10/21/18 15:30:35.358 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x70faf520> 08 10/21/18 15:30:35.358 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x70faf520> 08 10/21/18 15:30:35.358 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x70faf520> 08 10/21/18 15:30:35.358 JobHandler_LuaUPnP::HandleActionRequest argument Code=sebbyCode.setLocation() <0x70faf520> 01 10/21/18 15:30:35.359 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.setLocation()"]:1: attempt to call field 'setLocation' (a nil value) <0x70faf520> 01 10/21/18 15:30:35.359 JobHandler_LuaUPnP::RunLua failed: sebbyCode.setLocation() <0x70faf520> 02 10/21/18 15:30:35.359 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x70faf520>

Still racking my brain on this one. I have no idea why my code would run just fine in the Vera environment, but not in scenes or the “Test Luup code (Lua)” page. Support seems to have gone dormant… anyone have any ideas?

[quote=“sebby, post:1, topic:199946”] 01 10/20/18 20:16:44.658 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.setLocatin()"]:1: attempt to call field 'setLocatin' (a nil value)
anyone got any ideas?[/quote]

Looks like just a typo?

Error message say setLocatin() not setLocation()

Thanks AK, that example had a typo. the issue still persists even if I don’t fat-finger things… Also of note, all of this was working a few weeks ago, the code running on Vera, scenes, and the test luup code all worked just fine. i added a plugin and some child devices and now the code runs fine in the Vera environment, but not in the scenes or test luup code. very strange…

08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument Code=sebbyCode.setLocation() <0x6fb50520> 01 10/28/18 13:36:03.061 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.setLocation()..."]:1: attempt to call field 'setLocation' (a nil value) <0x6fb50520> 01 10/28/18 13:36:03.061 JobHandler_LuaUPnP::RunLua failed: sebbyCode.setLocation() <0x6fb50520> 02 10/28/18 13:36:03.062 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x6fb50520>

[quote=“sebby, post:6, topic:199946”]Thanks AK, that example had a typo. the issue still persists even if I don’t fat-finger things… Also of note, all of this was working a few weeks ago, the code running on Vera, scenes, and the test luup code all worked just fine. i added a plugin and some child devices and now the code runs fine in the Vera environment, but not in the scenes or test luup code. very strange…

08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument Code=sebbyCode.setLocation() <0x6fb50520> 01 10/28/18 13:36:03.061 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.setLocation()..."]:1: attempt to call field 'setLocation' (a nil value) <0x6fb50520> 01 10/28/18 13:36:03.061 JobHandler_LuaUPnP::RunLua failed: sebbyCode.setLocation() <0x6fb50520> 02 10/28/18 13:36:03.062 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x6fb50520> [/quote]

sebby, double-check the name of the function definition in your module/startup code. The error message specifically suggests that (1) [tt]sebbyCode[/tt] is being found (because it not issuing an error related to a reference through nil, which you would get if [tt]sebbyCode[/tt] was nil/undefined), and (2) [tt]setLocation[/tt] is not defined within what is being found as [tt]sebbyCode[/tt] (or it is defined, but declared [tt]local[/tt]).

You might also run this in the Lua test tool, and see if outputs expected results (to the Vera log–run it several times to make sure the log’s buffering flushes more quickly):

luup.log("sebbyCode is a " .. type(sebbyCode),2) for k,v in pairs(sebbyCode) do -- this will give an error if sebbyCode is undefined or not table, which is fine--that's good info luup.log(k .. " is a " .. type(v) .. " with value " .. tostring(v),2) end

This should dump the contents of [tt]sebbyCode[/tt] if it’s a table (or module), and you should see the function listed there as it is defined, e.g. [tt]setLocation is a function with value function: 0xabcdef[/tt]

[quote=“rigpapa, post:7, topic:199946”][quote=“sebby, post:6, topic:199946”]Thanks AK, that example had a typo. the issue still persists even if I don’t fat-finger things… Also of note, all of this was working a few weeks ago, the code running on Vera, scenes, and the test luup code all worked just fine. i added a plugin and some child devices and now the code runs fine in the Vera environment, but not in the scenes or test luup code. very strange…

08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x6fb50520> 08 10/28/18 13:36:03.060 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x6fb50520> 08 10/28/18 13:36:03.061 JobHandler_LuaUPnP::HandleActionRequest argument Code=sebbyCode.setLocation() <0x6fb50520> 01 10/28/18 13:36:03.061 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.setLocation()..."]:1: attempt to call field 'setLocation' (a nil value) <0x6fb50520> 01 10/28/18 13:36:03.061 JobHandler_LuaUPnP::RunLua failed: sebbyCode.setLocation() <0x6fb50520> 02 10/28/18 13:36:03.062 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x6fb50520> [/quote]

sebby, double-check the name of the function definition in your module/startup code. The error message specifically suggests that (1) [tt]sebbyCode[/tt] is being found (because it not issuing an error related to a reference through nil, which you would get if [tt]sebbyCode[/tt] was nil/undefined), and (2) [tt]setLocation[/tt] is not defined within what is being found as [tt]sebbyCode[/tt] (or it is defined, but declared [tt]local[/tt]).[/quote]

thanks for the help rigpappa, setLocation is actually defined as a global [_G.setLocation()]. i would think that if it was not defined correctly, it would not run at all. what i am experiencing is that the code runs just fine when triggered from one of my luup.variable_watch functions (also defined in sebbyCode), but it only fails in scenes or the test luup code.

You might also run this in the Lua test tool, and see if outputs expected results (to the Vera log--run it several times to make sure the log's buffering flushes more quickly):

luup.log("sebbyCode is a " .. type(sebbyCode),2) for k,v in pairs(sebbyCode) do -- this will give an error if sebbyCode is undefined or not table, which is fine--that's good info luup.log(k .. " is a " .. type(v) .. " with value " .. tostring(v),2) end

This should dump the contents of [tt]sebbyCode[/tt] if it’s a table (or module), and you should see the function listed there as it is defined, e.g. [tt]setLocation is a function with value function: 0xabcdef[/tt]

i ran the code, and it errors from the test luup screen. It shows the code looking like a string, not sure what i would have expected there. this is what it shows in the log:

08 10/28/18 14:09:13.530 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x70a0e520> 08 10/28/18 14:09:13.530 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x70a0e520> 08 10/28/18 14:09:13.531 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x70a0e520> 08 10/28/18 14:09:13.531 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x70a0e520> 08 10/28/18 14:09:13.531 JobHandler_LuaUPnP::HandleActionRequest argument Code=luup.log("sebbyCode is a " .. type(sebbyCode),2) for k,v in pairs(sebbyCode) do -- this will give an error if sebbyCode is undefined or not table, which is fine--that's good info luup.log(k .. " is a " .. type(v) .. " with value " .. tostring(v),2) end <0x70a0e520> 02 10/28/18 14:09:13.532 luup_log:0: sebbyCode is a string <0x70a0e520> 01 10/28/18 14:09:13.532 LuaInterface::StartEngine failed run: 0 [string "luup.log("sebbyCode is a " .. type(sebbyCod..."]:2: bad argument #1 to 'pairs' (table expected, got string) <0x70a0e520> 01 10/28/18 14:09:13.532 JobHandler_LuaUPnP::RunLua failed: luup.log("sebbyCode is a " .. type(sebbyCode),2) for k,v in pairs(sebbyCode) do -- this will give an error if sebbyCode is undefined or not table, which is fine--that's good info luup.log(k .. " is a " .. type(v) .. " with value " .. tostring(v),2) end <0x70a0e520> 02 10/28/18 14:09:13.532 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x70a0e520>

If [tt]setLocation[/tt] is defined as a global (in _G), then it’s no surprise that a call to [tt]sebbyCode.setLocation()[/tt] fails, because you are trying to call a function called [tt]setLocation[/tt] that lives inside [tt]sebbyCode[/tt], not a global (_G).

Unless that clarifies the problem enough for you, you need to post ALL of your code so we can get a complete picture. Having [tt]sebbyCode[/tt] come back as a string makes no sense all around, but you’re certainly not going to find [tt]setLocation[/tt] in a string object.

[quote=“rigpapa, post:9, topic:199946”]If [tt]setLocation[/tt] is defined as a global (in _G), then it’s no surprise that a call to [tt]sebbyCode.setLocation()[/tt] fails, because you are trying to call a function called [tt]setLocation[/tt] that lives inside [tt]sebbyCode[/tt], not a global (_G).

Unless that clarifies the problem enough for you, you need to post ALL of your code so we can get a complete picture. Having [tt]sebbyCode[/tt] come back as a string makes no sense all around, but you’re certainly not going to find [tt]setLocation[/tt] in a string object.[/quote]

yup, that makes sense. i tried to define it global to see if it would work and forgot to change my code. so, with it left as a global, i can call that function and it returns as expected in the logs (THANK YOU!!!). now any other calls to functions that are not global, i am still getting issues on those, for example my whichHouse() call that returns the house the code runs at.

10/28/18 15:33:40.826 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x70fe2520> 08 10/28/18 15:33:40.826 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x70fe2520> 08 10/28/18 15:33:40.826 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x70fe2520> 08 10/28/18 15:33:40.826 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x70fe2520> 08 10/28/18 15:33:40.826 JobHandler_LuaUPnP::HandleActionRequest argument Code=sebbyCode.whichHouse() <0x70fe2520> 01 10/28/18 15:33:40.827 LuaInterface::StartEngine failed run: 0 [string "sebbyCode.whichHouse()"]:1: attempt to call field 'whichHouse' (a nil value) <0x70fe2520> 01 10/28/18 15:33:40.827 JobHandler_LuaUPnP::RunLua failed: sebbyCode.whichHouse() <0x70fe2520> 02 10/28/18 15:33:40.828 JobHandler_LuaUPnP::RunAction device -1 action urn:micasaverde-com:serviceId:HomeAutomationGateway1/RunLua failed with 401/Code failed <0x70fe2520>

Excellent progress! OK, so now, your job is to figure out why sebbyCode is a string. That seems wrong, when you’re using it like a module. Use my test code from a previous post to confirm, probably hasn’t changed yet, but when that test code starts reporting expected functions from sebbyCode, you’ve found the problem. If it’s not jumping out at you, PM me your startup Lua where you define those functions.