Add an application that can be used to build a functional alarm system based on Asterisk, intended for use with raw sensor inputs and using IP phones as input terminals.
Overall workflow conception: use a simple relay to go off hook on an extension with immediate = yes
to call an application whenever activated (e.g. door/window opened)
Sensor triggered:
exten => s,1,AlarmSensor(myclient,door) ; first arg is name of the alarm client, 2nd is optional, the name of the sensor which is being triggered by this invocation
Manual keypad input:
exten => s,1,AlarmKeypad(myclient)
res_alarmsystem.conf
:
[home] ; name of client
type = client ; can be client, sensor, keypad, or server
client_id = 101
master_ip = 10.10.10.1:7788 ; IP/port to reach alarm master over IP
master_phone = DAHDI/g1/*70w18005551212,,D(www12#) ; POTS failover to reach alarm master by phone (will keep line open until disarm_delay has been reached, to avoid multiple calls)
ping_interval = 4 ; how often to ping the master
logfile = /var/log/asterisk/alarmclient.log
egress_delay = 15 ; number of seconds grace period to exit without re-triggering alarm
alarm_context ; same as on server, but won't need to be used in most cases on client. Could be used to do something locally if a break-in occurs, like sound a (louder) alarm
net_context ; same as on server, but won't need to be used in most cases on client. Could be used to do something locally if WAN connectivity is lost, like sound an alarm
[door]
type = sensor
sensor_id = 1
channel = DAHDI/17 ; if specified, then arg2 to AlarmSensor is optional since we can associate this way (and that way, the same immediate context can be used for all sensors)
client = home ; name of client with which this sensor is associated
disarm_delay = 45 ; number of seconds to disarm alarm before considering this a break-in
[keypad]
type = keypad
client = home
device = PJSIP/Polycom,,b(autoans) ; dial string for Dial which should include autoanswer capability for IP phone(s)
; must specify either a context OR a pin (and optionally audio for the latter)
context = panel ; context to which device will be bridged. Must hangup with special cause code XXX (define something non-standard) to indicate successful disarm. Can be used to implement custom disarm logic of your choice
pin = 4577 ; If no custom disarm functionality is required, can specify a hardcoded PIN which must be entered
audio = In conjunction with pin option, an audio file to play while alarm is triggered
; On server:
[general]
bindport=7788 ; bind port for server
[home]
type = server ; Alarm master, not client
alarm_context = alarm,disarmfailure,1 ; dialplan to execute upon failure to disarm alarm (breakin). This could for example send you a page, call an alarm monitoring center or family member, etc.
net_context = alarm,netfailure,1 ; dialplan to execute upon prolonged Internet connectivity failure to client
disarm_delay = 50 ; Amount of time permitted to receive an alarm disarmed event after an alarm is triggered before triggering alarm_context to be executed. Should be at least the value of disarm_delay on the client side
net_delay = 600 ; Amount of time the Internet connection may go out before triggering net_context to be executed. If intermittent outages are common, set this value to exceed that (or 1, to be notified of any connectivity loss).
logfile = /var/log/asterisk/alarmserver.log
Use same protocol for both IP/phone, simple and text based using DTMF characters:
clientID#eventID[sensorID]#
Events:
1 = ALARM_OKAY ; normal initialization or status
2 = ALARM_TRIGGERED ; alarm has been set off
3 = ALARM_DISARMED ; alarm has been disarmed by user
4 = ALARM_ARMED ; alarm has changed from disarmed to alarmed status
5 = ALARM_NET_LOST ; Internet connectivity lost
6 = ALARM_NET_RESTORED ; Internet connectivity restored
Variables provided to dialplan on server side when contexts executed:
${ALARMSYSTEM_CLIENTID}
${ALARMSYSTEM_SENSORID}
${ALARMSYSTEM_EVENT}
CLI commands:
alarmsystem show status <client ID> ; show status of client, ping status, and any connected sensors and their current state
alarmsystem arm <clientID> ; manually arm, e.g. from external app, e.g. task scheduler in Windows making a cURL request to a script that executes this CLI command
alarmsystem disarm <clientID> ; manually disarm, e.g. from external app, e.g. task scheduler in Windows making a cURL request to a script that executes this CLI command
We'll use UDP for IP communication with active bidirectional pings, so that both the client and the server can detect if they've lost connectivity to the other.
Future bonus feature: support reporting to a real alarm system (e.g. server running AlarmReceiver application by phone)
You must be
9/12/2024 5:48 PM — InterLinked
Autoresolved by code commit on GitHub:
res_alarmsystem: Add self-contained alarm system module.
https://github.com/InterLinked1/phreakscript/commit/6c51ec134143d1f201bc5ffd50c5aa213e34d187