Alert2 - a new alerting component

Hi @redstone99 - love all the continuing work. Alert2 really has been a huge deal for me especially with a lot of the changes you got in!

I have probably over a thousand alerts now at this point with generators, and I’ve been doing a good degree of tuning to try to get false positives out. However, I did miss an alert yesterday that mattered. As such, I wanted to be able to create various tiles with different displays, and also better separate off alerts from on. I have been using a version of the UI with the ability to select which states to hide (e.g. acked_on, acked_off, disabled, etc.), which priorities to show, change colors of icons (including separating off from low colors), and hide a few UI elements if you need (slider and ack bar) to make those tiles smaller.

Happy to now be a contributer!

EDIT2: One thing I did not change but would recommend is making the default low priority on color different than the off color to visually tell on alerts from off. I suggest grey for off and blue (theme) for low, that’s how I have the custom config set right now for me and it works well to differentiate.

1 Like

man you are truly awesome

1 Like

@Rudd-O - thanks!

@tman98 - You’re suggesting a config option to specify the color for condition alerts that are off, and that option would override the priority color. Is that right? Seems reasonable to me.

Yes - I actually provided for that configurability in a PR I submitted (and apologies my message didn’t actually mention that I actually had submitted a PR with the functionality described :man_facepalming:). I’ll try to work on the tests for it as you requested but I just can’t get to those for a while so wanted you to see the code. My EDIT2 was just saying I suggest we make the default “off” a different color than “on low”, which is not in my PR (but the configurability to override is)

Yes. I think the former, latter, or both of those options would work. The former involves less copy paste by using conditionals in the templates. The latter makes everything super clear and doesn’t require using logic / templates. Six of one, half dozen of the other.

Hi All,
I just released v1.13 of Alert2.

Changes

  • Allow fields of “data” parameter to take templates. Templates can access a parameter, “notify_reason”.
  • Stop producing “unavailable” logbook entries for alerts when HA restarts
  • Detect and throw error if generator requests creation of duplicate domain/name pairs
  • Update docs & tests

@DavidValeri - let me know how the new data field functionality works for you.

@tman98 (or others), In Issue 16, the idea arose of adding an option to make alerts continue to send reminder notifications until acked, even if the alert is no longer firing. I thought you may have desired something similar in the past. Any thoughts?

-Josh

1 Like

It works. Thank you. Here is an example in action.

data:
        channel: "{% if notify_reason != 'StopFiring' %}'Sump Pump - Water Depth Below Floor - Alert'{% else %}'Sump Pump - Water Depth Below Floor - OK'{% endif %}"
        ttl: 0
        priority: high
        timeout: "{% if notify_reason != 'StopFiring' %} 86400 {% else %} 60 {% endif %}"
        sticky: "{% if notify_reason != 'StopFiring' %} 'true' {% else %} 'false' {% endif %}"
        importance": max
        tag: sump_pump_water_depth_below_floor
        clickAction: dashboard-it/compressor-closet
        actions:
          - action: "ALERT2_SNOOZE_1h_sump_pump_water_depth_below_floor"
            title: "Snooze"

One bug in the docs. The text refers to reason and not to notify_reason. See hass-alert2/README.md at 64e5381bf02e28f83975756955187a8cb90d2c16 · redstone99/hass-alert2 · GitHub

One enhancement request. To a n00b like me, it was not immediately clear how to use the templates to set a boolean value. It seems one does it just like when returning a string. An example using this data type in the docs might be helpful as well.

Two questions about how to implement desirable behaviors using the existing functionality.

  1. To implement snooze, as shown in the snippet in my last post, I wrote an automation that looks for mobile app events where trigger.event.data.action starts with ALERT2_SNOOZE_1h. It then triggers the alert2.notification_control action to snooze the alert with the name matching the rest of trigger.event.data.action after the prefix and then clears the alert on the mobile devices. I can add the ability for the automation to take the snooze duration from trigger.event.data.action as well and to pull the alert ID from another field like tag, but before I go further down this road, I wanted to ask if I am approaching the problem correctly. Is this what I should be doing to snooze an alert from a mobile notification action?

  2. Is it possible to control the list of actions based on notification_reason? Could I have actions in the notification if notify_reason is not StopFiring but include them for the other values of notify_reason? I included a snippet of a more complex scenario involving an open garage door with a Close action that is hidden if the door is moving or is now closed. That’s beyond what can be done, and likely is more complex than Alert2 should try to handle, but I could still imagine that hiding some or all actions on a resolved alert would make sense since some of them may no longer be relevant or would be undesirable to accidentally trigger once the situation is resolved.

