I just configured a pretty slick burglar alarm with the open-source Home-Assistant platform running on my Raspberry Pi. It can be armed to trigger when a door is opened and/or when a motion sensor goes off.

Then, a sequence of events happens:

An IR LED turns on my stereo

A sound file I cobbled together starts playing. It starts with a computerized voice saying that your entry been detected and recorded, then it beeps for a while (giving you time to disarm), and then it goes into a blaring siren noise. Quite the escalation! https://partofthething.com/thoughts/wp-content/uploads/2016/08/burglar.mp3

A light blinks on and off a few times

A camera takes a series of snapshots of the area

An email is sent to my phone with the snapshots, showing me what’s going on

There’s also a silent-alarm mode that just takes pictures and emails them to me.

To disarm, you have to type the proper disarm sequence with an infrared remote I have sitting on the counter (re-purposed from and old DVD player).

To arm the system, I can flip a switch in the web-based GUI, but I also have it automatically arm at a certain time of night and when I activate the “leaving home sequence” (by turning off the light by the door when the door is open). It temporarily deactivates in the morning when the system detects me waking up. Pretty awesome!

Configuring a Burglar Alarm in Home Assistant

When I started, the SMTP email notification component in HA didn’t support in-line photo attachments so I added that capability with PR #2738. It has been merged and made it into the 0.26 release.

This system uses my Ecolink Z-wave door sensor and my Z-wave Aeotech Multisensor 6 as actuators (see an older post for more info about these). It uses the shell_command component to to take snapshots from my Foscam IP camera, and to issue LIRC commands that turn on the stereo. It uses the lirc component with my $1 IR receiver (hooked directly to the Pi’s GPIO pins) to receive the disarm command (see my earlier post on that). It uses the smtp component to send the email notifications. Here are some config entries:

Burglar automation

This triggers the alarm. (The second condition is important for those times when the disarm button isn’t working yet and your wife triggers like 5 copies of the script that play the siren noise 5 times overlapping and even if she turns off the stereo it keeps turning itself back on and she gets really mad at you. Just saying.

- alias: Burglar Alarm Door trigger: platform: state entity_id: binary_sensor.ecolink_doorwindow_sensor_sensor_3 from: 'off' to: 'on' action: service: script.turn_on entity_id: script.burglar condition: - platform: state entity_id: input_boolean.burglar_alarm_door state: 'on' - platform: state entity_id: script.burglar state: 'off' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 - alias : Burglar Alarm Door trigger : platform : state entity_id : binary_sensor.ecolink_doorwindow_sensor_sensor_3 from : 'off' to : 'on' action : service : script.turn_on entity_id : script.burglar condition : - platform : state entity_id : input_boolean.burglar_alarm_door state : 'on' - platform : state entity_id : script.burglar state : 'off'

Burglar script

This is the sequence that fires off all the commands once triggered. (Note that the images input to the emailer is the new thing I added).

burglar: alias: Burglar Alarm sequence: - service: shell_command.stereo_line_in - service: shell_command.snapshot data: filename: /home/pi/snapshot1.jpg - service: shell_command.fix_camera_jpg data: filename: /home/pi/snapshot1.jpg - delay: seconds: 1 - service: shell_command.intruder_music - service: script.turn_on entity_id: script.night_reminder - service: shell_command.snapshot data: filename: /home/pi/snapshot2.jpg - service: shell_command.fix_camera_jpg data: filename: /home/pi/snapshot2.jpg - service: notify.emailer data: title: 'Intruder alert' message: 'Intruder alert at apartment!!' data: images: - /home/pi/snapshot1.jpg - /home/pi/snapshot2.jpg 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 burglar : alias : Burglar Alarm sequence : - service : shell_command.stereo_line_in - service : shell_command.snapshot data : filename : /home/pi/snapshot1.jpg - service : shell_command.fix_camera_jpg data : filename : /home/pi/snapshot1.jpg - delay : seconds : 1 - service : shell_command.intruder_music - service : script.turn_on entity_id : script.night_reminder - service : shell_command.snapshot data : filename : /home/pi/snapshot2.jpg - service : shell_command.fix_camera_jpg data : filename : /home/pi/snapshot2.jpg - service : notify.emailer data : title : 'Intruder alert' message : 'Intruder alert at apartment!!' data : images : - /home/pi/snapshot1 . jpg - /home/pi/snapshot2 . jpg

Snapshot shell_commands

The convert command (from imagemagick) is required to avoid MIME errors in the SMTP python library (fixes headers somehow).

shell_command: snapshot: wget "http://camip:port/snapshot.cgi?user=<user>&pwd=<password>&resolution=32" -O {{filename}} fix_camera_jpg: convert {{filename}} {{filename}} intruder_music: mpg321 /home/pi/Videos/burglar.mp3 stereo_line_in: irsend SEND_ONCE STEREO KEY_VIDEO1 1 2 3 4 5 shell_command : snapshot : wget "http ://camip :port/snapshot.cgi?user= < user > &pwd = < password > &resolution =32" -O { { filename } } fix_camera_jpg : convert { { filename } } { { filename } } intruder_music : mpg321 /home/pi/Videos/burglar.mp3 stereo_line_in : irsend SEND_ONCE STEREO KEY_VIDEO1

Input_booleans

To control arming and disarming.

input_boolean: burglar_alarm_door: name: Burglar Alarm Door initial: off icon: mdi:lock-outline burglar_alarm_motion: name: Burglar Alarm Motion initial: off icon: mdi:lock-outline burglar_alarm_silent: name: Silent Burglar Alarm initial: off icon: mdi:lock-outline 1 2 3 4 5 6 7 8 9 10 11 12 13 input_boolean : burglar_alarm_door : name : Burglar Alarm Door initial : off icon : mdi :lock-outline burglar_alarm_motion : name : Burglar Alarm Motion initial : off icon : mdi :lock-outline burglar_alarm_silent : name : Silent Burglar Alarm initial : off icon : mdi :lock-outline

Feels pretty good to have all this, plus tons of other elaborate automations for just a few hundred bucks! Plus being able to get into home-assistant’s code and fiddle around is super rewarding and fun.