I just wanted to be able to use the persistent notification as an actual notification platform/service, so that it can be used in alerts or in notify groups.
I had seen complex solutions with automations detecting alert events or persistent notifications creations to then call another notification service, but I think I found a more straightforward solution. It simply uses the RESTful notification and the HA REST API:
notify:
- name: persist_it
platform: rest
resource: 'http://localhost:8123/api/services/persistent_notification/create'
method: POST_JSON
headers:
authorization: !secret persist_notif_token #create a long-term token in your profile page and add 'Bearer ' before it in your secrets file
content-type: 'application/json'
message_param_name: message
title_param_name: title
target_param_name: notification_id
You can then call it as another notify service, with the usual title and message parameters, and it will create the desired persistent notification.
Optionally, you can use the target parameter of the notify service to specify a persistent notification_id, if you want to be able to discard it later on with a call to the persistent_notification.dismiss service.
Thank you, this is very useful and exactly what I was looking for.
Just a tip: Donāt forget to add āBearerā in front of the API token in the secrets file
Also, if you are using a certificate, donāt use localhost but the hostname from the certificate and of course you will have to set the port to the correct value.
- name: persist_it
platform: rest
resource: 'http://localhost:8123/api/services/persistent_notification/create'
method: POST_JSON
headers:
authorization: !secret persist_notif_token #create a long-term token in your profile page and add 'Bearer ' before it in your secrets file
content-type: 'application/json'
message_param_name: message
title_param_name: title
target_param_name: notification_id
Iām a bit puzzled by the error at 09:13. Are you sure it always appears when calling that service?
For the other, if you are 100% sure of your token, then maybe try replacing localhost in the URL with the actual IP address of your instance. Same if you use SSL or have changed the port number, etc.
- name: persist_it
platform: rest
resource: "https://XXX.duckdns.org/api/services/persistent_notification/create"
method: POST_JSON
headers:
authorization: !secret persist_notif_token #create a long-term token in your profile page and add 'Bearer ' before it in your secrets file
content-type: "application/json"
message_param_name: message
title_param_name: title
target_param_name: notification_id
I think the first error did indeed not belong there, I think it happens when I update the notify part in home assistant and reload it. I tried calling the service three times and get this:
Are you sure you have created your long-lived token in your account profile? I am asking because my token does not look like the one you posted. In my secret file, it looks like this (truncated): persist_notif_token: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc[ā¦]
You will also see that I have not set any quote around the entry (but I doubt this is the issue).
Otherwise, you may just wait for the change request posted by Diogo above to be released, as this workaround should then soon become obsolete (hopefully!)
I assume you also tried after a full reboot of HA. Indeed, maybe just reloading rest and notifications services does not reload the secret file, for instance.