dzVents helper functions 'problem'
Posted: Friday 21 July 2017 11:36
Looking to dramatically simplify my alarm system scripts, I am struggling to get a helper fuction to work:
I have multiple ways to switch on/off the alarm (keypad, geofence, ..) so want to create a global helper function that does this.
When I call the helper function, it complains about attempting to access a global domoticz (nil value). I find that I cannot access domoticz data nor call domoticz devices from a helper function.
Am I doing something wrong or is that by design?
hetest.lua
return {
active = true,
on = {
devices = { 'hetest' }
},
execute = function(domoticz, dev)
local results = domoticz.helpers.AlarmOn(domoticz.security)
local results = domoticz.helpers.AlarmOff(domoticz.security)
end
}
global_data.lua
return {
helpers = {
AlarmOn = function(state)
print('In AlarmOn: ' .. state)
domoticz.devices('Security Panel').armAway()
end,
AlarmOff = function(state)
print('In AlarmOff: ' .. state)
domoticz.devices('Security Panel').disarm()
end
}
}
Error:
2017-07-21 11:27:16.732 Error: dzVents: Error: An error occured when calling event handler hetest
2017-07-21 11:27:16.732 Error: dzVents: Error: /home/pi/domoticz/scripts/dzVents/scripts/global_data.lua:15: attempt to index global 'domoticz' (a nil value)
I have multiple ways to switch on/off the alarm (keypad, geofence, ..) so want to create a global helper function that does this.
When I call the helper function, it complains about attempting to access a global domoticz (nil value). I find that I cannot access domoticz data nor call domoticz devices from a helper function.
Am I doing something wrong or is that by design?
hetest.lua
return {
active = true,
on = {
devices = { 'hetest' }
},
execute = function(domoticz, dev)
local results = domoticz.helpers.AlarmOn(domoticz.security)
local results = domoticz.helpers.AlarmOff(domoticz.security)
end
}
global_data.lua
return {
helpers = {
AlarmOn = function(state)
print('In AlarmOn: ' .. state)
domoticz.devices('Security Panel').armAway()
end,
AlarmOff = function(state)
print('In AlarmOff: ' .. state)
domoticz.devices('Security Panel').disarm()
end
}
}
Error:
2017-07-21 11:27:16.732 Error: dzVents: Error: An error occured when calling event handler hetest
2017-07-21 11:27:16.732 Error: dzVents: Error: /home/pi/domoticz/scripts/dzVents/scripts/global_data.lua:15: attempt to index global 'domoticz' (a nil value)