YAAS - Yet Another Alarm Script

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

YAAS - Yet Another Alarm Script

Post by emme »

Ok... this is nothing new...
but it's my way to handle alarms and notification.... and I wish to share and ear your opinion about

My setup works like this:
All PIRs, Magnets, Tamper and flood/gas sensors have the same 4 digits prefix (PIR_, MAG_ etc etc)

Based on the Donoticz Security Panel Status it takes actions

Actions are NOT included here.... this script simply update few variables that will trigger other scripts (not yet implemented) for eventually other actions

Probes and Tampers does not conseder the Domoticz Security panel status
(actually the Arm Home status is not implemented yet)

After 2 minutes with no events, alarm resets and restart:

Code: Select all


local PIR = 'PIR_'       -- Prefisso per devices Sensori Movimento
local MAG = 'MAG_'       -- Prefisso per contatti magnetici
local TMP = 'TMP_'       -- Prefisso per TAMPER
local PRB = 'PRB_'       -- Prefisso per sonde (Allagamento e Gas)
local SECSTATUS = globalvariables['Security']   -- Stato impianto allarme
local AllOff = true      -- Switch per valutazione allarme cessati
local DEBUG = false  
local prfPrompt = '>>> [SECURITY] <<< '

if DEBUG and SECSTATUS ~= 'Disarmed' then print(prfPrompt..'Stato impianto: '..SECSTATUS) end 

function timeDiffVar(vName)
    t1 = os.time()
    updTime = uservariables_lastupdate[vName]
    year = string.sub(updTime, 1, 4)
    month = string.sub(updTime, 6, 7)
    day = string.sub(updTime, 9, 10)
    hour = string.sub(updTime, 12, 13)
    minutes = string.sub(updTime, 15, 16)
    seconds = string.sub(updTime, 18, 19)
    
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    
    tDiff = os.difftime(t1,t2)
    return tDiff
end

commandArray = {}

    if SECSTATUS == 'Disarmed' and uservariables['Alarm_generic_Staus'] ~= '0' then 
        table.insert (commandArray, {['Variable:Alarm_Generic_Status'] = '0' })
        table.insert (commandArray, {['Variable:Alarm_Sirena'] = '0' })
    end 

-- Valutazione allarme
    for devName, devStatus in pairs(devicechanged) do 
        -- TUTTO INSERITO
        if (string.sub(devName,1,4) == PIR or string.sub(devName,1,4) == MAG) and uservariables['Alarm_Generic_Status'] == '0' and SECSTATUS == 'Armed Away' then
            if devStatus == 'On' then
                AllOff = false
                print(prfPrompt..'Riscontro: '..devName.. ' Cambio valore: '..devStatus..' Allarme ON')
                table.insert (commandArray, {['Variable:Alarm_Generic_Status'] = '1' })
                table.insert (commandArray, {['Variable:Alarm_Sirena'] = '1' })
                table.insert (commandArray, {['SendNotification'] = 'ALLARME#Attivato '..devName..' Innesco Sirena' })
            end

        -- SONDE E CONTROLLI PERDITE (indipendenti dallo stato del SecPanel)
        elseif string.sub(devName,1,4) == PRB and uservariables['Alarm_PRB_Status'] == '0'then
            if devStatus == 'On' then
                AllOff = false
                print(prfPrompt..'ALLARME SONDE: '..devName.. ' Cambio valore: '..devStatus..' Silenzioso')
                table.insert (commandArray, {['SendNotification'] = 'SENSORI SICUREZZA#Attivato '..devName..' Richiesta di Verifica Immediata!!!!' })
                table.insert (commandArray, {['Variable:Alarm_Generic_Status'] = '1' })
                table.insert (commandArray, {['Variable:Alarm_PRB_Status'] = '1' })
            end 

        -- TAMPER!!!!
        elseif string.sub(devName,1,4) == TMP then
            if devStatus == 'On' then
                AllOff = false
                print(prfPrompt..'ALLARME TAMPER: '..devName.. ' Cambio valore: '..devStatus..' Allarme ON')
                table.insert (commandArray, {['Variable:Alarm_Generic_Status'] = '1' })
                table.insert (commandArray, {['Variable:Alarm_Sirena'] = '1' })
                table.insert (commandArray, {['SendNotification'] = 'ALLARME#Attivato Tamper '..devName..' Innesco Sirena' })
            end 
        end
    end

-- Azzeramento Allarmi
    if AllOff and uservariables['Alarm_Generic_Status'] ~= '0' and timeDiffVar('Alarm_Generic_Status') >= 120 then 
        print(prfPrompt..'Allarme cessato... Ripristino') 
        table.insert (commandArray, {['Variable:Alarm_Generic_Status'] = '0' })
        table.insert (commandArray, {['Variable:Alarm_Sirena'] = '0' })
        table.insert (commandArray, {['Variable:Alarm_PRB_Status'] = '0' })
        table.insert (commandArray, {['SendNotification'] = 'ALLARME CESSATO#Fine Attività, Azzeramento allarmi e ripristino stato: '..SECSTATUS })
    end

-- Annullamento Sirena
    if uservariables['Alarm_Sirena'] == '1' and timeDiffVar('Alarm_Sirena') >= (tonumber(uservariables['Alarm_Sirena_Min'] * 60)) then
        table.insert (commandArray, {['Variable:Alarm_Sirena'] = '0' }) 
        table.insert (commandArray, {['SendNotification'] = 'SIRENA#Spegnimento Sirena. \n Ripristino stato: '..SECSTATUS })
    end 
    
return commandArray
what do you think about?
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest