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

Please @Anwen , can you share your card?

Thanks you.

Sure, here you go! This is the markdown card - not sure if you wanted the button card piece too, if so, let me know. Please note that Iā€™m no Markdown expert, still learning, so maybe this isnā€™t the best or most efficient way to do things, but it works for me :grin:

- type: markdown
  content: |
    <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 }} |
    | **Audio**         | {{ states.sensor.updater_audio.attributes.current_version }} | {{ states.sensor.updater_audio.attributes.newest_version }} |
    | **CLI**           | {{ states.sensor.updater_cli.attributes.current_version }} | {{ states.sensor.updater_cli.attributes.newest_version }} |
    | **DNS**           | {{ states.sensor.updater_dns.attributes.current_version }} |  {{ states.sensor.updater_dns.attributes.newest_version }} |
    | **Multicast**     | {{ states.sensor.updater_multicast.attributes.current_version }} |  {{ states.sensor.updater_multicast.attributes.newest_version }} |

edited 2020-05-31: With the change to HACS that came with HA 0.110, the names got an underscore added. So this line

 >    **{{ repo.display_name }}** _{{ repo["installed version"] }}_ -> _{{ repo["available version"] }}_

becomes

 >    **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_
3 Likes

Thanks !, I really like it, and how do you show the three buttons with the versions you have at the beginning?

