So you’ve got door sensors that tell you when a door is opened – the next logical step is to set up an alarm that will notify you if a door opens when you’re out.
I’m replacing SmartThings and that has a feature called Smart Home Monitor. You configure which sensors it uses and then get an alarm if any of them are triggered.
The system can be armed automatically when you go out, based on the presence sensors, and then disarmed when you get home. It can also be armed and disarmed manually.
if you have presence detection working, it’s easy to set up an equivalent system in HomeAssistant.
First of all, it’s worth setting up a group containing the sensors that you’re interested in. For example, I have:
doorsensor: name: Doors entities: - sensor.front_door_access - sensor.back_door_access - sensor.side_door_access
This is useful not just for automation but also for the front end if you want to see at a glance the status of your sensors:
With this in place, you could just set up a simple automation based on the sensors state – in this case sending a Pushover notification:
- alias: 'Trigger alarm' trigger: - platform: state entity_id: group.doorsensor state: 'open' action: - service: notify.pushover data: message: "Door opened" title: "Alarm"
I’ve omitted any presence detection at this point in order to test the basic alarm. In fact, presence alone isn’t the best way to control whether to trigger the notification. What you really want is the manual alarm control panel component.
First of all, enable the component in your configuration:
alarm_control_panel: - platform: manual
This will give you the alarm panel in your front end:
Clicking or tapping on it will give you the option to set it as “arm home” or “arm away”. Once it’s already armed, you’ll get the option to disarm it instead:
This gives you the same alarm options as the Smart Home Monitor, allowing you to distinguish between the alarm being active when you’re out and it being active when you’re home.
You can now use the status of your alarm panel to send an alert when a door opens if the panel is armed. You’ll also want it to trigger the alarm panel, so you get a visual indication in the front end when the alarm is active:
- alias: 'Trigger alarm' trigger: - platform: state entity_id: group.door_sensor to: 'open' condition: condition: or conditions: - condition: state entity_id: alarm_control_panel.ha_alarm state: armed_away - condition: state entity_id: alarm_control_panel.ha_alarm state: armed_home action: - service: alarm_control_panel.alarm_trigger entity_id: alarm_control_panel.ha_alarm - service: notify.pushover data: message: "Door opened" title: "Alarm"
You can then use automations to arm and disarm the alarm panel based on your presence:
- alias: "Gone out" trigger: - platform: state entity_id: group.all_devices from: 'home' to: 'not_home' action: - service: alarm_control_panel.alarm_arm_away entity_id: alarm_control_panel.ha_alarm - alias: "Got home" trigger: - platform: state entity_id: group.all_devices from: 'not_home' to: 'home' action: - service: alarm_control_panel.alarm_disarm entity_id: alarm_control_panel.ha_alarm
The advantage of this approach is that it’s possible to manually arm and disarm the alarm panel, making it more flexible than using notifications based purely on presence. It also gives you a visual indicator in the front end when your alarm has triggered:
So far so good, but notice the message – “Door opened”. Wouldn’t it be better to get a message telling you which door had opened?
In order to do that, you’ll need to revert to using a list of sensors instead of the group so that your automation can tell which of the sensors was triggered. You can then use a data_template in your notification to add the friendly name of the sensor:
- alias: 'Trigger alarm' trigger: - platform: state entity_id: sensor.side_door_access, sensor.front_door_access, sensor.back_door_access to: 'open' condition: condition: or conditions: - condition: state entity_id: alarm_control_panel.ha_alarm state: armed_away - condition: state entity_id: alarm_control_panel.ha_alarm state: armed_home action: - service: alarm_control_panel.alarm_trigger entity_id: alarm_control_panel.ha_alarm - service: notify.pushover data_template: message: '{{ trigger.to_state.attributes.friendly_name }} opened' data: title: 'Alarm'
Assuming your sensors have friendly names like “Back door”, “Front door” and so on, your notification should now look something like this:
To finish off, you can also arm and disarm the alarm overnight. You probably only want this to run if you’re home, otherwise the alarm should be set anyway and you can leave it alone – you certainly don’t want to disarm it in the morning when you’re away:
- alias: 'Arm alarm at night' trigger: platform: time after: "23:00:00" condition: condition: state entity_id: group.all_devices state: home action: service: alarm_control_panel.alarm_arm_home entity_id: alarm_control_panel.ha_alarm - alias: 'Disarm alarm in the morning' trigger: platform: time after: "07:00:00" condition: condition: state entity_id: group.all_devices state: home action: service: alarm_control_panel.alarm_disarm entity_id: alarm_control_panel.ha_alarm
So there you have it – an alarm notification system based around HomeAssistant. You can go further with the automations – perhaps have one of your Hue lights flash red? Maybe sound an alarm that repeats “Intruder Alert” at high volume? The possibilities are endless.
in Home Automation
Got this setup today and it’s working great, thank you
Thanks Keith, glad you found it useful
Nice post – thanks for some inspiration!