Get notified when Home Assistant has errors/can't start up

Is there a way to get a notification (email, pushbullet, node red, anything really) for the notifications in the frontend? More specifically, my postgres setup had an issue, and so the recorder component couldn’t start. HA had a notification about this in the frontend, but it took me days to notice, because often I don’t look at it. Can I configure Home Assistant to get critical warnings like that through some notification channel? Alternatively it seems that it would have been enough to look at the home assistant log, is there a way to get access to that through, say, node red? I could probably build an alarm that way.

You can have an automation act on the notification entity. I do this for invalid log-ins.

You would have to either still have the notification or create a false one to get the entity ID to watch.

You can set up a custom card that will set a card in the frontend to display the notifications.

the card is the “home feed” card - https://github.com/gadgetchnnel/lovelace-home-feed-card

Here is the config I use that only shows the card on a notification:

  - type: 'custom:home-feed-card'
    title: Notifications
    show_empty: false

That’s it. It just works after that.

There are more things you can do with it but right now that’s all I use it for.

Thanks all for the comments. Adding it to the frontend isn’t actually going to help me, because I mostly automated my home, so I rarely open Home Assistent directly. However, with the hint fron silvrr, I figured out that you can listen in NodeRed to events that (regex) match the entity_id persistent_notification\..*. With this, I can forward the notifications to my favorite notification channel.

is this still working for you? Would you mind sharing the details how you accomplished this? I’m in the same boat as you - I don’t look at the HA interface that often and want critical alerts sooner than later.

Yes, this is still working for me, I just tested it by creating a persistent notification through the developer page and the service that allows the creation of such notifications. In node red I use the Home Assistent node called “events: all”, and send that to a function node, where I filter the events, and turn them into something I can send over Pushover to my phone. This is what my code looks like:


if ('event_type' in msg &&
    msg.event_type == 'state_changed' &&
    'entity_id' in msg.payload &&
    msg.payload.entity_id.startsWith('persistent_notification.')) {
    // this is a persistent notification
} else {
    // something else, ignore
    return null;
}

let title = 'Home Assistant Notification';

let message = '';

message += 'entity_id = ' + msg.payload.entity_id;

let data = msg.payload.event;
if (data && 'new_state' in data && 'attributes' in data.new_state) {
    message += '\n' + 'title = ' + data.new_state.attributes.title;
    message += '\n' + 'message = ' + data.new_state.attributes.message;
} else {
    message += '\n' + 'full data = ' + JSON.stringify(msg, undefined, 2);
}

return {
    topic: title,
    payload: message,
};

Hope this helps :slight_smile:

1 Like

This is perfect! Appreciate you taking the effort to share. I’ll give it a go when I’m back home.

@stefanheule I was able to get this working but made a few tweaks that (I think) simplified things. Sharing here to add to the knowledge pool. I referenced this post where they were picking up the persistent notifications via automations.yaml.

I’m using the all events node and filtering out to only call_service events. From there I am using a function as you suggested to filter, but it’s a bit more brief. An then lastly using a call service node to call notify and send me a notification. I’m referencing the message object to populate the notify data to pass on the title and message.

function code:

if (msg.payload.event.domain == 'persistent_notification' &&
    msg.payload.event.service == 'create')
    // this is a persistent notification
    {
    return msg.payload;
} else {
    // ignore
    return null;
}

and the data within notify service node:

{
    "title": "Persistant: {{event.service_data.title}}",
    "message": "{{event.service_data.message}}"
}
1 Like

For those that don’t want the additional overhead of NodeRed, a simple “Push all Persistent Notifications to PushOver or Pushbullet” can be accomplished using native HA automation as follows:

- id: 'persistent_notifications_push'
  alias: HA Persistent Notifications to Pushover
  description: ''
  trigger:
  - event_data:
      domain: persistent_notification
      service: create
    event_type: call_service
    platform: event
  condition: []
  action:
  - data_template:
      data:
        priority: 0
        sound: pianobar
      message: '{{trigger.event.data.service_data.message}}'
      title: 'Persistent: {{trigger.event.data.service_data.title}}'
    service: notify.pushover_notifier

Important to remember to use data_template: rather than data: in the action, so that the trigger variables can be referenced. Guidance here: https://www.home-assistant.io/docs/automation/templating/

4 Likes

Thanks a lot for this, I found the node.red code online but needed the YAML. Appreciate it! Have it working with Discord

Both methods are working smoothly when the persistent notifications appear during a normal HA cycle, but I’m more interested in the ones that show right after HA is restarted, both the Automation and the Node-Red script are missing them.

1 Like