The card with the three buttons uses the custom button card (https://github.com/custom-cards/button-card), and is in a vertical stack with the markdown card. I am just using the HA version sensor (https://www.home-assistant.io/integrations/version/) instead of what @CentralCommand did above, because I made those buttons a long time ago. The first two are really just for display purposes; if you click them they just show the more-info dialog.

The button for the Remote UI toggles the Remote UI for HA Cloud on and off, with a lock so I donā€™t toggle it by mistake. I made a template switch to do this:

platform: template
switches:
  cloud_connected:
    value_template: "{{ is_state('binary_sensor.remote_ui', 'on') }}"
    turn_on:
      service: cloud.remote_connect
    turn_off:
      service: cloud.remote_disconnect

In ui-lovelace.yaml I have the following to set a template for font-size for the button card:

button_card_templates:
  smaller_text:
    styles:
      name:
        - font-size: 14px
      state:
        - font-size: 14px

In my Lovelace view, the code for the horizontal stack of three button cards is:

    - type: horizontal-stack
      cards:
        - type: "custom:button-card"
          template: smaller_text
          entity: sensor.installed_version
          icon: mdi:home-assistant
          color: "#42a5f5"
          size: 25%
          show_state: true
          tap_action:
            action: more-info
        - type: "custom:button-card"
          template: smaller_text
          icon: mdi:home-assistant
          color: "#42a5f5"
          size: 25%
          show_state: true
          entity: sensor.latest_available_version
          tap_action:
            action: more-info
        - type: "custom:button-card"
          template: smaller_text
          show_state: true
          entity:  binary_sensor.remote_ui
          lock:
            enabled: true
          size: 25%
          tap_action:
            action: call-service
            service: switch.toggle
            service_data: 
              entity_id: switch.cloud_connected
          state:
            - value: 'on'
              icon: mdi:cloud-check
              color: "#42a5f5"
            - value: 'off'
              icon: mdi:cloud-alert
              color: "#b8b8b8"

Hope that helps. Have fun!

Thank you very much for your help.

1 Like

Hereā€™s my version copied from @Anwenā€™s useful markdown card.

I use HA Core on docker so I needed a docker updates jinja script

I have version monitors setup for the local system dockers and the github releases and named them the same so sensor.github_XXX_version and sensor.docker_XXX_version then use the docker variable in my jinja script to pass the names and loop it through.

{% macro version_remove(text) %}
    {{- text | regex_replace(find='^[v]', replace='', ignorecase=False) | regex_replace(find='\s', replace='', ignorecase=False) }}
{% endmacro %}
{% macro sentence_case(text) %}
    {{- text[0]|upper}}{{text[1:] -}}
{% endmacro %}
{%- set dockers = {"containers": ["adguardhome", "adminer", "alertmanager", "cadvisor", "dozzle", "grafana", "node_exporter", "nodered", "nzbget", "prometheus", "radarr", "sonarr", "tautulli", "unifi_poller", "mosquittomqtt", "airconnect"]} -%}
{%- for container in dockers.containers -%}
  {%- set current = 'sensor.docker_'+container+'_version' -%}
  {%- set latest = 'sensor.github_'+container+'_version' -%}
  {%- if version_remove(states(current)) != version_remove(states(latest)) and states(latest) != "" %}
  >    **{{sentence_case(container)}}** _{{ states(current)|regex_replace(find='^[v]', replace='', ignorecase=False) }}_ -> _{{states(latest)|regex_replace(find='^[v]', replace='', ignorecase=False)}}_
  {%- endif -%}
{% endfor %}

Hope it helps someone out!

Before anyone asks how I get the versions its all here.

4 Likes

Quick question - are HACS notifications broken? Iā€™ve got the code from https://hacs.xyz/docs/basic/automation#updates-pending

but notifications are incomplete:

image

1 Like

Ah right, thanks for the reminder, this needs an update.

In 1.0 the fields were changed inside sensor.hacs. previously for each repo with an update the fields for installed and available version were installed version and available version with a space. Now the fields are installed_version and available_version with an underscore as of 1.0.

It was in the release notes here. Looks like you found a bug with the hacs docs, that probably needs an update to account for the field name change.

[EDIT] Actually no, I just looked at it and it was updated to account for the new field change, thatā€™s not the issue here. Also I had the field names wrong, fixed them. Not really sure whatā€™s going on for you, I donā€™t use that guide myself but it all looks correctā€¦

1 Like

Iā€™m having the same exact issue.

I missed it in the release notes - thanks.

And it was too subtle a change in the docs! missed it there too.

1 Like

Ah I see, you had the code running already and weā€™re trying to figure out what changed so you knew how to update it. And yea it was pretty subtle.

For the record I updated my Node RED flows in the 2nd post above to account for this change for anyone using those. People who previously imported will probably find it easier to make the changes manually then re-import. If you search for ā€œinstalled versionā€ then it will highlight the one node that refers to those fields (its the use component node that calls the ā€œnotify meā€ component off the HACS update flow). That was the only place those fields were referenced.

I got it all working but i canā€™t get the markdown card working tried all sorts and just get errors

I just updated the my post above for the markdown card to reflect a change in HACS that came with HA 0.110.x, if that helps anyone.

Thanks for the update!, also I have problems with addons section for 0.112.3 version, despite having new uptdates for addons the count is always 0.

I am using @CentralCommandā€™s update package with a couple of small changes relevant to my environment, and everything seems to be working great apart from the alerts.

I have checked and re-checked the code and I canā€™t see anything wrong with it, but it isnā€™t working.

Both sensor.hacs and binary_sensor.updater_hacs are active with an update but none of the notifiers sent the message.

binary_sensor_updater_hacs
sensor_hacs

  # HACS repos have updates available - unacknowledgeable, auto-dismiss, me only
  hacs_update_available:
    name: HACS repos have updates
    entity_id: binary_sensor.updater_hacs
    state: 'on'
    can_acknowledge: true
    repeat: 360
    title: "Updates available in {{ states('sensor.hacs') }} HACS repo{% if states('sensor.hacs') | int > 1 %}s{% endif %}"
    message: ""
    notifiers:
      - notify.telegram
      - notify.notify
      - notify.html5
    data:
      tag: 'hacs-update-available'
      url: 'https://**my url**/hacs/installed

I checked the sensor template and the alert title template and they are both working

sensor template
message template

Any help would be gratefully received

In alerts the notifiers canā€™t have the domain in front.:slight_smile:

Simply remove the notify. in front of your notifiers:

notifiers:
  - telegram
  - notify
  - html5

Hey @paddy0174, Thank you, that got it.

I knew it would be something simple

Thanks again :smiley:

I wanted a notification for core updates:

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

Yea I got tired of waiting for binary_sensor.updater to update and made one of those too, itā€™s actually in the original post under the last collapse:

Iā€™m a little confused by yours though. It looks like youā€™re setting the value of the sensor to value_json.data but youā€™re processing the response like this

jq '{"newest_version":.data.version_latest,"current_version":.data.version}'

So it looks like you arenā€™t actually telling jq to add a data field. Am I missing something or is your sensor always false right now?

If you look at mine above you can just copy the value_template and drop it in. I know Iā€™ve been using mine for a while without issue.

I somehow missed that - it wouldā€™ve saved me the time I spent getting it to work :face_with_hand_over_mouth:

Am I missing something or is your sensor always false right now?

I donā€™t know why, but it works. I got a notification today when 0.114.0b4 was released :man_shrugging:
Either way, good work! I love these.