Alert / Android App Notification - Auto Dismiss

So I had a Well No S**t Sherlock moment today with the Alert integration and Android App Notifications. You can get them to auto-dismiss (and I’m not talking about the timeout parameter).

To clear an android notification you send the clear_notification message to the mobile_app target.

    - service: notify.mobile_app_myphone
      data:
        message: clear_notification
        data:
          tag: some_alert

Well it turns out you can use clear_notification in the done_message: parameter of an alert, and the notification will clear when the alert turns off!

alert:
  some_alert:
    title: Test Alert
    message: "This an alert."
    done_message: clear_notification
    entity_id: binary_sensor.some_alert

I was just able to delete about 40 some odd dismiss notification automations! I used to use Push and I think I just transferred the notifications to the Android app notifications without stepping back and thinking about it. This was probably obvious to most of you geniuses but thought I’d point this out for anybody else who may of had a d’oh! moment with this one.

2 Likes

@jazzyisj thanks for that information. I would have one thing to add :wink:
for those who didn’t read the documentation: It’s important to add a tag otherwise you will just receive a “clear_notification” message :smiley:

so in that case the example should look something like:

alert:
  some_alert:
    title: Test Alert
    message: "This an alert."
    data:
      tag: some_alert
    done_message: clear_notification
    entity_id: binary_sensor.some_alert

took me a while to figure that out :slight_smile:

Unfortunately, as of Home Assistant 2021.5.4, clearing notifications from alerts does not seem work on iOS.

Hi! Thanks for sharing this wonderful feature!
Do you know what happens when you have one of more notifiers?

Example of my situation in alerts.yaml:

garage_open_alert:
  name: Garage Open Alert
  entity_id: binary_sensor.garage_closed
  state: 'off'
  repeat:
    - 5
    - 15
  message: 'Warning: the garage is open!'
  done_message: 'Garage is closed'
  skip_first: true
  notifiers:
    - voice_assistants
    - mobile_app

When the alert turn off, I’d like to clear notification on the mobile APP and to send a message to my Voice Assistant.

Using your suggestion done_message: clear_notification how could I send a done notification to other notifier?

Create a separate automation to play the voice assistant message triggered by binary_sensor.garage_closed turning off.

It took me ages to find the right combination of done_message, data tag structure, and mobile_app_* notifier format to get alerts working for mobile apps. I opened a PR to document this, feedback / additional contributions welcome: Update alert.markdown with companion app examples by danepowell · Pull Request #28753 · home-assistant/home-assistant.io · GitHub