Yep, I know that pain. I really like alerts but the combination of these two features creates some serious challenges.
I’m guessing you also want to send your notifications to your phone and create them as persistent notifications and discovered data
isn’t allowed for persistent notifications? I actually have a solution to that if you’re interested. What I do is I have a bunch of notification groups like this:
- name: 'home'
platform: group
services: []
- name: 'mike'
platform: group
services: []
Notice that services
is completely empty. These do literally nothing by default but they are valid targets in alerts (and anywhere else that accepts a notification service). Critically they also don’t validate the service data so you can have anything you want in data
.
Those services may do nothing by default but they still fire a call_service
event just like any other service. So you can then make an automation which listens for those events and maps parts of the data to different services like so:
automation:
- id: fdbb59354977476e9f80b6099ed2a5aa_notify_to_script
alias: Notify to script
description: When specific notification groups are called translate their service data into a send_notification call
mode: parallel
max: 50
trace:
stored_traces: 15
trigger:
- id: home
platform: event
event_type: call_service
event_data:
domain: notify
service: home
- id: mike
platform: event
event_type: call_service
event_data:
domain: notify
service: mike
action:
- service: notify.mobile_app_mikes_phone
data:
title: "{{ trigger.event.data.service_data.title }}"
message: "{{ trigger.event.data.service_data.message }}"
data: "{{ trigger.event.data.service_data.data }}"
- condition: "{{ trigger.id == 'home' }}"
- service: persistent_notification.create
data:
title: "{{ trigger.event.data.service_data.title }}"
message: "{{ trigger.event.data.service_data.message }}"
notification_id: "{{ trigger.event.data.service_data.data.tag }}"
I realize in this example notify.mike
looks kind of silly since its basically the same thing as notify.mobile_app_mikes_phone
. In my actual automation mike
sends to both my android phone and my mac after normalizing the fields that are different for ios vs. android. Which I can share but its a lot more complicated so I didn’t want to distract more on here, figured this conveyed the idea well enough.
EDIT: If you’re trying to dismiss the notification when the alert is over you can do that too. Just set done_message
to clear_notification
. And then in this automation add a choose
which calls persistent_notification.create
or persistent_notification.dismiss
based on the message.