Get notified any time there is a new Home Assistant alert

My Home Assistant

I accidentally broke Home Assistant updating to docker 20.10 on my supervised install. That would’ve never occurred had I seen the a Home Assistant alert about 3 days earlier. So I decided to keep that from happening again by setting up HA to alert me any time a new HA alert pops up. And since we now have blueprints, seemed like a great opportunity to try them out.

:warning: Additional Dependency

In order to make this blueprint work you also must set up feedreader to watch the HA alerts feed, the events this integration fires are what triggers the automation. To do that, add the following to your configuration.yaml:

feedreader:
    urls:
    - https://alerts.home-assistant.io/feed.xml

This will check the feed once an hour by default, you can adjust the scan_interval if you prefer a quicker response time. Restart after, then you can use this blueprint.

Notes

There’s a few features missing that I hope get added in the future to make this easier to use:

  1. There’s currently no way to make a service selector to let users pick a service of type notify so you’ll have to type in the notifier name. I know a lot of other blueprints ask users to select a device of type mobile_app but I want to create a persistent notification by default. Plus I want to use this blueprint and I don’t use mobile app notifications
  2. The Additional Data option is really scrappy, you have to enter the data in JSON format in the box. I hope a dictionary type selector is added in the future so this can become YAML entry.

Blueprint

blueprint:
  name: Send Notification for Home Assistant Alert
  description: Send notification on your preferred channel when there is a new Home Assistant alert published
  domain: automation
  input:
    notifier:
      name: Notifier
      description: 'Name of integration you prefer to use for notifications (i.e. what comes after `notify.` in the service call). Defaults to `persistent_notification`'
      default: persistent_notification
    title:
      name: Notification title
      description: 'Title of notification when there is an alert. Defaults to "New Home Assistant alert"'
      default: New Home Assistant alert
    urls_supported:
      name: URLs are supported
      description: 'True if your notification platform supports clicking the notification to open a URL, false to just include the alert URL in the message body'
      selector:
        boolean:
      default: false
    additional_data:
      name: Additional data for notification
      description: 'Additional data to include in service call if your notification platform has extended functionality. Will need to write as a JSON object (ex. `{"badge":"https://alerts.home-assistant.io/images/favicon.png", "priority":"high"}`)'
      default: "{}"
    feed_url:
      name: Feed URL
      description: 'Used for testing automation by setting to a custom URL so you can create fake HA alerts and see it in action. Leave blank otherwise so it defaults to the normal HA alert feed'
      default: 'https://alerts.home-assistant.io/feed.xml'

mode: parallel

variables:
  notifier: !input notifier
  urls_supported: !input urls_supported
  additional_data: !input additional_data

trigger:
  platform: event
  event_type: feedreader
  event_data:
    feed_url: !input feed_url

action:
- service: "notify.{{ notifier }}"
  data:
    title: !input title
    message: "{{ trigger.event.data.title + ('' if urls_supported else '\n' + trigger.event.data.link) }}"
    data: "{% set data = additional_data | from_json %}{% if urls_supported %}{{ dict(data, url=trigger.event.data.link) }}{% else %}{{ data }}{% endif %}"
7 Likes

Many thanks for sharing this! I’ve experienced the same thing and boy did I feel stupid when I saw the alert. Especially since I broke a lot more trying to get home assistant back up again.

FYI, had to update the blueprint. The template I was using for setting additional data in the notify service call was getting butchered on import and no longer outputting a dictionary correctly. I fixed it and tested it and its working correctly now.

Hooray, it worked! Got the HomematicIP alert. I had tested it with a local clone of the feed a bunch but this is the first actual alert lol

Dunno how many people are using this but for anyone wondering why they never got a notification for Security Disclosure 2, its because the feed entry for the first Security Disclosure was updated without changing the date fields instead of a new one being posted. Feedreader looks at these fields and so it didn’t pick up the change to the entry.

I created an issue about it. Hopefully the HA team will change this pattern when it comes to updates to existing alerts otherwise not entirely sure what can be done here.

4 Likes

Yep. Not using the blueprint but same problem. Thanks for creating the issue.

I tried to use this blueprint and I also integrated feedreader before doing so. Unfortunately manually triggering the automation does not work, HA log shows:

Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'trigger' is undefined
and
Error while executing automation automation.notify_system_new_home_assistant_alert: Error rendering data template: UndefinedError: 'trigger' is undefined

feedreader-Settings:

feedreader:
  urls:
    - https://alerts.home-assistant.io/feed.xml
  scan_interval:
    hours: 6
  max_entries: 10

Won´t feeds be pulled initially after added to yaml and HA has been restarted? Or would it take 6 hours?

It doesn’t really work like that. On startup the feedreader integration builds a cache of the rss feed as it exists then. Then it polls that feed and any time a new event appears it creates an event of type feedreader. The automation this blueprint makes listens for those events and notifies you when it gets them.

So it really doesn’t do anything on startup or when manually triggered. It only does something when a new alert appears in the rss feed it is watching.

If you want to test it, that’s why I put in that feed_url input. You can clone the alerts RSS feed somewhere (like the www folder of your HA config for example) and then have feedreader and this blueprint watch your cloned feed there. Then you can add a fake alert to the list and see that it sends you a notification.

