Home Assistant: Advanced garage door alert
Once again my better half forgot the garage door open for couple of hours, luckily it was not freezing outside so no actual harm was done. So far I’ve only trusted on push notifications that is being sent when the garage door has been open for five minutes, but there’s couple of problems with that:
- Notification hangover: Too many push notifications in the whole Android, so they are not getting the the attention needed
- I’m the only one receiving those notifications so far, so if I’m not near my phone those will be void
So this got me really thinking about more advanced notification system that could reliably inform us if the garage door was indeed left open.
The plan (what the automation does)
- Make an automation that will send repeating notifications every 15 minutes until garage door is closed
- Alert needs to be able to dismiss in case I want to keep the door open on purpose
- I want to see active alert(s) on Home Assistant dashboard
- Set the living room ceiling light red when the garage has been open more than 5 minutes
So that means in order to make this kind of automation two devices are needed:
- Open/close sensor for the garage door
- Supported RBG light(s)
And of course Home Assistant App for the phone.
Home Assistant Alerts
Home Assistant Alerts are a bit less known Home Assistant feature that got few advanced functions that normal notification system does not have:
- It has a state (on, off and idle): it is easy to check if an alert is ongoing
- It can be dismissed: alert is acknowledged without any actions
- It has support to send repeating push notifications
- It has support to send done notification when the alert is handled
The feature set seems to be great for my plan: Make a automation that will send repeating notifications and can be seen directly from Home Assistant dashboard!
One thing about that alerts that I’m kind of against, alerts are observing objects. Meaning that they do follow some other entities and can’t be triggered by automation directly. So for this templated sensor (for complex automations) or a helper entity is required.
Since I’m enabling the whole alerts framework on my Home Assistant instance, I though why not to use it more generic so that I can also add even more alerts for other purposes later on. And for that, I did create a couple of notification groups for different kind of alert levels: Informative, Warning and Critical. All of those can have separate notification channels, but for now on, I’m going with only push notifications for myself:
notify:
- name: STD_Information
platform: group
services:
- service: mobile_app_sm_s906b
- name: STD_Warning
platform: group
services:
- service: mobile_app_sm_s906b
- name: STD_Critical
platform: group
services:
- service: mobile_app_sm_s906b
Oh, and the alerts needs to be enabled by adding a support flag into the configuration yaml:
alert:
Automations
Ok, now that the required components are rather clear it’s time to build the automation!
Every time before actually building the automation(s) a few moments should be spent of thinking all those corner cases. E.g. in my case there a possible scenario that the light is already on when the garage door has notified as open, then the light will turn red. Ok, that’s good, but what if the garage door is then closed? It can not turn off the light, but it has to return to previous state! And luckily for that, we have service called scene.create in Home Assistant to do exactly that.
scene.create will save the current status of an entity into scene that we can restore later on. Restore is done with just activating the scene we just saved.
Ok, enough talk, show me the code:
# The alert itself
alert:
garage_open_warn_alert_active:
name: Garage Open
message: Garage door has been left open!
done_message: Garage is now closed.
entity_id: input_boolean.garage_door_open_alert
state: "on"
repeat: 15 # This will repeat every 15 minutes
can_acknowledge: true
skip_first: false
notifiers:
- STD_Warning # Use the warning notifier (not included in this package)
# Helper triggered by the automation
input_boolean:
garage_door_open_alert:
name: Garage Door Notify
icon: mdi:alert
automation:
# Set helper to true when garage has been open more than 5 minutes
- id: garage_door_left_open
alias: 'Security: Garage Door Left Open'
trigger:
- entity_id: binary_sensor.door_sensor_garage
for: 0:05:00
from: 'off'
platform: state
to: 'on'
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.garage_door_open_alert
mode: single
# Garage door closed, clear the helper
- id: garage_door_closed
alias: 'Security: Garage door closed'
trigger:
- entity_id: binary_sensor.door_sensor_garage
from: 'on'
platform: state
to: 'off'
action:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.garage_door_open_alert
# Alert activated, do the necessary actions: take a snapshot of current light status and set the lights to red
- id: garage_door_alert_on
alias: 'Security: Garage door alert active'
trigger:
- entity_id: alert.garage_open_warn_alert_active
platform: state
to: 'on'
action:
- service: scene.create
data:
scene_id: previous_living_room_ceiling_light
snapshot_entities: light.living_room_ceiling
- service: light.turn_on
target:
entity_id: light.living_room_ceiling
data:
brightness: 255
rgb_color: [255,0,0]
# Alert deactivated, reset the light state to previous
- id: garage_door_alert_off
alias: 'Security: Garage door alert off / dismissed'
trigger:
- entity_id: alert.garage_open_warn_alert_active
platform: state
to: 'off'
- entity_id: alert.garage_open_warn_alert_active
platform: state
to: 'idle'
action:
- scene: scene.previous_living_room_ceiling_light
User Interface for alerts
But how about UI part then? I want to see active alerts on my dashboard and dismiss those when needed!
Well, auto entities -card is the key in here! Auto entities does exactly what the name of the card says: it will display entities automatically with specific conditions/filters in place. E.g. I can automatically display ALL alerts that contains text “alert” in it. Once again, Auto entities can be installed through HACS.
And here’s the UI code that uses card-mod for a bit of colouring and auto-entities to hide/show the alert:
type: vertical-stack
cards:
- type: custom:auto-entities
show_empty: false
card:
type: entities
title: Active Alerts
card_mod:
style: |
ha-card {
background-color: rgba(232, 222, 211,1);
border-radius: 5px;
--card-mod-icon-color: red;
--primary-color: white;
--paper-item-icon-color: white;
--secondary-text-color: gray;
}
filter:
include:
- entity_id: /^alert(.).*/
options:
secondary_info: last-changed
exclude:
- state: idle
sort:
method: last_changed
reverse: true
Conclusion
Everything works as intended for the simulated environment, but (fortunately) the real test has still to come if and when the garage door is left open next time 🙂
Hi,
Is this a work in progress? I could use these alerts 🙂
But the code shows: TODO
Hah, good catch!
I’ve somehow managed to destroy that part of the post while I editing this post a bit.. I’ll put the code back in a bit, so just a sec 🙂
..and it’s back. Thanks again for pointing that out!