(
  ...

  $getActions := function() {(
    $actions := [];
    $actions := $append(
      $actions,
      payload.moving = false and payload.notifying = true ? 
        {
          "action": "CLOSE_DAT_SHIT",
          "title": "Close"
        }
        :
        []);
    $actions;
  )};

  {
     "message":
       payload.displayName 
         & (topic = "OPEN" ?
           " left open since "
             & $formatDate(payload.opened)
             & " ("
             & $toMMSSFromNow(payload.opened)
             & ")."
           : " closed at "
             & $formatDate(payload.lastChanged)),
     "title": "Door Ajar",
     "data": {
       ...
       "tag": payload.id,
       "progress": payload.notifying = false ? 100 : (payload.moving ? 1 : -1),
       "progress_max": 100,
       "progress_indeterminate": payload.moving,
       "alert_once": payload.moving,
       "actions": $getActions()
     }
  }
)

Thanks for the typo notice. I fixed it and updated the docs. Yes, you can specify booleans and action lists in the data fields. I added examples to the doc - here’s the relevant yaml example:

alert2:
  alerts:
    - domain: cam_basement
      name: motion_while_away
      condition: ...
      notifier: mobile_app_pixel_8
      data:
        group: motion-alarms
        # Integer data field
        timeout: "{% if notify_reason == 'Fire' %} 600 {% else %} 20 {% endif %}"
        # String data field
        channel: "{% if notify_reason == 'Fire' %} 'channel-a' {% else %} 'channel-b' {% endif %}"
        # Boolean data field
        sticky: "{% if notify_reason == 'Fire' %} True {% else %} False {% endif %}"
        # Array of dict data field
        actions: "{% if notify_reason=='Fire' %} [{ 'action': 'foo', 'title': 'bar' }] {% else %} [] {% endif %}",

So boolean is done with capitals and no quotes. The “true” you specified becomes the string “true”.

I’m not super familiar with building actionable notifications in the companion app. Reading the companion app doc, it looks like there’s no way to pass extra fields back in the event resulting from an action, so yeah, I guess you have to parse out the entity id from the trigger.event.data.action.

-Josh

1 Like

I took a look at the trace since I had an alert fire today and I do think the event has access to all of the fields in data. So I could pull the alert ID from tag, since I match those up. The only variable for the snooze action is the duration so I can parse that out of trigger.event.data.action. Below is is a chunk of the variables from the automation trace.

trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: event
  event:
    event_type: mobile_app_notification_action
    data:
      timeout: '86400'
      sticky: 'true'
      tag: sump_pump_water_depth_below_floor
      title: Sump Pump - Water Depth Below Floor
      webhook_id: ...
      channel: Sump Pump - Water Depth Below Floor - Alert
      clickAction: dashboard-it/compressor-closet
      message: Water depth below the floor, 1.46 ft., is outside the safe range.
      action_1_title: Snooze
      action_1_key: ALERT2_SNOOZE_1h_sump_pump_water_depth_below_floor
      server_id: '3'
      action: ALERT2_SNOOZE_1h_sump_pump_water_depth_below_floor
      device_id: ...
    origin: REMOTE
    time_fired: '2025-06-27T17:50:08.800431+00:00'
    context:
      id: ...
      parent_id: null
      user_id: ...
  description: event 'mobile_app_notification_action'

If you’re not telling me I am missing something that makes snoozing an alert from the companion app notification more simple, I will keep going down this route with a separate automation to handle snooze. This use case might also be a good example to include in the documentation, unless I missed it.

Thank you.

@lesf - thanks for giving Alert2 a try!

Looks like you found a bug. Can you tell me what you were doing with that alert when you got deletion error? Like how else had you tried to delete it?

Also, I’d like to make the experience of Alert2 a little less overwhelming for new users. Any suggestions?

@DavidValeri - yeah, it looks like the way to trigger an action from the companion app is by triggering based on the event generated.

-Josh

