Update notifications! Core, HACS, Supervisor and Addons (now a blueprint!)

Hello, it’s possibile to add an auto-dismiss of the update available notification?

As add-on are autoupdating, and when upgrading core HASS will be restarted so the issue is not present, i still have the problem with HACS, that after i have started all the upgrades sometime i forgot to dismiss the notification, so i’ll come back after few hours and i still have the old update available notification.

Another good thing that i love to have is the upgrade to version x.xx complete notification, is there any service that can help me in that?

This is actually pretty easy as it turns out. One of the options in the alert integration is done_message. This is the message that gets sent to the notifier when the alert was on and is now off because its alerting condition has become false. In your case that would mean an upgrade was available and now it is complete.

So in your alerts just set the done_message to something like so:

done_message: "Upgrade to version {{ state_attr('<ID of the matching upgrade sensor for this alert', 'newest_version') }} complete"

So this one is easy if you use mobile notifications although it kind of rules out your ability to do the “upgrade complete” notification because it uses the same field. When you send a notification with the message clear_notification then it dismisses any existing notifications with the same tag (see here for info on notification commands like this). So to get an alert which creates a mobile notification and then automatically dismisses it when the condition becomes false you can simply do this:

alert:
  my_alert:
    name: My example alert
    entity_id: binary_sensor.problem_found
    state: 'on'
    title: "There's a problem!"
    message: "It's bad, go check it out!"
    done_message: 'clear_notification'
    notifier: my_ios_or_android_phone
    repeat: 30
    data:
      tag: REQUIRED_FIELD

With this when the alert turns on it will create a mobile notification with the tag REQUIRED_FIELD and that message. But then when the alert turns back off it will send the message clear_notification to the same tag, causing the mobile app to auto-dismiss this notification it created.

This trick works with any alert, including the upgrade notification ones shown here. It does however require that you use the mobile app for notifications. If you use some other notification service then you’ll need to look up if that service supports dismissing notifications and how/if you can leverage it from an alert.

Now I’m going to take a stab in the dark here and say that what you actually want here is not auto-dismiss but rather you want the “Upgrade complete” notification to replace the “Update available” notification once it is done. In that case, we use the first technique but now add a tag so the new notification replaces the old one. So your alert looks like this:

alert:
  my_alert:
    name: My example alert
    entity_id: binary_sensor.problem_found
    state: 'on'
    title: "There's a problem!"
    message: "It's bad, go check it out!"
    done_message: 'The problem has been resolved!'
    notifier: my_ios_or_android_phone
    repeat: 30
    data:
      tag: REQUIRED_FIELD

What will happen here is each notification created by this alert will replace the previous notification on your phone/mac/ipad/etc. since they all have the same tag. So when the problem is resolved the “It’s bad, go theck it out!” notification becomes the “The problem has been resolved!” notification, you never see both.

Again though this technique only works if you use the mobile app. If you have a different notifier you’ll have to see if/how it supports notification replacement.

1 Like

Hello,

what is the size of your image /local/homeassistant/homeassistant.png in pixel please?

my result is like this :
Sans titre

1200x630 px

1 Like

After the update, everyone has this problem:

  • sensor.home_assistant_operating_system_version
    image
  • sensor.home_assistant_operating_system_newest_version
    image

Yes.

Screenshot 2021-09-14 at 23-04-26 Administration - Home Assistant

Looks like someone forgot to update the status page:

Screenshot 2021-09-14 at 23-06-17 https version home-assistant io

1 Like

@CentralCommand I have a basic syntax issue here.

How to handle ' which are part of the command in the command_line sensor definition? (also in HA Terminal addon first)

I need to run this command on a foreign SSH host:

pihole -v | head -1 | grep -oP '(?<=\is v)(\d*\.)+(\d*)'

As you can see it already contains ' twice for the RegEx definition. I already tried few combinations in Terminal addon prior to defining the sensor but I can´t make it syntactially work.

You got an idea? What´s a working escape sequence for this?

Update 1: on SSH/Terminal addon using " around the actual command works
(ssh username@IP -i /config/.ssh/id_rsa -o UserKnownHostsFile=/config/.ssh/known_hosts "pihole -v | head -1 | grep -oP '(?<=\is v)(\d*\.)+(\d*)'") but not in the sensor definition, YAML seems to be a bit special here…