Well that´s strange. There was a new alert (with URL https://alerts.home-assistant.io/#rituals_perfume_genie.markdown) recently (has been removed meanwhile) - which triggered my blueprint based automation (March 4th 06:17) - but it seems like the blueprint can´t handle my notification group (group of devices) cause I did receive nothing:

That’s not good. I use notification groups for everything too so I don’t think its a problem with all groups, must be something with one of the integrations behind the one you use? Notification groups actually just make a service call to with identical data to every notifier in the group.

Is there any errors in your log that might give a hint about it doesn’t like? Or if you don’t mind sharing what integration(s) you do use for notifications I can take a look at what that particular notification service lists as allowed inputs and see if I can piece together what happened.

Well I use the Home Assistant Companion App, sometimes for a single device, sometimes for a group of devices. E. g. notify.my_smartphone or notify.all_devices.

Unfortunately I don´t have logs anymore (HA Core has been restarted meanwhile, don´t know if and where former logs are stored, running HASS OS). Did not dive into the local xml thing yet otherwise I could recreate the situation. Do you have an example XML where I just need to add the timestamp so a new feed element gets detected and the automation triggers?

Actually the easiest way to get an example URL is to just go to the current URL - https://alerts.home-assistant.io/feed.xml. It’s actually just an XML file at that endpoint so you can download it, store it somewhere locally that HA can access and then tweak away to test scenarios.

Although bear in mind this issue is still open so changing the timestamp or data of an existing entry won’t trigger a feedreader event and an alert. Adding a new one to the top should though.

[EDIT] Oh wait right, changing the timestamp of an existing entry may trigger an alert, I’m not sure. The issue with changing a timestamp is its not a realistic recreation of what alerts.homeassistant.io actually does. Currently the alerts site does not change the timestamps of entries when it updates them, it just updates the data.

Well… today when my RSS feed reader told me bout yesterday´s Alerts – Home Assistant I checked my automation and - it did not fire. No trace available, last trigger 11 weeks ago (when I was testing and firing it manually for sure).

What´s wrong with it? Any remote diagnose result? :wink:

alias: Notify_System_New Home Assistant Alert
description: >-
  See
  https://community.home-assistant.io/t/get-notified-any-time-there-is-a-new-home-assistant-alert/256924/6
use_blueprint:
  path: >-
    CentralCommand/get-notified-any-time-there-is-a-new-home-assistant-alert.yaml
  input:
    feed_url: https://alerts.home-assistant.io/feed.xml
    title: '🆘 Warning: New Home Assistant Alert'
    urls_supported: true
    additional_data: '{}'
    notifier: persistent_notification

Huh, that’s strange. So just to clarify, yesterday’s actually is the first one that should’ve fired in that 11 week timeframe. The only other one in that window was the Simplisafe one but that one wouldn’t have fired because it was an update to an existing alert rather then a new alert. See this post above for info on why updates on problematic and the linked github issue (which is still open).

I was not able to find any way around that issue so I switched to scraping and parsing the XML in Node RED at some point rather then using this blueprint. I’d like to go back to it but I want to get the alerts about updates to existing items as well and it appears that can’t be done with an automation currently.

All that being said, I don’t really know why it wouldn’t still be working for new alert items. Nothing has changed about the feedreader integration in like 9 months and the feed is clearly still there. Just to check, your feedreader config is pointed to the actual alerts feed and not to the feed you were using for testing right? Looks right other then that and can’t imagine why you wouldn’t at least get a trace.

One thing you could do is all events are recorded in the DB. You could use the pgAdmin add-on to take a look and make sure there was actual an event fired by feedreader and it looks correct. That’ll tell us if its feedreader or the automation at elast.

As recently two new HA alerts were published I took the chance to monitor what´s going on (why I don´t receive notifications?!?):


(21st and 23rd of September)

So what happened according to automation trace log?

  1. Good news: it was triggered in both cases.
  2. Here´s what went wrong in both (all) cases:
Logger: homeassistant.components.automation.notify_system_neuer_home_assistant_alert
Source: components/automation/__init__.py:505
Integration: Automatisierung (documentation, issues)
First occurred: 21. September 2021, 08:37:40 (2 occurrences)
Last logged: 23. September 2021, 14:37:40

Error while executing automation automation.notify_system_neuer_home_assistant_alert: extra keys not allowed @ data['data']

I think this data inside data is not accepted by the notification service, is it?

Reminder: I wanted to (and still want to / will) use a notify service (notify.all_devices which contains mobile devices with HA Companion app), not the default persistent notification.
BUT: currently I completely use it as delivered with “persistent_notification”:

For now I just removed the {} but I´m quite sure that will fix nothing.

Any idea @CentralCommand?

You have to uncheck “urls are supported”. The persistent notification service does not support clicking the notification to open a url. Since you have that selected it’s making a data field and adding the url inside it.

Thx I‘ll give it a try.

It still does NOT work. Making me crazy meanwhile. Automation gets triggered but NEVER EVER a persistent notification is created!

This is my blueprint config:

id: XXXXXXXXXXXXX'
alias: Notify_System_Neuer Home Assistant Alert
description: >-
  Siehe
  https://community.home-assistant.io/t/get-notified-any-time-there-is-a-new-home-assistant-alert/256924/6
use_blueprint:
  path: >-
    CentralCommand/get-notified-any-time-there-is-a-new-home-assistant-alert.yaml
  input:
    feed_url: https://alerts.home-assistant.io/feed.xml
    title: '🆘 Warnung: Neuer Home Assistant-Alert'
    urls_supported: false
    notifier: persistent_notification
    additional_data: '{}'

Please note: Removing the {} is not possible. Once removed and the automation is being saved and reloaded, those {} are back automatically.

**What´s wrong with it? @CentralCommand ** Meanwhile I think this blueprint simply doesn´t work. It´s been almost 9 months and it did not work once.

I got a notification today. But I turned the blueprint into a normal automation.

image

I´m so desperate I´d like to test this as well. Can you share your automation config (maybe via PM)?