I ended up restoring from a backup from the night before. I’ll play around this weekend and see if I can do it again. If so will post a new message (I had deleted this msg after restoring from backup).

I have not given up and am still using your alert2, things are slowly getting there. Don’t get me wrong it is awesome! The amount of options are just a bit much when one is just starting out with Home Assistant (am moving off an old Vera automation unit).

Suggestions, hmm how about giving examples starting with simple things.

  1. Door open, popup notification, then build upon that…
  2. Alert only if not home (variable already set giving mode of system…home, away, etc)
  3. Group all external doors into this alert
  4. Add notification to companion app on phone

Or even do a multi-step instruction with motion detectors.

Les

Hi All,
Two things. First, I’m considering a breaking change that would change the state of an event alert that has never fired from the empty string “” → “never fired”. It appears that some parts of HA make assumptions that entities won’t use the empty string as a state. If you don’t use event alerts or don’t have code that examines the state of the event alert entity, this wouldn’t affect you. Thoughts?

Second, I created a new doc, Alert2 Recipes, to be a perhaps more manageable and example-driven way to get familiar with Alert2. It’s pretty bare-bones at the moment, but let me know if you have suggestions of things to add.

@lesf, I included some simple versions of some of the examples you listed. There’s room for more examples.

-Josh

2 Likes

Sorry for the delay, been traveling a bunch. I don’t have a need personally for alerts to fire notifications if unacked but also no longer firing.

I’m going to try to get testing going for the PR I submitted as I think that PR has some features requested by others as well. It’ll likely take me a week or two again due to traveling, but is there any info to look at to help see how to get an Alert2 test environment running for running the UI tests?

I added testing instructions to the READMEs of Alert2 and Alert2-UI. Let me know if they need improving. I think I also posted a few thoughts in your PR discussion thread. Thanks for adding some tests!
J

I really appreciate you putting the effort into this. Documentation is not always fun. I’ll start trying out some of your recipes.

I’m quite new to HA and tackling this is my first shall we say big task.

alert2 solves the main reason I was still hanging on to my Vera / MiCasa Verde box.
Les

1 Like

Hi All,
I just released v1.14 of Alert2 and the UI.

Breaking Change

  • The state of an event alert that has never fired has changed from the empty string (“”) to “has never fired”.

Changes

  • You can now snooze without ack’ing. notification_control now takes an extra argument, ack_at_snooze_start that defaults to true. The UI is updated to allow you to adjust it.
  • A default dictionary can now be set for the data config field. If data is also set in an alert definition, it will override the default dictionary on a key-by-key basis. Similarly, any data default set via the UI will override data keys set in YAML.
  • The report() service call now allows an extra data argument
  • Fix a JS error that sometimes appears in the browser console.

@woodersayer - I think you requested some of these a long time ago.

@lesf - Let me know how it goes and if you have suggestions for other examples to add to Recipes.

-Josh

I’ve just started playing around with this integration (and alerts and notifications in general). What I’d like to do is have different configurations for the notifiers configured in the alert. eg. I want to send a critical notification via the mobile app and specify different messages to each of the alert notifiers. Any ideas on how to accomplish that?

Hi @chris28, Thanks for trying out Alert2. At present, I think you need to create separate alerts. Can you give me a concrete example of your use case? Is it mainly that you want to be able to associate a default notifier with different priority levels - Eg, if you declare an alert of priority “medium”, then it automatically uses a certain notifier? And give me an example of the different messages you have in mind.
-J

Hey @redstone99, I thought I might have to set up different alerts. Creating separate alerts isn’t a big deal though I was hoping that I wouldn’t have to duplicate the set up. Oh well.

What I want to be able to do is issue an alert when my garage door obstruction sensor detects a problem (it has a tendancy to get knocked off alignment from kids) and I’d like to send a critical notification to my phone and to send a TTS message to the speakers in my house only if the house is “Active” (this I can do with templating). The notification message to my phone just needs to be a short “The obstruction sensor is off” sorta thing and the speakers one is more detailed to let the rest of the house know that something is off on the door. I was sorta hoping there was some way that the notifier list accepted a nested hash with some additional configuration. Kinda like:

notifier: 
  - mobile_app_chris_iphone
    message: "This is a message specifically for this notifier"
  - whole_home_announcements
    message: "This is a different message for this notifier"

Thanks

Chris