Page 1 of 1

Constant or global variable in on section

Posted: Sunday 20 December 2020 20:33
by Barberousse
Hello,

Is it possible to pass a global variable or global constant in the on section? When I try this:

Code: Select all

-- master blind
sejourMasterBlindDevice = "Volet séjour"
-- slave blinds
sejourSlaveBlindDevices = {"Volet lingerie"}
-- slave groups
sejourSlaveGroupDevices = {"Groupe volets séjour"}
-- specific time to wait for before opening
sejourSpecificTime = "08:10"
-- slave blinds 2 at specificTime
sejourSlaveBlindDevicesAfterSpecificTime = {"Volet salon ouest"}

return {
	on = {
		timer = {
		    "at " .. sejourSpecificTime
	    devices = {
            domoticz.globalData.dayDevice,
            sejourMasterBlindDevice
		},

Code: Select all

 2020-12-20 20:27:00.557 Error: dzVents: Error: (3.0.2) .../scripts/dzVents/generated_scripts/Maître séjour 3.lua:18: attempt to index a nil value (field 'globalData') 
I have to change this way to get it working:

Code: Select all

-- master blind
sejourMasterBlindDevice = "Volet séjour"
-- slave blinds
sejourSlaveBlindDevices = {"Volet lingerie"}
-- slave groups
sejourSlaveGroupDevices = {"Groupe volets séjour"}
-- specific time to wait for before opening
sejourSpecificTime = "08:10"
-- slave blinds 2 at specificTime
sejourSlaveBlindDevicesAfterSpecificTime = {"Volet salon ouest"}

return {
	on = {
		timer = {
		    "at " .. sejourSpecificTime
		},
	    devices = {
            "Il fait jour",
            sejourMasterBlindDevice
        }
	},
Any idea to pass global constants or variables to the ON section? Variables declared just before like "sejourMasterBlindDevice", not in global_data "return" statement, are only usable in current script, because if I use them in other scripts, sometimes they will be defined, sometimes not, depending on the order of scripts evaluation.

Than you for your ideas.

Re: Constant or global variable in on section

Posted: Sunday 20 December 2020 22:38
by Barberousse
I tried with "domoticz.helpers.dayDevice" in on section too and it gives a nil error again.

2020-12-20 22:39:31.447 Error: dzVents: Error: (3.0.2) .../scripts/dzVents/generated_scripts/Maître séjour 3.lua:18: attempt to index a nil value (field 'helpers')

Re: Constant or global variable in on section

Posted: Sunday 20 December 2020 23:20
by waaren
Barberousse wrote: Sunday 20 December 2020 22:38 I tried with "domoticz.helpers.dayDevice" in on section too and it gives a nil error again.
The domoticz object with everything in it is passed as first parm to the execute section. It is not known in the on = section.
There are ways around it but it will negatively influence the performance of dzVents quite significant.