Hi,
I’m running Home Assistant along with a couple of other services such as Influx, Grafana, Pilight, and MySQL in docker containers. Instead of manually checking for upgrades for these images I’ve created sensors in Home Assistant that pull the latest image versions.
Especially for Home Assistant itself this is more useful to me than the other update notifications since it always takes a couple of days until the docker images are available.
Up until now I used a simple REST sensor that gets all available tags of a certain docker image and grabs the name of the first result which is the newest version.
- platform: rest
name: Home Assistant Latest Version
resource: https://registry.hub.docker.com/v2/repositories/homeassistant/raspberrypi2-homeassistant/tags
scan_interval: 28800
value_template: '{{ value_json.results[0].name }}'
This works for other non-HA images as well. However, sometimes the tag list begins with “latest” which needs to be skipped. Sometimes, the version contains more characters than necessary, e.g. “v.1.2”. By adapting the value template these things can be dealt with.
Now, with the latest release of home assistant and the introduction of beta releases my sensor naturally still showed the latest version which last week were the different beta releases. Since I’m not interested in those, I want to display the latest stable release.
The tag order of my HA image looks like this currently:
0.66.0b3 0.66.0.b2 0.66.0.beta1 0.66.0.beta0 0.65.6
With HA’s beta naming scheme being all over the place I’ve run out of ideas on how to do this with simple value templates.
So I’ve switched from a REST sensor to a command line sensor that curls the address above and then pipes the output through some regex expressions to isolate the latest stable version (0.65.6) in the case above.
Unfortunately, my HA container’s grep utility lacks the ability to execute perl regexes which would have been a more presentable solution. So I had to fall back to slightly different approach:
- platform: command_line
name: Home Assistant Latest Docker
command: curl -s -L https://registry.hub.docker.com/v2/repositories/homeassistant/raspberrypi2-homeassistant/tags/ | grep -Eo '"name":\s"[0-9.]*"' | head -1 | sed -e "s/\"name\":\s\"/${replace}/g" | sed -e "s/\"/${replace}/g"
scan_interval: 28800
What it does is isolate the JSON parts that have the pattern “name”: “” , taking the first result and then extracting the version number by replacing the excess characters with “”. Since the pattern for only includes numbers and dots ([0-9.]*), the beta versions are skipped.
Voila:
Hope this helps other to save some time.
Cheers
Jochen
Sidenote: It would of course be even cooler if homeassistant would recognize how it was installed (pip, docker, …) and only notify of updates when the relevant distribution channel has received the upgrade.