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

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

Omg, thank you so much.

1 Like

Can a sensor be made for os agent?

  - platform: github
    access_token: xxxxxx295af35336abeab34ebf81ac31c4
    repositories:
      - path: 'home-assistant/os-agent'

Thanks I did a search in my HA after you posted the the code and I found that I had already setup this sensor. I set this up the same time and the same way that I set up the core sensor. Now I need to remember why I didn’t add it to my system status card? I had an issue getting the current version. On the core I setup a “update sensor”

- platform: command_line
    name: Updater Core
    command: 'curl http://supervisor/core/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version, "update_available":.data.update_available}'''
    value_template: "{% if value_json.update_available %}on{% else %}off{% endif %}"
    json_attributes:
    - update_available
    - newest_version
    - current_version

Tried the same for os-agent and it doesn’t work.

  - platform: command_line
    name: Updater Core
    command: 'curl http://supervisor/os_agent/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version, "update_available":.data.update_available}'''
    value_template: "{% if value_json.update_available %}on{% else %}off{% endif %}"
    json_attributes:
    - update_available
    - newest_version
    - current_version

I assume that I am looking at the wrong place?

I don’t think supervisor has an endpoint for os-agent.

Is there anyway to get this info? The sensor from agent just shows latest. It does not show current.

Using a bash script in cron

#!/bin/bash

# Only edit the following setup lines with correct login information

# Mosquitto Broker Details

mqttuser=***user
mqttpassword=***pass
mqttbroker=**ipaddress
mqttport=**port

# DO NOT ALTER ANYTHING BELOW THIS LINE

versionstring=$(dpkg -l | grep os-agent | tr -s ' ' | cut -d ' ' -f3)

versionstring='{"state":"'"v$versionstring"'"}'
echo $versionstring

# Publish to MQTT Broker

mosquitto_pub -h $mqttbroker -p $mqttport -u "$mqttuser" -P "$mqttpassword" -t haosagentinstalled -m "$versionstring" -r

You need to have mosquitto tools installed.