Confused by variables - plz save a noob :/
Posted: Saturday 10 October 2020 18:20
By trying to clean up my messy scripts, I messed them up even more I fear…
I think I am confused about local, global and persistent variables…
I thought it was practical to put the ids of the devices I often use in global_data, encouraging me to always use the same variable names etc.
So my global_data kinda looks like this:
My scripts usually start with the declaration of the variables of the devices, like
So I removed the often used local declarations and put them in global_data. And nothing worked anymore 
Sooooo…. global and persistent variables aren’t the same thing I guess? Can someone please educate me, because I feel quite silly now.
Thx
I think I am confused about local, global and persistent variables…
I thought it was practical to put the ids of the devices I often use in global_data, encouraging me to always use the same variable names etc.
So my global_data kinda looks like this:
Code: Select all
-- this scripts holds all the globally persistent variables and helper functions
-- see the documentation in the wiki
-- NOTE:
-- THERE CAN BE ONLY ONE global_data SCRIPT in your Domoticz install.
return {
-- global persistent data
data = {
OWMForecast = {}
},
helpers = {
-- SYSTEEM
-- systeem
idxNachtstand = 153,
-- verwarming
idxPompWoonkamer = 1328,
idxPompKeuken = 255,
idxRelaisVerwarming = 1333, -- idxSchakelaarKeuken
-- weer
idx_forecast_weather_6h = 2287, -- temperatuur over 6 uur
-- KAMERS
-- woonkamer
idxBewegingWoonkamer = 2500,
idxLuxWoonkamer = 2502,
idxTempWoonkamer = 1326,
idxThermostaatWoonkamer = 193,
idxSchakelaarEettafel1x = 2117,
idxSchakelaarSalontafel1x = 2164,
idxLampEettafel = 2096,
idxLampSalontafel = 2106,
idxKleineStaandeLamp = 2492,
idxGroteStaandeLamp = 2493,
-- global helper functions
myStatusboard = function(domoticz, statusboard, statusboardCMD)
-- code
if statusboardCMD == 'CLR' then
domoticz.devices(statusboard).updateText('')
else
domoticz.devices(statusboard).updateText(statusboardCMD)
end
end
}
}Code: Select all
local idxLuxWoonkamer = 2502
local idxBewegingWoonkamer = 2500
local idxVentilatorSlaapkamer = 212
local idxSchakelaarEettafel1x = 2117
local idxSchakelaarSalontafel1x = 2164
local idxLampEettafel = 2096
local idxLampSalontafel = 2106
return {
on = {
devices = {
idxBewegingWoonkamer,
idxSchakelaarEettafel1x,
idxSchakelaarSalontafel1x
}, -- end devices
timer = {
'every 12 minutes'
} -- end timer
}, -- end on
et cetera
Sooooo…. global and persistent variables aren’t the same thing I guess? Can someone please educate me, because I feel quite silly now.
Thx