Marque1968 wrote: Friday 01 March 2019 9:37
I have a global_data via the gui:
The findIn... functions I have impemented in the system already, and work as expected, however not so for the constant variables.
But the calling of these constant variables result in the following log entry:
Code: Select all
2019-03-01 09:12:42.878 Status: dzVents: Error (2.4.14): ...icz/scripts/dzVents/generated_scripts/test radiation.lua:1: attempt to index field 'helpers' (a nil value)
I also read there was a DATA section to the global_data.lua, but I do not want these values to be changed by functions in any other script (or even this one, for that matter).
Your global_data is correct but you try to access the domoticz object in your script in an area where it is not accessible.
To retrieve the value from domoticz.helpers.DID_radiationdisplay, you will have to move the assign statement inside the execute = function part
like:
Code: Select all
return {
on = {
devices = { idx_radiation },
timer = {"every minute"},
},
execute = function(domoticz, triggeredItem, info)
local idx_virtual = domoticz.helpers.DID_radiationdisplay
domoticz.log("idx_virtual: " .. idx_virtual)
end
}
The other thing is that the term CONSTANT used in global_data could led you believe that it cannot be changed in your script. Which is not the case as you can see from this example: (Let it execute at least twice to see what happens)
Code: Select all
return {
on = {
timer = {"every minute"},
},
execute = function(domoticz, triggeredItem, info)
local idx_virtual = domoticz.helpers.DID_radiationdisplay
domoticz.log("idx_virtual: " .. idx_virtual)
domoticz.helpers.DID_radiationdisplay = "Not a real constant"
local idx_virtual = domoticz.helpers.DID_radiationdisplay
domoticz.log("idx_virtual: " .. idx_virtual)
end
}
In fact Lua does not know a constant type as such. As explained
here there is a (complicated) way to work around that but I never found a good reason inside the domoticz area to use that approach.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki