Raspberry Pi + Home Assistant DIY Burglar Alarm

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.

Arm the burglar alarm

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!
  • 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.

Burglar alarm
The email I get when the burglar alarm goes off

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.

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).

Snapshot shell_commands

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

Input_booleans

To control arming and disarming.

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.

12 thoughts on “Raspberry Pi + Home Assistant DIY Burglar Alarm”

  1. hello friend. i followed your tutorial.. i receive the email…but photos no… why that happens? i think the configuration is correct.

    1. I’m not sure. Are there any useful log messages? Can you confirm that the photos are being created in the file locations that you expect them to be in?

  2. Hello. Pretty amazing stuff.
    I’m new in home automation but have some good knowledge in linux and shell programming. I am making my own bulgar alarm using HA in pi with a multisensor and a siren. I’ve done a good progress but would like to make it more efficient. I would like my HA to remember the previous states of “Input booleans” after a PI restart e.g. after a temp power interruption. I am thinking to use shell commands and files acting as flags. So the intial state would be defined by the file name.
    Do you have any idea how i could incorporate “if-like” statements in HA?

    Thanks

    1. We should build that feature into HA, but right now I don’t think it’s there. Someone got it working using shell commands and automations similar to your suggestion. I don’t really have a better idea at the moment. Oh you could use an external MQTT server with persistence I guess but that requires two machines.

    1. You can either go into the phone app and press the DISARM button that I made (it runs the disarm script), or (more conveniently), you can use the IR remote control to send the “disarm sequence” which is basically just a numeric code. So it’s just like a regular alarm system in that you have to type the secret code to disarm.

  3. Too cool! Of course I’d want to have lasers but then that might not be legal. Just saying….

Leave a Reply

Your email address will not be published. Required fields are marked *