Yes , another Alarm script ...

Moderator: leecollings

Post Reply
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Yes , another Alarm script ...

Post by jmleglise »

Same same but different !

You may find some source of inspiration and I will publish in the Wiki, if you are interested and ask for.

- Motion sensor: PIR wireless AND PIR wired sensor (HC-SR501). Search the forum to see my nice case.
- 2 wired siren inside and outside.
- Alarm Mode is a selector with : Off, On, Auto (auto is for auto Arming the alarm based on my system of presence detection of the familly by beacon (bluetooth low energy tracker). Each key of the familly has a beacon. If no beacon is detected inside the house, the alarm is activated.
- The alarm sounds 30 sec after an intrusion detected. And this may be stopped everytime before and after with domoticz switch AND with hardware switch.
- The Alarm may sound only 1 every 3 hours to prevent the neighborhoods to become crazy ...
- The night, special mode : the alarm is always On. (Last TODO, I planned to check a PIR near the chamber, If it detects something before the PIR elsewhere then i will switch off the alarm because a member of the familly wake up.)
- everything on battery (UPC)

Code: Select all

function timedifference (s)
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
 end

local time= os.date("*t")
local minutes = time.min + time.hour * 60
local localhost = 'https://localhost:xxxx'  -- Adapt to your system : port, auth ...
local idxAlarmSoundTimer ='113' 					-- Your Alarm Sound Timer Switch Device IDX

commandArray = {}

device=tostring(next(devicechanged))

-- #################   Disarm Alarm with physical Switch
if device=="Alarm Switch" then    -- intercept the Alarm
    -- os.execute("izsynth \"Alarme désarmée.\" &")
    commandArray[#commandArray + 1] = {['Relay 7 - Internal Siren'] ='Off' }
    commandArray[#commandArray + 1] = {['Relay 8 - External Siren'] ='Off' }
    commandArray[#commandArray + 1] = {['Alarm Mode'] ='Off' }
    commandArray[#commandArray + 1] = {['Alarm Switch'] ='Off AFTER 5' }   -- secondes
    return commandArray 
end

-- #################   30 sec Timer passed. Sounds the Alarm !
if device=="Alarm Sound Timer" and otherdevices[device] == 'On' and otherdevices['Alarm Mode'] ~= 'Off' then  -- Check Alarm Mode a last time 
    commandArray[#commandArray + 1] = {['SendNotification'] ='Maison/Alarm#Siren SOUNDS !!! for 5 minutes.'..time.hour..'h'..time.min..'#0' }
    commandArray[#commandArray + 1] = {['Relay 7 - Internal Siren'] ='On' }    -- sounds 5 minutes  (off delay set to 300 sec)
    commandArray[#commandArray + 1] = {['Relay 8 - External Siren'] ='On' }    -- sounds 5 minutes  (off delay set to 300 sec)
    commandArray[#commandArray + 1] = {['Alarm Sound Timer'] ='Off' }
    return commandArray 
end

-- ################# Detect Intrusion
if string.sub(device,1,6) == 'Motion' and otherdevices[device] == 'On'  -- No burst ! The PIR sensor must emit only 1 per 5 minutes
    and timedifference(otherdevices_lastupdate['Alarm Mode']) > 5*60    --   5 minutes to leave the house when alarm is activated 
    and timedifference(otherdevices_lastupdate['Relay 7 - Internal Siren']) > 3*60*60    --   3h minimal delayed between 2 sounds. no hassle the neighborhood     
    then
    if otherdevices['Alarm Mode'] == 'Auto' then   -- alarm automatic : check presence of beacon;
        beaconHome=0
        for variableName, variableValue in pairs(uservariables) do
            if string.sub(variableName,1,3)=="Tag" and (variableValue ~= "AWAY" or uservariables_lastupdate[variableName]<5*60)   then
                beaconHome=beaconHome+1
            end
        end
    end

    if otherdevices['Alarm Mode'] == 'On' or (otherdevices['Alarm Mode'] == 'Auto' and beaconHome==0) then -- Alarm ON  and Intrusion detected !

        --commandArray[#commandArray + 1] = {['Alarm Sound Timer'] ='On AFTER 30' }   -- Doesnt work ...
        commandArray[#commandArray + 1] = {['Alarm Sound Timer'] ='On' }   -- The switch has an "On delay" of 30sec. It will be intercepted by devicechanged. Trick because the event system doesnt trigger an event for switch activted in Lua...
        --os.execute('curl -k "'..localhost..'/json.htm?type=command&param=switchlight&idx='..idxAlarmSoundTimer..'&switchcmd="On AFTER 30""')  -- doesnt work neither ...
        
        commandArray[#commandArray + 1] = {['SendNotification'] ='Maison/Alarm#Intrusion detected. Siren in 30 seconds.'..time.hour..'h'..time.min..'#0' }
        os.execute("izsynth \"Who is here ? Alarm sounds in 30 secondes.\" &")
        -- TODO take photo !!!
    elseif minutes>1*60 and minutes <5*60 then -- alarm Off, check for security by night
 -- #####################  Security by night  between 1h00 and 5h00
        -- TODO : install a PIR upstairs, to desactivate the alarm if a familly member wake up. 
        os.execute("izsynth \"Who is here ? Alarm sounds in 30 secondes.\" &")
        commandArray[#commandArray + 1] = {['SendNotification'] ='Maison/Alarm#Intrusion detected by night. Who s here ? '..time.hour..'h'..time.min..'#0' }            
        -- TODO take photo !!!        
    end
end

return commandArray
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: Yes , another Alarm script ...

Post by korniza »

nice! I think that is better to build zones with group of sensors and also place security status (arm away/arm home/disarm) inside the script.
I see that most of scripts did not check the status of sensors when they place the alarm. for example I have some z-wave sensors that fail due to bad quality of signal, so if I place alarm without check them I will get after a while an alarm.
Also an extra parameter could be the HOLIDAY mode that if you are on holidays to get an another notification (SMS for example) and check also for any power failure (if intruder had powered off main power of house).
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: Yes , another Alarm script ...

Post by jmleglise »

Thank you for your feed back,
place security status (arm away/arm home/disarm) inside the script.
I don't understand. what do you mean ?

And what do you advice in case of power outage ? (I have my domotic + internet box + siren backed up on an UPC. And I can detect a power outage with the upc)
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest