Sensor for latest docker image versions

Can you post the code for this? Including the sensors?

This lovelace card with standard sensors.
Sensors:

sensor:

  - platform: template
    sensors:
      ha_startup_time:
        value_template: >-
          {{ as_timestamp((states.automation.startup_notification.attributes|default).last_triggered|default(None))|timestamp_local or 'unknown' }}

  - platform: version
    beta: false
    source: docker
    name: ha_version_docker_stable

  - platform: version
    name: ha_version
    source: local
    beta: false

  - platform: version
    name: ha_pypi_version
    source: pypi
    beta: false

  - platform: rest
    name: ha_github_version
    resource: 'https://api.github.com/repos/home-assistant/home-assistant/releases/latest'
    headers:
      accept: application/vnd.github.v3+json
      content-type: application/json
      user-agent: home-assistant/rest-sensor
    value_template: >-
      {{ value_json.tag_name if value_json.tag_name.split('.')|length != 2 else value_json.tag_name ~ '.0' }}
    scan_interval: 1800

card:

- type: vertical-stack
    cards:
      - type: entities
        title: Home-Assistant
        show_header_toggle: false
        entities:
          - sensor.ha_startup_time
          - sensor.ha_version
          - sensor.ha_github_version
          - sensor.ha_pypi_version
          - sensor.ha_version_docker_stable
2 Likes

Do you know what the secret is to getting version info from “Official” repositories?

This is the one I am trying to get updated info for; I could try to pull from this page but I like to keep all my sensors similar. I have seven others that work great but there is something about this one that gets me.

https://hub.docker.com/_/eclipse-mosquitto

Sorry, dont use this anymore. Update the containers with portainer now.

I was thinking about this today.
I use a docker container called DIUN (Docker Image Update Notifier) - https://github.com/crazy-max/diun
This monitors your docker containers and looks for updated images on a regular basis. It can send notifications and, having checked today, it can also sent notifications to MQTT or WebHook, which means it could be used to trigger HASS.
Watchtower could well do this as well, but doesn’t have MQTT or Webhook - I’ve raised a new feature request on their GitHub for this.

3 Likes

I ended up going a different route on this.
I have a cronjob script run to download the newest image (just download), since docker will only download if there is an updated version of whatever tag you are using.
Then I compare the number of docker images with the number of containers. If there are more images then containers then I have a container to update. This works for me based on my setup; I have all my containers restart (this works for all except MaryTTS sometimes for some reason). I don’t have containers that don’t run (most of the time).
I am debating, since I think I am stable at the number of containers I run, just grep the name of images and if the count is more than one then that one is in need of updating.
Doing it this way has the benefit of not having to wait on a container to download when I find an update is available.

That being said, I will look into Diun.

If you used docker-compose it would do all that for you…

I didn’t like certain aspects of docker-compose; I found it difficult to manage images independently and still have them interact on the same docker network. I’m sure if I play with it long enough I could get it to work, but my way works for me (currently).

Then you were doing it wrong lol.

I don’t disagree.

Can I ask how you use your labels, I always had an issue with the exclusion label having problems with double quoting.

Hi,

I have the same need.
(tracking down my Docker containers to get notified when updates are available)
and I ended up with my own solution: What’s up Docker?

It integrates seamlessly with Home-assistant using Mqtt Discovery.

I run it at home for some time and now some other Home-assistant addicts seem to enjoy it as well :slight_smile:.

Here is the topic around the tool.

You can give it a try if you wish.
And feel free to ask for support or raise issues on Github if needed!

7 Likes

Hi All,

i didin’t know why, but i’ve the error above to the definition of the sensor template.

AssertionError: Tried to resolve a name to a reference that was unknown to the frame ('result')

Did anyone have this error in the last HA version?

Thanks

Has anyone integrated diun with home assistant via mqtt?

No, but What’s Up Docker integrates easily!

Thanks, but It doesn’t work on kubernetes. I use home assistant deployed on k3s.

I did try integrating DIUN with HASS once. You can do it either via sending a webhook to HASS, or by using MQTT.
It worked, but I found it annoying that I had to setup individual entities for each and every container individually to achieve what I wanted.

Thanks @DerekO . Do you have an example of how did you integrate using MQTT?

Just include this in your docker-compose (or equivalent in docker run) and edit accordingly:

      - WUD_TRIGGER_MQTT_MOSQUITTO_URL=mqtt://mqtt.lan:1883
      - WUD_TRIGGER_MQTT_MOSQUITTO_HASS_ENABLED=true

This will start posting to MQTT, by default under /wud/container/docker. Each container will have it’s own topic underneath that

Then you need to setup MQTT sensors in HASS.

The reason I didn’t like it was because each container is in it’s own topic, which means you need to create a HASS MQTT sensor for each individually. I did see that there was a Github project somewhere to do this for you, but it looks like it doesn’t work anymore.

Thanks, where I fail is with defining MQTT sensors in HASS, I receive the message but can’t integrate it.

These are my env variables, messages are sent and I can see them in mqtt queue, but not in homeassistant sensor.

      env:
        - name: TZ
          value: "Europe/Paris"
        - name: LOG_LEVEL
          value: "info"
        - name: LOG_JSON
          value: "false"
        - name: DIUN_WATCH_WORKERS
          value: "20"
        - name: DIUN_WATCH_SCHEDULE
          value: "0 */6 * * *"
        - name: DIUN_PROVIDERS_KUBERNETES
          value: "true"
        - name: DIUN_PROVIDERS_KUBERNETES_WATCHBYDEFAULT
          value: "true"
        - name: DIUN_NOTIF_MQTT_SCHEME
          value: "mqtt"
        - name: DIUN_NOTIF_MQTT_HOST
          value: "192.168.0.2"
        - name: DIUN_NOTIF_MQTT_PORT
          value: "1883"
        - name: DIUN_NOTIF_MQTT_USERNAME
          value: "user"
        - name: DIUN_NOTIF_MQTT_PASSWORD
          value: "password"
        - name: DIUN_NOTIF_MQTT_CLIENT
          value: "diun"
        - name: DIUN_NOTIF_MQTT_TOPIC
          value: "homeassistant/diun"
        - name: DIUN_NOTIF_MQTT_QOS
          value: "0"