Page 1 of 1

Set globalData initial value from user variable?

Posted: Saturday 13 April 2019 22:40
by doh
Is it possible to do something like this in global_data.lua:

Code: Select all

globalvariablename = { initial = domoticz.variables('user_variable_name').value }
I tried this but it doesn't seem to work.

What's the best way to initialise globalData values from user variables?

I'd prefer not to have to put the values directly in global_data.lua as (a) they could be sensitive - like passwords and (b) it's easier to update and edit user variables through the GUI.

Thanks

Re: Set globalData initial value from user variable?

Posted: Saturday 13 April 2019 23:22
by waaren
doh wrote: Saturday 13 April 2019 22:40 Is it possible to do something like this in global_data.lua:

Code: Select all

globalvariablename = { initial = domoticz.variables('user_variable_name').value }
I tried this but it doesn't seem to work.
Not possible as the domoticz object is not available in that part of global_data.lua. But what is your usecase if you already have this value in a uservariable ?
What's the best way to initialise globalData values from user variables?
Initialise in a helper function and pass the domoticz object to that helper function.

define helper function in global_data.lua

Code: Select all

	helpers =   {
					mySecretValue = function(dz, var)
						return var.value
					end,
                }
and call with:

Code: Select all

dz.log(dz.helpers.mySecretValue(dz, dz.variables('password')),dz.LOG_FORCE)