Set globalData initial value from user variable?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Set globalData initial value from user variable?

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Set globalData initial value from user variable?

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest