Scene error at Vera Reboot

I have a scene that causes an error when I reboot the Vera. Sometimes it also causes an error when the luup is reloaded.

This scene is scheduled to run every minute and it fetches data from a website and post the value in the multi string device.

This is the error:

LuaInterface::CallFunction_Scene Scene  57 failed attempt to call a nil value <0x7799a520>

This is the Scene code:

[code]-- Input Device
local dID1 = 246 – Multistring Device

– Input Variables
local powerconsumptionLimit = 30 – Percent
local RuntimeLimit = 15 – Minutes
local twSecs = 600 – Number of seconds in time window

local socket = require(“socket”)
local ltn12 = require(‘ltn12’)
local https = require(“ssl.https”)
https.TIMEOUT = 5

– Get UPS Status page
function Powershute()
local response_body = {}
local rBody, code, response_headers, rStatus = https.request{
url = “https://192.168.148.3:6547/quickstatus”,
method = “GET”,
verify = “none”,
mode = “client”,
options = “all”,
protocol = “sslv3”,
headers = {
[“Accept-Encoding”] = “sdch”,
},
sink = ltn12.sink.table(response_body)
}
if (code ~= 200) then
luup.log(“APC: Powerchute page return error”)
return false
else
return table.concat(response_body)
end
end

– Extract values
local page = Powershute()
local DeviceStatus = page: match ‘

([^<])

local RealPowerPct = page: match '
([^<])

local RuntimeRemaining = page: match ‘
([^<]*)

– Set variables in Multistring Device
local timestamp = os.date(‘%X’)
local datestamp = os.date(‘%d %B %Y’)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable1”, DeviceStatus, dID1)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable2”, RealPowerPct, dID1)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable3”, RuntimeRemaining, dID1)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable4”, timestamp, dID1)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable5”, datestamp, dID1)[/code]

I’ve been searching en testing for weeks but I can’t find the error. I’ve even tried adding delays.
I’ve posted an thread before [url=http://forum.micasaverde.com/index.php/topic,35591.msg262988.html#msg262988]http://forum.micasaverde.com/index.php/topic,35591.msg262988.html#msg262988[/url] but I was way off so don’t look at this.

Any help will be greatly appreciated

Not going to be able to help, but I have the same situation. Reload of LUUP sometimes results in error but a second reload clears it. Now that the reload luup button is gone from the serial port config, I’m not even sure where to go to force reload Luup. Any ideas on that one?

One thing to remember is that Vera will run the LUA startup code fairly early in the boot up process, and long before a lot of stuff is set up.

What I find works for me is to set up a scene I call “Initialize”, and I schedule that scene to run in the last statement of my startup code. Therefore the Initialize scene runs when Vera is ready to handle scenes. The Initialize scene contains LUA code that I do not want run until Vera is fully functional (for example, sending out door lock commands).

Do not know about reloading LUA code only, but you can use the following LUA code to reboot Vera (which de facto causes a LUA reload):

os.execute("reboot")

http://<IP_OF_VERA>:3480/data_request?id=reload

Yeah same here, when I reboot vera (Settings - Net & Wifi) or reload the luup engine the scenes comes up with an error. When I reload the luup engine again the error disappears. The problem is that this causes my alarm scene’s to stop working and this happens also when I’m from home

How do you script this? Is there a code that checks if the Vera i fully functional ?

I cheat (and make life easier for me) by making the code for running scenes a function. (I do the same for turning on/off devices.) Making it a function has other advantages as well, as you will see:

In my startup code, I will have the following (of course a lot of additional stuff too):

...
function RunScene(scnnum)
  local iscnnum = tonumber(scnnum)
  luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{ SceneNum = iscnnum },0)
end
...
scnInitialize = 12
RunScene(scnInitialize)

As stated in an earlier post, the Initialize scene will get scheduled, but won’t actually run until Vera is ready to run scenes.

This should be enough. But if further delay is necessary (for example waiting another 2 minutes), you could always have a second “Initialize” scene, and have the scene code in the first Initialize be as follows:

local scnInitialize2 = 13
luup.call_delay("RunScene", 120, scnInitialize2)

By the way, these “delays” will also happen when LUA is reloaded, which will occur when you save things. Caused momentary confusion for me when my door locks were behaving strangely (until I realized this).

Thank you, I got it working now.
Like I mentioned, I did try adding a delay but I guess it wasn’t long enough.

Funny thing I found out is that Vera handles scenes as a function already as I found several log entries with this

function scene_8() my code function scene_15() my code etc

I didn’t want to change all my scenes so I solved it this way.

I added these lines in the scene that caused the error

[code]
function CheckLua()
LuaStartup = 1
end

if LuaStartup == nil then
luup.call_delay(“CheckLua”, 120)
return false
end[/code]

I also tried adding part of the code in the Edit Startup Lua but somehow this resulted in the same error.

Well I still have the same issue but the nil error is a lot less then it used to be.
I was messing around with the new qubino device and after the 4th luup reload the scene error came back.

Shame that Vera doesn’t reload the luup engine automatically after it detects an error.