How to address global data in dzvents

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
athoopen
Posts: 40
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Netherlands
Contact:

How to address global data in dzvents

Post 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!!!
Cheers,
Arjan
plugge

Re: How to address global data in dzvents

Post by plugge »

Take a look at the manual:
Global persistent variables: https://www.domoticz.com/wiki/DzVents:_ ... _variables
athoopen
Posts: 40
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: How to address global data in dzvents

Post 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)
Cheers,
Arjan
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: How to address global data in dzvents

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest