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¶m=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