dzVents Using a Function From Another Event
Posted: Saturday 09 September 2017 4:14
I currently have several dzVents events in Domoticz. I have an identical function in two events called getMinutes() which gets me the current time of the day in minutes. The first one I forgot to pass the domoticz time object into it properly, the second was done correctly. When the first event ran and used the function it created an error that came from the other script with the same function. The first event is called BT Occupancy, the second event is called Garage dZ.
Function:
dTime is the domoticz time object
Log:
2017-09-07 16:16:48.705 Error: dzVents: Error: An error occured when calling event handler BT Occupancy
2017-09-07 16:16:48.705 Error: dzVents: Error: ...domoticz/scripts/dzVents/generated_scripts/Garage dZ.lua:5: bad argument #1 to 'gmatch' (string expected, got nil)
Notice the first line, there is no explanation of what the error is! The second one looks like a normal error.
I suspected that dzVents was sharing or somehow looking at functions by their name and also looking outside the event (there are no helper functions) and into other events somehow, so I re-named one of the functions and its variables and the errors went away. I am running the latest beta version of domoticz on a PI3.
Am I off track?
Function:
Code: Select all
function getMinutes(dTime)
local raw = dTime.rawTime
local a = {}
local i = 0
for v in string.gmatch(raw, "%d+") do
a[i] = tonumber(v)
i = i + 1
end
local min = a[1] + a[0] * 60
return min
end
Log:
2017-09-07 16:16:48.705 Error: dzVents: Error: An error occured when calling event handler BT Occupancy
2017-09-07 16:16:48.705 Error: dzVents: Error: ...domoticz/scripts/dzVents/generated_scripts/Garage dZ.lua:5: bad argument #1 to 'gmatch' (string expected, got nil)
Notice the first line, there is no explanation of what the error is! The second one looks like a normal error.
I suspected that dzVents was sharing or somehow looking at functions by their name and also looking outside the event (there are no helper functions) and into other events somehow, so I re-named one of the functions and its variables and the errors went away. I am running the latest beta version of domoticz on a PI3.
Am I off track?