I've not talked too much about my Home Assistant installation but it's absolutely amazing and I've just done something even more awesome with it. Creating a home alarm system was much easier than I'd anticipated and I'm going to share all of the details here!
Home Assistant
If you want to do any home automation and you don't know about Home Assistant, then you need to get acquainted with it very quickly. I control so much stuff in my house with it and it's so damn awesome and easy to do. I have smart light switches, smart power outlets, energy monitoring, a water pump, external lighting, a garage door opener and motion sensing lights that vary how bright they come on based on the time of day all hooked up to it, and that's just off the top of my head. There are no subscriptions to pay, you just need a Raspberry Pi and a bit of time to set it up.
Of course it has a companion mobile app that offers all of the same functionality too.
Creating a home alarm system
Whilst exploring the options of additional things I can hook up to Home Assistant, I came across the ability to create a home alarm system and it got me wondering... What does an alarm system actually need to do? You need to be able to turn it on and off, it needs to detect that people are there when it's turned on and it needs to let you know. These are all things I already do with Home Assistant in some way or another.
Notifications
We already have notifications setup and they go directly to my wife's phone and to my phone for a variety of different things. Here is a look at the list of notifications recently sent to my phone.
We have a smart doorbell, the Ubiquiti Doorbell G4, and it's hooked into Home Assistant so that when someone presses the button, we get a notification!
Here's how that looks in Home Assistant:
It's easy to create notifications for almost anything and this will come in handy later.
Audible Warnings
The other cool thing with our smart doorbell automation is that it's also hooked into the Echo Dot speakers we have in most rooms of the house and it plays a doorbell chime for us. Not only do we get a notification to our phones when something happens, but we can also play sounds in the house... Interesting!
The Echo Dot speakers might not be the loudest speakers in the world, but they're definitely good enough to act as a doorbell chime.
Motion Detection
The next feature I'd like to have for an alarm system is to detect people inside the house and we already have a bunch of these Xiaomi Aqara Motion Sensors which are little battery operated PIR sensors.
You can pick these up for a few GBP/USD each so they're really cheap and they run on a CR2450 battery which at my current rate of power consumption will last about 3 years. We generally stick these on the corner of door frames and I use them to control the lights in the hallways, the landing, the utility room and the pantry. Places where you walk through for just a moment and don't want to turn the lights on and off frequently. The motion sensor detects movement when you walk in and turns the lights on and then, 30 seconds after you're gone, it turns the lights back off for you!
You don't need to worry about difficulty checking battery levels because you can (of course) also monitor those through Home Assistant so you know exactly where you are.
Based on how long I've been using these sensors for already, and how little battery power has been consumed, I can say they will be lasting for quite a long time on a single battery.
Door opening/closing detection
Another Xiaomi Aqara product we use quite widely is the Door and Window sensor, which is a simple reed switch device for checking if a door or window is open or closed.
The most useful one of these we have is on the garage door and we have an automation to let us know at 22:00 every night if the garage door is still open. In itself that's quite a good anti-burglary mechanism and it's saved us a few times from leaving the garage door open all night, but it will form part of a bigger picture soon.
CCTV Cameras
I recently wrote about my CCTV upgrade at home in Securing my house with Ubiquiti's UniFi Protect range and if you do have a home CCTV system, there's a good chance it will have some kind of motion detection and notification facility.
My Ubiquiti kit hooks directly into Home Assistant so any motion detection trigger on my CCTV system can pass through and be used by Home Assistant too. This gives me another reliable source of motion detection alongside the PIR sensors and allows me to extract even more value out of my CCTV cameras.
Creating an alarm
Once you have all of the physical devices and sensors you're going to use already in place, creating the alarm in Home Assistant is really simple. The first thing you need to do is create it in your configuration.yaml
file.
default_config:
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
light: !include lights.yaml
sensor: !include sensors.yaml
binary_sensor: !include binary_sensors.yaml
input_select: !include input_selects.yaml
alarm_control_panel: !include alarm_control_panel.yaml
http:
use_x_forwarded_for: true
trusted_proxies: 172.30.33.2
discovery:
enable:
- nanoleaf_aurora
I like to keep my configuration file as simple as possible so I've moved various pieces of configuration to external files and included them in. Right down at the bottom of the list you can see my alarm_control_panel.yaml
file which is where I'm going to define my alarm, and here it is.
- platform: manual
name: Home Alarm
code: 1234
code_arm_required: false # Don't need code to arm.
disarm_after_trigger: false # Leave alarm armed after triggering.
arming_time: 30 # Time to leave the house after arming.
delay_time: 60 # Time to turn off after entering the house.
trigger_time: 600 # How long the alarm goes off for.
disarmed:
trigger_time: 0 # Can't be triggered when disarmed.
armed_home:
arming_time: 0 # Arm instantly when at home.
delay_time: 0 # Trigger instantly when at home.
That's the basics to create an alarm in Home Assistant and I added a new Dashboard just for my alarm panel.
Because I set code_arm_required: false
above, I can turn on the alarm without having to enter the code, the code is only required to disarm the alarm. The alarm also has two modes, away
and home
but I'm only using away.
When arming it in away
mode, it sets the full alarm with all sensors and triggers, but home
mode might be used when you're in bed to only arm things downstairs, as an example. We have two dogs that act as a pretty good alarm system downstairs when we're in bed which is why we only need away
mode. Now that the alarm is setup and configured, you need to create some automations to control what happens when the alarm is in each state.
Automations
I have created 4 automations for my alarm, one for each of the various states when I'd like to something to happen.
Let's go through these and start with Alarm - Trigger when motion detected
. This is when the alarm has been armed and something is going to trigger it.
- alias: Alarm - Trigger when motion detected
trigger:
- platform: state
entity_id: binary_sensor.presence_49
to: 'on'
- platform: state
entity_id: binary_sensor.presence_45
to: 'on'
- platform: state
entity_id: binary_sensor.presence_51
to: 'on'
- platform: state
entity_id: binary_sensor.presence_46
to: 'on'
- platform: state
entity_id: binary_sensor.presence_55
to: 'on'
- platform: state
entity_id: binary_sensor.openclose_42
to: 'open'
- platform: state
entity_id: binary_sensor.motion_garage
to: 'on'
- platform: state
entity_id: binary_sensor.presence_62
to: 'on'
condition:
condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_home
- 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
id: efbb8954de8045aaaa0aa814bde515ae
Here I have a variety of binary_sensor.presence_xx
which are the Aqara PIR sensors throughout the house, I have the binary_sensor.openclose_42
which is the garage door and I have binary_sensor.motion_garage
which is the motion detection on the Ubiquiti CCTV camera installed in the garage. I will be adding a few more sensors to this as I've ordered some more of the PIR sensors and the door/window sensors, but for now, it's certainly enough to get started. I will also be adding smart detections from the external CCTV cameras with zones set to the garden, driveway etc... When any of those sensors trigger, the condition checks to see if the alarm is armed and if it is, it triggers the alarm.
Once the alarm is triggered, it goes to the pending state. If you've had an alarm before, this is the point when you come through the door and the alarm panel is beeping at you but all of the alarms haven't gone off yet. At this point I configured a 60 second delay above to get my phone out, open the app, punch in the code and disarm the alarm. During that time though, I'd like to know that the alarm is armed and expects me to disarm it, but I have no alarm panel on the wall beeping at me... :)
- alias: Alarm - Pending
trigger:
- platform: state
entity_id: alarm_control_panel.home_alarm
from: armed_away
to: pending
action:
- delay: 00:00:05
- service: notify.mobile_app_serenity
data:
message: Alarm Pending - Motion Detected!
- service: notify.mobile_app_nicolas_iphone
data:
message: Alarm Pending - Motion Detected!
- service: notify.alexa_media
data_template:
message: Alarm pending, please turn it off!
data:
type: tts
target:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:04
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: clock_01
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:01
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: clock_01
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:01
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: clock_01
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:01
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: clock_01
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
id: cf28e7c217e0485596cffc8260be2745
This automation detects when the alarm has changed into the pending state and sends a notification to our mobile devices telling us the alarm is armed and needs to be disarmed, because maybe I forgot I turned it on or someone else turned it on. After this it fires a voice notification to all of the Echo Dot devices around the house to say "Alarm pending, please turn it off!" and then starts playing a clock ticking sound, just to put the pressure on you to move faster! Either you succeed and disarm the alarm, or, if your hands were too full of shopping and your phone was still in the car (or you're actually a burglar), the alarm triggers.
- alias: Alarm - Triggered
trigger:
- platform: state
entity_id: alarm_control_panel.home_alarm
to: triggered
action:
- service: notify.mobile_app_serenity
data:
message: Alarm Triggered - Motion Detected!
- service: notify.mobile_app_nicolas_iphone
data:
message: Alarm Triggered - Motion Detected!
- service: notify.alexa_media
data_template:
message: Alarm Triggered, Police Notified!
data:
type: tts
target:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:04
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: amzn_sfx_scifi_alarm_04
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:04
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: amzn_sfx_scifi_alarm_04
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
- delay: 00:00:04
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: amzn_sfx_scifi_alarm_04
entity_id:
- media_player.echo_arthur_s_room
- media_player.echo_bedroom
- media_player.scott_s_echo_dot_2
- media_player.echo_kitchen
- media_player.echo_living_room
- media_player.echo_office
id: f781b2a0a6c245c98daccfa1641879d1
If the alarm triggers the first thing that happens is another notification to our mobile devices to tell us the alarm wasn't disarmed in time and the alarm is now triggered. After this, another voice notification is played through all of our speakers, "Alarm Triggered, Police Notified!". The police aren't actually notified, at least not yet, but I figured if you were breaking into my house then I may as well say something scary! After this, all of the speakers start playing a rather annoying alarm sound which isn't loud enough to be heard outside, but it will certainly let someone in the house know that the alarm is going off.
One thing I'm yet to add to this, but I am working on, is a scene for all of the lights throughout the house. We have smart lights all over the inside and outside of our house and some kind of strobe effect for the white lights and red/blue flashing combination for the colour lights would certainly draw some attention!
The final state is then disarmed and we just have a simple notification here so that if someone triggers the alarm by accident then we know it's been disarmed when we get the notification and everything is fine.
- alias: Alarm - Disarmed
trigger:
- platform: state
entity_id: alarm_control_panel.home_alarm
to: disarmed
action:
- service: notify.mobile_app_serenity
data:
message: Alarm Disarmed
- service: notify.mobile_app_nicolas_iphone
data:
message: Alarm Disarmed
id: 118afb36f63a4d8390330c3cf9593d91
Further ideas
Looking at the notifications on my phone further up, we can see there was one for needing to check our post box and one for the tumble dryer being finished. The post box is a Xiaomi Aqara Vibration Sensor that sends a notification when it gets hit and is triggered when a letter drops in the post box and hits it. This could be handy to attach to a door or window to detect vibrations perhaps, maybe it could also be attached to something that a thief might move and take with them. Again, they're cheap to come by and the batteries inside them last years.
The tumble dryer notification comes from a Shelly smart relay that does power monitoring and previously from a TP-Link Kasa smart plug. The Shelly relays are really cheap and easy to configure and you can trigger alerts based on anything you like.
One thought for the shelly was if you have motion activated outdoor lights that you detect when they turn on and draw power whilst the alarm is activated and send a notification, which might even be before someone gets close to the house!
Future Upgrades
I'm definitely getting some more of the Aqara door/window sensors for around the house and for things like the downstairs bathroom where it's not really worth having a motion sensor, I will get a window sensor for the window as it's on the ground floor. The smart detections from the Ubiquiti Protect cameras will be integrated soon and then things should be really looking good.
If you have any other ideas for upgrades to the alarm system or other sensors/devices that I could use to improve it, let me know in the comments below!