Page 1 of 1

How to address global data in dzvents

Posted: Monday 24 July 2023 11:05
by athoopen
All,

I am trying to adress global data and I only get error messages :? so I must be doing something wrong, but I don't know what.
Could any of you help this beginner out?

I have a global script called "Global":

Code: Select all

return {
	data = {
		-- Max Helderheid van lampen
		HelderheidVoordeur        = { initial = 100 },
		HelderheidSierverlichting = { initial = 40 },
		HelderheidSchuurdeur      = { initial = 80 } 
		-- Let op: laatste data regel wordt NIET afgesloten met een komma!
	},
	helpers = {
            .... all my functions are here...
NB: In the above the 3 vars are actually more "constants", they will not be changed in any kind.
I got a script which needs to use the value of HelderheidVoordeur:

Code: Select all

return {
	on = {
		timer = {
			'at 10:41',
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'BuitenlampVoordeurAan',
	},
	execute = function(domoticz, timer)
        local dg = require ("Global")
        local helderheid = dg.data.HelderheidVoordeur -- error on next line: concatenate table??
        domoticz.log('HelderheidVoordeur is ' .. helderheid, domoticz.LOG_INFO)

        -- Welke vertraging moet er gebruikt worden
        local delay   = dg.helpers.SunshineDelay("Sunset")
        -- Melding in de log
        domoticz.log('Delay BuitenlampVoordeurAan is ' .. delay, domoticz.LOG_INFO)
        -- os.execute("/usr/local/bin/telegramsend Delay BuitenlampVoordeurAan is " .. delay)
        -- Zachtjes aan zetten ...
        local results = dg.helpers.LightFadeIn(domoticz, 2001, delay, 0, helderheid)
	end
}
I use dg=require("Global") to adress the global data and functions/helpers then dg.data.HelderheidVoordeur to get the value. But using this value in domoticz.log() gives the error "concatenate table".
If I set local helderheid=100 it all works including calling the helper functions LightFadeIn....

What is the correct way to get the value of the global var HelderheidVoordeur ????

TIA!!!

Re: How to address global data in dzvents

Posted: Monday 24 July 2023 11:23
by plugge
Take a look at the manual:
Global persistent variables: https://www.domoticz.com/wiki/DzVents:_ ... _variables

Re: How to address global data in dzvents

Posted: Monday 24 July 2023 12:31
by athoopen
Thank you!! Got it working now.

Followed the wrong tutorial .... RTFM :D

For those who still need help:
  • Remove local dg = require ("Global")
  • Replace usage of dg into domoticz
  • Global script filename must be global_data (not Global)

Re: How to address global data in dzvents

Posted: Monday 24 July 2023 19:27
by Kedi
I use in the scripts (just part of the code):

Code: Select all

local dg = require ("global_data")
dz.executeShellCommand(dg.MQTTDOMCMD..'-t '  .. MQTTTopic .. " -m '" .. message .. "'")
In the globel_data.lua I just have

Code: Select all

MQTTDOMCMD = 'mosquitto_pub -h 127.0.0.1 -u <user> -P <password> ',
This way I can "compress" commands and reuse them and see what the origin is.