We have moved at community.getvera.com

Author Topic: Suddenly have the same lua error in all my scenes  (Read 1751 times)

Offline pasqualz

  • Sr. Newbie
  • *
  • Posts: 41
  • Karma: +2/-0
Suddenly have the same lua error in all my scenes
« on: May 19, 2014, 12:01:17 pm »
Hi All,
I'm running a Vera3, UI5 (1.5.622 .)
I've been delving into the wonderful world of lua scripting for exactly 2 weeks and have made some great scenes. Everything was working great until this morning when I made a small lua code change on one scene. Suddenly, after saving the scene, the dashboard status showed ERROR : Error in lua for scenes and events. I thought "No biggie, I obviously screwed up something, I'll just delete what I added. Well, I deleted exactly the line I added, then saved again and got the same error. Then I tried running the scene anyway and got the following error in the log.
Scene::RunScene running 60 test logging <0x2d73f680>
01   05/19/14 11:41:24.469   LuaInterface::CallFunction_Scene Scene  60 failed attempt to call a nil value <0x2d73f680>
I went back into the log and found a log entry that references a possible issue with one of my scenes, the log entry is:

01   05/19/14 11:51:22.569   LuaInterface::LoadCode: [string "function scene_52()..."]:157: ')' expected near 'opensensors' <0x2b8cb000>
01   05/19/14 11:51:22.585   JobHandler_LuaUPnP::Run cannot start lua with code:

Here is the scene lua code:

Code: [Select]
local vol = 65
local son = 27 --mast bdr =33, kitch=27
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " door and window sensors found, and all are closed", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " sensors found and " .. numopen .. " " .. isare .. " open." .. opensensors, Language="en", Volume=vol}, son)
     
end

Can anyone see where the expected ')' is supposed to go? Would this one issue stop all lua code from running?
Thanks
Pasqual

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: Suddenly have the same lua error in all my scenes
« Reply #1 on: May 19, 2014, 01:00:56 pm »
Try adding a blank line to the end of the script.?
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 pasqualz

  • Sr. Newbie
  • *
  • Posts: 41
  • Karma: +2/-0
Re: Suddenly have the same lua error in all my scenes
« Reply #2 on: May 19, 2014, 04:02:37 pm »
Update: I saved all of my lua scripts from my scenes then deleted them all, then recreated the scenes and pasted the scripts back in and everything works again... Very strange, I can't imaging what happened...

Offline rosco70

  • Newbie
  • *
  • Posts: 7
  • Karma: +2/-0
Re: Suddenly have the same lua error in all my scenes
« Reply #3 on: October 21, 2018, 10:53:38 am »
Hi folks

I ended up here because none of my LUA commands in scenes were working, even though the LUA test box in Apps/Develop was working.

I'm a noob and didn't realise that any errors in the LUA code in any scene will cause the LUA in *ALL*scenes to stop working.

When saving new scenes containing LUA you can see if there  are errors in the code in the Vera log. It shows as all the LUA code in your scenes in red, preceded by an error message. It took me a few hours to figure all this out, so I thought I would post here just in case anyone else ends up here.

Cheers, Rob.

Offline seko2

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Suddenly have the same lua error in all my scenes
« Reply #4 on: November 12, 2018, 03:59:46 pm »
Hi Rob,

thanks for this hint which solved my problem too. I had setup may vera from ground up and I made a typo in one LUA command in another scene (only wanted to comment out a line, but switched to Python language -> #). After correcting the comment my new scene also runs as expected. Hours later and after reading your post only...

Sebastian.