Are you tired of paying monthly fees for an antiquated alarm system, in this blog post I’m going to show you how you can build your custom made alarm system with a piece of software called home assistant.
DIY alarm system will feature a tablet as a home alarm panel, a Sonos speaker as a siren and a mobile phone notification, the brains of the system is home assistant, a free open source software can can be installed on a computer that is always on or on a dedicated micro computer such as a raspberry pi.
Table of Contents
Home Security Alarm System Course!
If you are just getting started with home assistant I suggest you enroll in my Free Home Assistant Course !
If you want to follow my home security system course then click here
List of Products used in this project:
Check latest prices on Amazon
Philips Hue Motion Sensor: US or UK
Links
Discord: https://discord.gg/cvWnj4Jf9f
Facebook: https://www.facebook.com/leonardosmarthomemakers
Home Assistant
To Install home assistant you can reference this guide: here
And these videos:
Installation Steps
First thing to do is to enable the file editor add-one. This will give us easy access to the configuration files.
Alarm Panel
The alarm panel needs a name, I’m calling it home_alarm, this is an optional configuration. I’m enabling a code to use to disarm the alarm. This code is stored in a secret file, which will enable you to share you configuration file. The arming time is set at 45 seconds which is the time that it takes from when the alarm is armed. This will give you time to leave the property after you armed the alarm. The delay time is the grace period between when the alarm is triggered and the alarm is sounded. Configured at 60 seconds, feel free to change these values as you wish.
I’m adding in ios: to enable notification on IOS devices.
The automation split file of code is there to help us keep the code organised neatly in folders.
Add the following lines of code in the configuration.yaml file and save and restart hass.
automation split: !include_dir_list ./automations/
alarm_control_panel:
- platform: manual
name: home_alarm
code: !secret alarm_code
arming_time: 45
delay_time: 60
ios:
Now add your alarm code in the secrets.yaml file
In my example I’m using 1111
alarm_code: 1111
Sensors
Now this section is open and flexible, in the video I use a Philips Hue bridge with some motion sensors paired, I also have some Aqara sensors and some contact sensor. You can use any type of sensor to detect motion.
The list of compatible sensors you will find them here
Automation to Trigger Alarm
Now in the file editor create the following folders:
automations and inside create an alarm folder.
Now we need to create two automation files, the first file will change the state of the alarm panel to “triggered”.
The second automation will trigger a series of actions based on the fact that the alarm panel is triggered.
Create a new file and call it sound_alarm.yaml within the alarm folder you just created.
Now add this code into the file and save and reload automations:
Replace the binary_sensor with your own sensor, in my example I have three, but you can have more or less.
alias: 'Trigger alarm while armed away'
trigger:
- platform: state
entity_id: binary_sensor.hallway_sensor_motion
to: 'on'
- platform: state
entity_id: binary_sensor.landing_sensor_motion
to: 'on'
- platform: state
entity_id: binary_sensor.landing_sensor_2_motion
to: 'on'
condition:
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_away
action:
service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.home_alarm
Now, create another file in the same folder called notification_alarm.yaml and add this code:
alias: 'Send notification when alarm triggered'
trigger:
- platform: state
entity_id: alarm_control_panel.home_alarm
to: 'triggered'
action:
- service: notify.mobile_app_giordano_s_iphone_7
data:
message: "ALARM! The alarm has been triggered"
- service: media_player.play_media
data:
entity_id: media_player.kitchen
media_content_id: 'http://192.168.1.153:8123/local/siren.mp3'
media_content_type: 'music'
Save and reload automations.
For all of this to work you will need to install home assistant on your mobile device and find out the mobile app name in my case “mobile_app_giordano_s_iphone_7” change the code above with your value.
Add your sonos device to home assistant and keep track of its entity id. In my example it is “media_player.kitchen”.
In the media_content_id replace the IP address with the IP address of your own home assistant.
Then go back to the file editor and create a folder called www
Upload any mp3 that you want to use as a siren. I’m using siren.mp3. Now restart the whole home assistant server.
If you are using a google mini you need to change the media_content_type to ‘audio/mp3’.
DISCLAIMER: This blog post contain affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This allows us to continue to make posts like this.