Use globalData in dzvents active test?

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:

Use globalData in dzvents active test?

Post by doh »

Trying to use a globalData value in the active part of a dzvents script to determine whether to run it or not, like this:

Code: Select all

return {

	active = function(domoticz)
			return (domoticz.globalData.variablename ~= '')
	end,
	on = ...
This just errors - looks like it doesn't recognise globalData within the active section:

Code: Select all

2019-04-13 22:16:00.503 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: /home/pi/domoticz/scripts/dzVents/scripts/test.lua:4: attempt to index field 'globalData' (a nil value)
Is there a way to achieve this?

Thanks
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use globalData in dzvents active test?

Post by waaren »

doh wrote: Saturday 13 April 2019 23:18 Trying to use a globalData value in the active part of a dzvents script to determine whether to run it or not

Code: Select all

2019-04-13 22:16:00.503 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: /home/pi/domoticz/scripts/dzVents/scripts/test.lua:4: attempt to index field 'globalData' (a nil value)
Is there a way to achieve this?
Yes. define the variable in the helpers = section of the global_data script and refer to it like

Code: Select all

return {

	active = function(domoticz)
			return (domoticz.helpers.variablename ~= '')
	end,
	on = ...
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