9 hours ago
Code:
-- 1. MAPPATURA: "Tag del Sensore" -> "Tag dell'Abilitazione"
local mappa_settori = {
['sensore_area_1_settore_1'] = 'area_1_settore_1',
['sensore_area_1_settore_2'] = 'area_1_settore_2',
['sensore_area_1_settore_3'] = 'area_1_settore_3',
['sensore_area_2_settore_1'] = 'area_2_settore_1',
['sensore_area_2_settore_2'] = 'area_2_settore_2',
['sensore_area_2_settore_3'] = 'area_2_settore_3',
}
local valore_allarme = event.getvalue()
local addr_sorgente = event.dst
if valore_allarme == true then
-- A. CONTROLLO ESCLUSIONE (5/2/x -> 5/5/100+x)
local offset = tonumber(addr_sorgente:match("/([^/]+)$"))
if offset then
local addr_esclusione = "5/5/" .. (100 + offset)
if grp.getvalue(addr_esclusione) == true then
log('ESCLUSO: ' .. addr_sorgente)
return
end
end
-- B. RECUPERO OGGETTO E IDENTIFICAZIONE
local oggetto_allarme = grp.find(addr_sorgente)
local tags = (oggetto_allarme and oggetto_allarme.tags) or {}
local tag_abilitazione_da_cercare = nil
-- Cerchiamo quale dei tag del sensore è presente nella nostra mappa
for _, tag in ipairs(tags) do
local clean_tag = tag:gsub("%s+", ""):lower()
if mappa_settori[clean_tag] then
tag_abilitazione_da_cercare = mappa_settori[clean_tag]
break
end
end
-- C. VERIFICA STATO AREA
if tag_abilitazione_da_cercare then
-- Cerchiamo l'oggetto che ha il tag del settore (es. 'area_1_settore_1')
local ogg_settore = grp.tag(tag_abilitazione_da_cercare)
if #ogg_settore > 0 then
local stato_area = grp.getvalue(ogg_settore[1].address)
if stato_area == true then
-- D. INVIO MAIL
local mailer = require('mail')
local nome_sensore = oggetto_allarme.name or addr_sorgente
local res, err = mailer.send('tua_mail@esempio.it',
'ALLARME: ' .. nome_sensore,
'Allarme reale in ' .. tag_abilitazione_da_cercare)
log('Mail inviata:', res)
else
log('Area disattivata: ' .. tag_abilitazione_da_cercare)
end
else
log('ERRORE: Nessun oggetto di comando trovato con tag: ' .. tag_abilitazione_da_cercare)
end
else
log('ERRORE: Sensore ' .. addr_sorgente .. ' non ha un tag "sensore_area_..." valido.')
end
endHi everybody,
with this script I would like to send a notification (by mail) if an alarm sensor (tag alarm) goes to true but only if this sensor own to a sector (tag "area_x_sector_x) is armed.
The sensor has a second tag "sensore_area_x_settore_x) in order to verify if it owns to the sector armed.
It does not work because the tag value is empty.
How can be possible? Is it possible to use 2 tags for a grp address?
Thanks.