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:

TODO

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 🙂

Leave a Reply

Your email address will not be published.