We have moved at community.getvera.com

Author Topic: Code runs OK in Test, but not in scene  (Read 2096 times)

Offline XA44Owq26HxCq88

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-1
Code runs OK in Test, but not in scene
« on: January 18, 2019, 11:51:55 am »
I've got a problem this morning. It seems that all of scenes that have LUA code in them are not working. Last night at sunset they all worked fine.

I've tested a sample of code in the APP - Develop Code - Test Lua Code screen.
It works fine.

But when I cut and paste the same code into a test scene, manually operated, just the code, it does not work.

Did I screw something up? I've been trying to fix a door/window device that has intermittent communication (I think the unit has failed). Still haven't fixed that issue, but I may have messed up something else along the way? I updated the neighbor nodes under Settings-Z wave settings-update neighbor nodes.

I'm on a VeraPlus, UI7, have about 25 devices.

Any help would be greatly appreciated

Offline XA44Owq26HxCq88

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-1
Re: Code runs OK in Test, but not in scene
« Reply #1 on: January 18, 2019, 12:59:28 pm »
Thought I'd share the solution that was given to me by the helpful people at the other end of the Vera support phone line.

Here's the situation -

I had been working with trying to diagnose a faulty door/window sensor. I had written a piece of code that would sound my doorbell unit when the door was opened. It seemed to work ok when I tested the code. It did not work when I put it into a scene. I chalked it up to the door/window sensor not working (which it still isn't)

The bottom line is that if you insert a piece of defective LUA code into a scene, Vera will not run ANY LUA code, whether it is in the particular scene where the bad code is, or any other scene that has LUA code.

So my other scenes are now apparently working - I'll be sure when I go through 24 hours. Still working on getting the sensor working. Anybody know of a powered door/window sensor, not a battery operated one?

Hope this helps someone else.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Code runs OK in Test, but not in scene
« Reply #2 on: January 18, 2019, 01:27:00 pm »
Yes it is odd but the entire lua interpreter goes down if it sees any error in the code... You should actually get a warning message on the UI about it. Something like "error in scene lua or plugin". Would have been hard for us to know you had errors in other code! :)
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline rlmalisz

  • Sr. Member
  • ****
  • Posts: 400
  • Karma: +1/-0
Re: Code runs OK in Test, but not in scene
« Reply #3 on: January 18, 2019, 04:07:00 pm »
Thought I'd share the solution that was given to me by the helpful people at the other end of the Vera support phone line.

Here's the situation -

I had been working with trying to diagnose a faulty door/window sensor. I had written a piece of code that would sound my doorbell unit when the door was opened. It seemed to work ok when I tested the code. It did not work when I put it into a scene. I chalked it up to the door/window sensor not working (which it still isn't)

The bottom line is that if you insert a piece of defective LUA code into a scene, Vera will not run ANY LUA code, whether it is in the particular scene where the bad code is, or any other scene that has LUA code.

So my other scenes are now apparently working - I'll be sure when I go through 24 hours. Still working on getting the sensor working. Anybody know of a powered door/window sensor, not a battery operated one?

Hope this helps someone else.

They're battery-powered, but we have the Schlage sensors all around the house.  Replaced the first battery a few weeks back...for a sensor that had been in use for over two years.

--Richard

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +189/-3
Re: Code runs OK in Test, but not in scene
« Reply #4 on: January 18, 2019, 04:26:29 pm »
Yes it is odd but the entire lua interpreter goes down if it sees any error in the code... You should actually get a warning message on the UI about it. Something like "error in scene lua or plugin". Would have been hard for us to know you had errors in other code! :)

I just tried an experiment. I put some garbage into scene Lua for a scene. No error when saving the Lua or the scene--Vera isn't checking syntax at this point. No surprises there (although they could put it through loadstring() and get immediate feedback on it from the underlying interpreter).

On Luup reload, as you said, scene Lua is completely botched for all scenes. Luup logs this fact in nice attention-getting red color in the log. But most informative is what Vera logs there: all of the scene Lua for every scene that has it, and the startup Lua, are displayed as a single Lua fragment in the error message. So this tells us that Luup is making a giant string out of all of it, and pushing it into loadstring() in one go, rather than preparing each individually. This explains why a hard error in any scene or startup Lua disables all scene Lua and startup Lua. So...

