I still could do with some help since I try to create a global function to softly switch off a light. The trouble I have is that it returns an error and I have no clue what I am doing wrong.
This is the global function I created:
Code: Select all
return {
-- global persistent data
data = {
myGlobalVar = { initial = 12 }
},
-- global helper functions
helpers = {
myHelperFunction = function(domoticz)
-- code
end,
LightSoftOn = function (domoticz, idx)
-- os.execute("/usr/local/bin/telegramsend Execute LightSoftOn for " .. IDX)
for brightness = 0, 100, 1 do
domoticz.devices(idx).setColorBrightness(255, 255, 255, brightness).afterSec(brightness)
end
return true
end,
LightSoftOff = function (domoticz, idx)
-- os.execute("/usr/local/bin/telegramsend Execute LightSoftOff for " .. idx)
for brightness = 100, 0, -1 do
domoticz.devices(idx).setColorBrightness(255, 255, 255, brightness).afterSec(100 - brightness)
end
domoticz.devices(idx).switchOff().afterSec(idx)
return true
end,
...
and here how I call it:
Code: Select all
return {
on = {
timer = {
'every 2 minutes',
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'TEST',
},
execute = function(domoticz, timer)
-- local Lamp = domoticz.devices(2002)
LightSoftOff (domoticz, 2002)
end
}
Which results in the error:
Code: Select all
2023-06-18 16:46:00.500 Error: dzVents: Error: (3.1.8) TEST: An error occurred when calling event handler XYZtest
2023-06-18 16:46:00.500 Error: dzVents: Error: (3.1.8) TEST: ...i/domoticz/scripts/dzVents/generated_scripts/XYZtest.lua:14: attempt to call a nil value (global 'LightSoftOff')
What am I doing wrong?? All help is appreciated!