I have this in my global_data,
Code: Select all
-- Global Data and Helper Functions Configuration
return {
-- Global persistent data
data = {
lastStateUserGPS = {initial = ''},
},
-- Global constants and configurations
constants = {
PUSHOVER = {
-- User IDs
USERS = {
FAMILIE = '1',
},
-- Application IDs
APPS = {
HUIS = '1',
TEST = '1',
WAS = '1',
DOMOTICZ = '1',
ALARM = '1',
SERVER = '1',
},
-- Priority levels
PRIORITY = {
LOWEST = -2,
LOW = -1,
NORMAL = 0,
HIGH = 1,
EMERGENCY = 2
},
-- All available Pushover sounds
SOUNDS = {
-- Default sound
PUSHOVER = 'pushover', -- Default Pushover tone
-- Standard sounds
BIKE = 'bike',
BUGLE = 'bugle',
CASHREGISTER = 'cashregister',
CLASSICAL = 'classical',
COSMIC = 'cosmic',
FALLING = 'falling',
GAMELAN = 'gamelan',
INCOMING = 'incoming',
INTERMISSION = 'intermission',
MAGIC = 'magic',
MECHANICAL = 'mechanical',
PIANOBAR = 'pianobar',
SIREN = 'siren',
SPACEALARM = 'spacealarm',
TUGBOAT = 'tugboat',
-- Long sounds
ALIEN = 'alien', -- Alien Alarm (long)
CLIMB = 'climb', -- Climb (long)
PERSISTENT = 'persistent', -- Persistent (long)
ECHO = 'echo', -- Pushover Echo (long)
UPDOWN = 'updown', -- Up Down (long)
-- Special
VIBRATE = 'vibrate', -- Vibrate Only
NONE = 'none', -- Silent
-- Custom sounds
CLEARANNOUNCETONES = 'clear-announce-tones',
LIGHTSWITCH = 'light-switch',
},
-- Default values
DEFAULTS = {
PRIORITY = 0,
SOUND = 'pushover', -- Changed default to standard Pushover sound
TITLE = 'Domoticz Notification',
TTL = nil,
},
-- Common TTL presets (in seconds)
TTL = {
ONE_HOUR = 3600,
FOUR_HOURS = 14400,
EIGHT_HOURS = 28800,
ONE_DAY = 86400,
THREE_DAYS = 259200,
ONE_WEEK = 604800,
},
},
},
-- Global helper functions
helpers = {
-- Enhanced pushover function with TTL support
pushover = function(domoticz, scriptVar, PushoverUser, PushoverApp, title, message, priority, sound, ttl)
-- Input validation
assert(PushoverUser, 'PushoverUser is required')
assert(PushoverApp, 'PushoverApp is required')
assert(message, 'Message is required')
-- TTL validation when provided
if ttl then
assert(type(ttl) == 'number' and ttl > 0, 'TTL must be a positive number of seconds')
-- TTL is ignored for emergency priority
if priority == domoticz.constants.PUSHOVER.PRIORITY.EMERGENCY then
domoticz.log('TTL is ignored for emergency priority messages', domoticz.LOG_DEBUG)
ttl = nil
end
end
-- Logging
domoticz.log(
string.format(
'Sending Pushover notification - User: %s, App: %s, Title: %s, Sound: %s, TTL: %s',
PushoverUser, PushoverApp, title or 'No title',
sound or domoticz.constants.PUSHOVER.DEFAULTS.SOUND, ttl or 'No TTL'
), domoticz.LOG_DEBUG
)
-- Prepare post data
local postData = {
token = PushoverApp,
user = PushoverUser,
message = message,
title = title or domoticz.constants.PUSHOVER.DEFAULTS.TITLE,
priority = priority or domoticz.constants.PUSHOVER.DEFAULTS.PRIORITY,
sound = sound or domoticz.constants.PUSHOVER.DEFAULTS.SOUND,
}
-- Add TTL if specified
if ttl then
postData.ttl = ttl
end
-- Send notification
domoticz.openURL(
{
url = 'https://api.pushover.net/1/messages.json',
method = 'POST',
callback = scriptVar,
postData = postData,
}
)
end,
},
}
If I do:
Code: Select all
domoticz.log('Test: ' .. domoticz.globalData.constants.PUSHOVER.USERS.FAMILIE, domoticz.LOG_DEBUG)
Code: Select all
2025-01-15 12:39:44.023 Error: dzVents: Test_Pushover: ...ticz/scripts/dzVents/generated_scripts/Test_Pushover.lua:20: attempt to index a nil value (field 'constants')