Always look in your Vera log file if your scenes stop running. But then, this should go without saying. The Vera log is hard to sift through, but it's full of gold. It may be worth a squiz any time you're editing scene Lua, just to be sure.
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 akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Code runs OK in Test, but not in scene
« Reply #5 on: January 18, 2019, 05:44:44 pm »
...all of the scene Lua for every scene that has it, and the startup Lua, are displayed as a single Lua fragment in the error message. So this tells us that Luup is making a giant string out of all of it, and pushing it into loadstring() in one go, rather than preparing each individually.

Yes, this is a very cheap and cheerful way of making them share the same Lua context.  Rather sad that they didn't bother to use the powerful built-in setfenv() (in Lua 5.1) which can make that happen for separately compiled modules.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline XA44Owq26HxCq88

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-1
Re: Code runs OK in Test, but not in scene
« Reply #6 on: January 25, 2019, 10:15:32 am »
Rafale77,

I had come to expect that blue line warning of the error, but in this instance I wasn't seeing any notice.

I tried to get to my logs using the following command

http://192.168.1.x/cgi-bin/cmh/log.sh?Device=0
(where x is the local device)

Got a "not Found" error

thanks

Offline HSD99

  • Sr. Member
  • ****
  • Posts: 384
  • Karma: +22/-0

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Code runs OK in Test, but not in scene
« Reply #8 on: January 25, 2019, 11:15:09 am »
Use http://vera_IP/cgi-bin/cmh/log.sh?Device=LuaUPnP

That is the correct url to get to the log from the browser.
If the log file happen to be large, this may hammer the browser. If you happen to use USB logging, it may be a while before you see the log.
I highly recommend downloading the log so you can do a search for things by SCP instead. Install winscp and go to /tmp/log/cmh on the vera...
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline HSD99

  • Sr. Member
  • ****
  • Posts: 384
  • Karma: +22/-0
Re: Code runs OK in Test, but not in scene
« Reply #9 on: January 25, 2019, 11:25:08 am »
If you install ALTUI, you can use its built-in tools to view and search the logs.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1121
  • Karma: +189/-3
Re: Code runs OK in Test, but not in scene
« Reply #10 on: January 25, 2019, 01:22:05 pm »
The latest version of LuaView also does syntax-checking of the Lua code and reports any errors (in addition to using the ACE syntax-highlighting editor on both UI7 and AltUI). This may help find errors you might otherwise find difficult to notice (until Luup reloads and then nothing works).
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 rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Code runs OK in Test, but not in scene
« Reply #11 on: January 25, 2019, 01:41:28 pm »
Actually Luaview is a great way to look at all your lua code at once and try to figure out where the problem may come from. Thanks Rigpapa! I did not have much use for it initially but I get the feeling I may need it in the near future.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline XA44Owq26HxCq88

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-1
Re: Code runs OK in Test, but not in scene
« Reply #12 on: January 25, 2019, 02:04:48 pm »
Thanks for the help

http://vera_IP/cgi-bin/cmh/log.sh?Device=LuaUPnP

Did not work for me, I still get the message   "Not Found" error   {}

I've got AltUI installed but cannot find where the log reporting is.

What is winscp? Couldn't find it in apps

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: Code runs OK in Test, but not in scene
« Reply #13 on: January 25, 2019, 02:06:55 pm »
https://winscp.net/eng/index.php

It's a program for windows allowing you to access a remote computer and get files from its drive.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline HSD99

  • Sr. Member
  • ****
  • Posts: 384
  • Karma: +22/-0
Re: Code runs OK in Test, but not in scene
« Reply #14 on: January 25, 2019, 02:46:21 pm »
Thanks for the help

http://vera_IP/cgi-bin/cmh/log.sh?Device=LuaUPnP

Did not work for me, I still get the message   "Not Found" error   {}

I've got AltUI installed but cannot find where the log reporting is.

What is winscp? Couldn't find it in apps

In ALTUI, look under Misc---> OS Commands.  There are a number of pre-built commands for searching and examining the logs.