I'm having problems getting Luup codes to run for *any* scene I create. The code fails to run 100% of the time. I sent an email to support and they said this was a known bug(?!?!) but I somehow doubt it. I've also tested the code in the Develop Apps -> Test Luup code and using ZeroBrane. The code works as expected.
Here's what I'm doing:
- I created a scene (either manual or triggered...doesn't matter)
- Under the section that says "Also run the following Luup code" I added Add the Luup below
- Then I either trigger the scene by turning on a light in the event of a triggered scene, or run it manually if it's a manual scene. Still no dice.
This happens with *any* Luup code I enter but here's what I'm using:
local function WriteToLog(message, clear)
local socket = require(“socket”)
local time = socket.gettime() or os.time()
local tms = string.format(“.%03d “,math.floor (1000 * (time % 1)))
local stamp = os.date(”%d %b %Y %T”,math.floor(time)) … tms
local mode = “a+”
if clear then mode = “w+” end
local file = io.open(“/www/SceneLog.txt”, mode)
file:write(stamp … (message or “”) … “\n”)
file:close()
end
[quote=“jamespitman, post:1, topic:189412”] Vera Edge v1.7.1419
Hey Everyone -
I'm having problems getting Luup codes to run for *any* scene I create. The code fails to run 100% of the time. I sent an email to support and they said this was a known bug(?!?!) but I somehow doubt it. I've also tested the code in the Develop Apps -> Test Luup code and using ZeroBrane. The code works as expected.
Here's what I'm doing:
- I created a scene (either manual or triggered...doesn't matter)
- Under the section that says "Also run the following Luup code" I added Add the Luup below
- Then I either trigger the scene by turning on a light in the event of a triggered scene, or run it manually if it's a manual scene. Still no dice.
This happens with *any* Luup code I enter but here's what I'm using:
local function WriteToLog(message, clear)
local socket = require(“socket”)
local time = socket.gettime() or os.time()
local tms = string.format(“.%03d “,math.floor (1000 * (time % 1)))
local stamp = os.date(”%d %b %Y %T”,math.floor(time)) … tms
local mode = “a+”
if clear then mode = “w+” end
local file = io.open(“/www/SceneLog.txt”, mode)
file:write(stamp … (message or “”) … “\n”)
file:close()
end
WriteToLog(“Log - Cabinet Lights On”,false)
[/quote]
This is a stab, but aren’t you missing a “return true” at the exit of the code? I think the “Test Luup” thing is forgiving about that, but that actual code embedded in scenes or plugins running in the Luup engine is not.
Thanks for taking a stab at tit but apparently, still no dice. I added "return true" to the end and it still doesn't run
local function WriteToLog(message, clear)
local socket = require(“socket”)
local time = socket.gettime() or os.time()
local tms = string.format(“.%03d “,math.floor (1000 * (time % 1)))
local stamp = os.date(”%d %b %Y %T”,math.floor(time)) … tms
local mode = “a+”
if clear then mode = “w+” end
local file = io.open(“/www/SceneLog.txt”, mode)
file:write(stamp … (message or “”) … “\n”)
file:close()
end
And again, tested it in Luup Test area and it works fine there. Just not in a Scene.
(It’d be nice if someone from Vera support took a look this or confirmed here that there is a bug or something so I can stop banging my head about this
Try changing the WriteLog function to be global rather than local (remove the “local”).
Side note: I generally place global functions in the LUA Startup code section. That way the function will always be available to every scene. (Global Functions that are in a scene are not available until that scene has run, after a reboot/Lua reload).
I apparently got this working and in contrast to what I was told from support, there wasn't a bug in my instance. I had also reported I was getting an error that said "Error in lua for scenes and events". I deleted all my other scenes, and it cleared the error. The Luup code in scenes then started triggering as expected. Now I have a different problem, but thats for a different thread...
Thanks everyone -
Best Home Automation shopping experience. Shop at Ezlo!