Update 2: I believe some part of the actual RegEx (some characters are probably used as escape sequence by YAML/HA) is the problem. No idea how to work around this though…

Yea if your command has both single and double quotes in it then you have to escape one of them. What I usually do is wrap the command in single quotes and then escape the single quotes inside, you do this by using a double single quote (''). There’s actually an example of this in the package at the top, here’s the command line sensor for the new addons one:

# Sensor to track details on new addons
- platform: command_line
  name: New addons
  command: 'curl http://supervisor/addons -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" 2> /dev/null | jq --slurpfile slugs /config/common/found_addon_slugs.txt ''{"addons":[.data.addons[] | select(.slug as $slug | $slugs | index($slug) | not)], "repositories":.data.repositories}'''
  scan_interval: 900
  unit_of_measurement: new release(s)
  value_template: "{{ value_json.addons | length }}"
  json_attributes:
    - addons
    - repositories
    - addon_slugs

Notice the command has both single and double quotes in it so the single quotes are escaped inside.

The problem seems to be the RegEx part. As soon as I have at least one \ in the command_line sensor command, Visual Studio Code complains unknown escape sequence :frowning: :frowning: :frowning:

I try to avoid adding even more complexity to this by using an external script (Command Line - Home Assistant)…

Oh I see what you mean. Maybe try replacing all the single backslashes with \\? So that way the first interpreter sees the escape sequence for backslash and then passes on a backslash to the command itself.

1 Like

Simple but probably genius. VSC stopped complaining; I will continue with sensor definition and give it a try. Thanks for the moment!

1 Like

Hi all,

I received a mail from GitHub, stating my “personal access token, HACS , has an outdated format”.
Looking at HACS, I do not see any option in updating the GitHub token in HACS.
Anyone has suggestions?
Thanks.

I am now seeing warnings from the templates created in post 1.
One of them is:

Template variable warning: 'dict object' has no attribute 'installed' when rendering '<ha-icon icon="mdi:home-assistant"></ha-icon>&nbsp;**Add-ons needing update:** &nbsp;&nbsp; {{ states.sensor.supervisor_updates.state }} > {% for addon in states.sensor.supervisor_updates.attributes.addons %} > {{ addon.name }}&nbsp; {{ addon.installed }} -> {{ addon.version }} > {% endfor %} <ha-icon icon="hacs:hacs"></ha-icon>&nbsp;**HACS updates available:** &nbsp;&nbsp; {{ states.sensor.hacs.state }} > {% for repo in states.sensor.hacs.attributes.repositories %} > **{{ repo.display_name }}** _{{ repo["installed version"] }}_ -> _{{ repo["available version"] }}_ > {% endfor %} --- | | Current&nbsp;&nbsp;&nbsp; | Latest | |--- |:---: |:---: | | **Supervisor**&nbsp;&nbsp;&nbsp; | {{ states.sensor.supervisor_updates.attributes.current_version }} | {{ states.sensor.supervisor_updates.attributes.newest_version }} | |

How do I fix this?

Hello and thanks for sharing this!
I’m rather new to HA and never tried packages before.
I’ve put your code in a yaml and linked it in config.yaml, but when I check the config I get “Package update_notification setup failed. Component alert has duplicate key ‘name’”.
Is there any way to fix this?
Thanks!

PS: HA is supervised and up to date.

This error message tells you, that there is the name tag set twice in alert.

You should be able to find that in your package file, otherwise post the content of that file. Obviously there seem to be an error in your package file, as in the first post there is only one name tag under alert. :slight_smile:

Hi, great job is done here, works lke a charm, much apreсiated.
I have a question though: I want to make those update sensors to look similar to standard binary_sensor.updater, which values are nice No updates and Update available, but here it’s just Off and OK.
Can I change those values somehow?

Update: Nevemind, found the solution in offical docs. Just add to those sensors:

device_class: update
2 Likes

Hopefully this grows into an addon itself that can be a one click install into home assistant.
I am just overwhelmed with all the config I have to do and i am afraid I am gonna mess my HA if I mess with this.

2 Likes

Hi, is there an updated version of this that works with the latest version?

When I paste the first part into my config, I get errors:

Because you have to insert this under the sensor domain. Eg.

sensor:
  - platform: command_line
1 Like