So I figured I may as well crosspost this while it is fresh. I hope it helps someone.
I haven’t seen much on persistent_notification.create and notify.persistent_notification recently
Persistent notitifcations and Critical Notifications
What are I am talking about?
The service `persistent_notification.create’
- They are not Companion app notifications to IOS or Android
How is it different from The service 'notify.persistent_notification'
`notification_id` cannot be used with 'notify.persistent_notification'
So you can send multiple messages that stack up on your notification panel.
This is true for either service.
Only persistent_notification.create
accepts an ID
Using notication_id ONLY the new message will arrive under that ID
Regardless of how many times it is sent.
Old messages with matching ID will be overwritten
So that’s details out of the way. Now some examples.
Example Message
service: persistent_notification.create
data:
message: There is an update in Os-Agent!
title: Update message
Add some Markdown
Bold <b>My bold text</b> or in the UI **My bold text**
Cursive <i>My cursive text</i>
Link [Link](https://home-assistant.io/)
service: persistent_notification.create
data:
message: <b>There is</b> <i>an update in</i> [Os-Agent!](https://github.com/home-assistant/os-agent)
title: Update message
with Spacing
service: persistent_notification.create
data:
message: >-
**There is** <i> an update in </i>
[Os-Agent!](https://github.com/home-assistant/os-agent)
*My cursive text*
**My bold text**
title: Update message
compact using line breaks
service: persistent_notification.create
data:
message: >-
**There is** <i> an update in </i> [Os-Agent!](https://github.com/home-assistant/os-agent) </br>
*My cursive text* <br></br>
**My bold text**
title: Update message
This is the output of spacing or compact
complex example with variables and sensors.
The sensor
with quote marks
service: persistent_notification.create
data:
notification_id: os-agent
message: >-
OS_Agent {{ states('sensor.os_agent_version_github') }} is
available
[Latest](https://github.com/home-assistant/os-agent/releases/latest)
" wget https://github.com/home-assistant/os-agent/releases/download/{{
states('sensor.os_agent_version_github') }}/os-agent_{{
states('sensor.os_agent_version_github') }}_linux_aarch64.deb "
" sudo dpkg -i os-agent_{{ states('sensor.os_agent_version_github')
}}_linux_aarch64.deb "
title: OS_Agent New Version
Plain and spaced
service: persistent_notification.create
data:
notification_id: os-agent
message: >-
OS_Agent is
available
[Latest](https://github.com/home-assistant/os-agent/releases/latest)
wget https://github.com/home-assistant/os-agent/releases/download/1.4.0/os-agent_1.4.0_linux_aarch64.deb
sudo dpkg -i os-agent_1.4.0_linux_aarch64.deb
title: OS_Agent New Version
Spaced with sensor as variable
service: persistent_notification.create
data:
notification_id: os-agent
message: >-
OS_Agent {{ states('sensor.os_agent_version_github') }} is
available
[Latest](https://github.com/home-assistant/os-agent/releases/latest)
wget https://github.com/home-assistant/os-agent/releases/download/{{
states('sensor.os_agent_version_github') }}/os-agent_{{
states('sensor.os_agent_version_github') }}_linux_aarch64.deb
sudo dpkg -i os-agent_{{ states('sensor.os_agent_version_github')
}}_linux_aarch64.deb
title: OS_Agent New Version
compact with sensor variables
service: persistent_notification.create
data:
notification_id: os-agent
message: >-
OS_Agent {{ states('sensor.os_agent_version_github') }} is
available<br></br>
[Latest](https://github.com/home-assistant/os-agent/releases/latest)<br></br>
wget https://github.com/home-assistant/os-agent/releases/download/{{
states('sensor.os_agent_version_github') }}/os-agent_{{
states('sensor.os_agent_version_github') }}_linux_aarch64.deb<br></br> sudo
dpkg -i os-agent_{{ states('sensor.os_agent_version_github')
}}_linux_aarch64.deb
title: OS_Agent New Version
the result of Plain, Spaced with vars, or compact with variables
Related automations
One Shot notification
This will disappear once you click on it. It will not return until the sensor attribute updates again.
The sensor via github integration
The Automation with variable version number message
alias: Os-Agent Update
description: OS Agent upgrade available
trigger:
- platform: state
entity_id:
- sensor.home_assistant_os_agent_latest_release
attribute: tag ## <<<<<<<<< the attribute
condition:
- condition: template
value_template: >-
{{ trigger.from_state.attributes.tag != "unavailable" and
trigger.from_state.attributes.tag != "unknown" }}
- condition: not
conditions:
- condition: state
entity_id: sensor.home_assistant_os_agent_latest_release
attribute: tag ## <<<<<<<<< the attribute
state: unavailable
- condition: state
entity_id: sensor.home_assistant_os_agent_latest_release
attribute: tag ## <<<<<<<<< the attribute
state: unknown
action:
- service: persistent_notification.create
data:
notification_id: os-agent
title: "There is an update in Os-Agent! "
message: >-
OS_Agent {{ states('sensor.home_assistant_os_agent_latest_tag') }} is
available<br></br> [os-agent
latest](https://github.com/home-assistant/os-agent) <br></br> wget
https://github.com/home-assistant/os-agent/releases/download/{{
states('sensor.home_assistant_os_agent_latest_tag')
}}/os-agent_1.4.0_linux_x86_64.deb<br></br> sudo dpkg -i os-agent_{{
states('sensor.home_assistant_os_agent_latest_tag')
}}_linux_x86_64.deb<br></br>
mode: single
Critical notification
A notification that comes back and bugs you until you complete the task. Mine checks every morning. If the github version is higher the result will be “True” and then a message will be sent.
The else can be removed, I just had it in there for testing. One day I may set it up to be a clickable action or something. I just cut and past it onto my host console. After reading the changes from the link of course…
The top two are rest sensors.
They check the installed home assistant agent version and github agent version.
template:
- sensor:
- name: OS_agent Updater
unique_id: os_agent_updater_version8123
icon: mdi:memory
state: >
"{{ states('sensor.os_agent_version_github' ) > states('sensor.os_agent_version_installed' ) }}"
The Automation with variable HOST archtype and version number message
alias: os_agent version check
description: Check if the installed and released os_agent versions match
trigger:
- platform: sun
event: sunrise
offset: "0:59:00"
enabled: true
- platform: time
at: "10:00:00"
enabled: false
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.os_agent_version
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.os_agent_version_github
- if:
- condition: state
state: "\"True\""
for:
hours: 0
minutes: 0
seconds: 0
entity_id: sensor.os_agent_updater
then:
- service: persistent_notification.create
data:
notification_id: os-agent
message: >-
OS_Agent {{ states('sensor.os_agent_version_github') }} is
available<br></br>
[Latest](https://github.com/home-assistant/os-agent/releases/latest)<br></br>
wget https://github.com/home-assistant/os-agent/releases/download/{{
states('sensor.os_agent_version_github') }}/os-agent_{{
states('sensor.os_agent_version_github')
}}_linux_{{ states('sensor.host_arch')
}}.deb<br></br> sudo dpkg -i os-agent_{{
states('sensor.os_agent_version_github') }}_linux_{{ states('sensor.host_arch')
}}.deb
title: OS_Agent New Version
- service: notify.mobile_app_android_phone
data:
message: OS_Agent {{ states('sensor.os_agent_version_github') }} is available
data:
clickAction: https://github.com/home-assistant/os-agent/releases/latest
else:
- service: persistent_notification.create
data:
notification_id: os-agent
title: OS_Agent was version checked
message: "{{ now().timestamp() | timestamp_custom('%H:%M:%S %D') }}"
mode: single
Enjoy
edit added Host arch variable to last automation msg.
Thanks
Thanks to @Tryfos yet-another-ignore-previous-unavailable-state
Thanks to @Friedrieck 2020 notify-to-persistent-notification