Page 1 of 1

Why does "local domoticz = require("global_data")" not always work?

Posted: Saturday 18 February 2023 13:21
by Sarcas
My scripts use a lot of info I put in global_data. That file looks a bit like this:

Code: Select all

return {
	-- global persistent data
	data =	{
		OWMForecast = {},
		kelvinBuiten = {},
		hueScenes  = {},
		sceneWoonkamerStatus = { initial = 'Auto' }
			},

	helpers =	{
-- SYSTEEM
		idxNachtstand  = 153,
-- KAMERS
-- woonkamer
		idxBewegingWoonkamer = 2500,
		idxLuxWoonkamer = 2502, 
		idxTempWoonkamerOog = 2508, 
		idxTempWoonkamerRookmelder = 5149,
		idxThermostaatDagstandWoonkamerVirtual = 5131,
		idxThermostaatNachtstandWoonkamerVirtual = 3127,
		idxModusWoonkamerRadiatorknop = 5117,
			}
	}

A lot of my scripts start like this:

Code: Select all

local domoticz = require("global_data")

local idxLuxWoonkamer = domoticz.helpers.idxLuxWoonkamer
local idxNachtstand = domoticz.helpers.idxNachtstand
local idxBuitengroep = domoticz.helpers.idxBuitengroep
local idxMuggenlamp = domoticz.helpers.idxMuggenlamp

return {
    on = {
        devices = {
            idxLuxWoonkamer
        },
        timer = {
            "every minute"
            
            et cetera
            
But some scripts simply refuse to work unless I do it like:

Code: Select all

-- local domoticz = require("global_data")

local idxLuxWoonkamer = 2502
local idxNachtstand = 153
local idxBuitengroep = 10
local idxMuggenlamp = 5233

return {
    on = {
        devices = {
            idxLuxWoonkamer
        },
        timer = {
            "every minute"
All my script names start with a z because I read that global_data has to load first when starting up domoticz. It should work. It works for most of my scripts. But some dont. No error, no nothing. Like they dont exist. What is going on?