Upgrade home assistant from the UI using Docker

One of the downsides of using docker is that we can’t click a button to upgrade the app. I decided to fix this :slight_smile:

I’m documenting this to make sure I don’t forget how I did it, but hopefully it will help others.

The way this works is pretty simple (but I’m not a linux expert, and I’m fairly sure this isn’t a secure way of doing this, so I’m looking forward to suggestions!)

Step 1:
Create a named pipe file that can be edited inside the container. Go to the home assistant config folder on your docker host and create the following file:
mkfifo cmdpipe

Step 2:
Create a shell script to update your home assistance instance. I use docker-compose so mine is different but… create whatever script you need to to update home assistant. Mine looks like this and is called up.sh

cd /mnt/docker/Compose/host
docker-compose pull
docker-compose up -d

Remember to chmod +x it.

Step 3:
Create a script to monitor the pipe file. I know this is super bad practice to pipe this straight into sh… especially since it runs as root, but I don’t know a better way - so if anyone has any better ideas I want to know!

Create the following file /etc/init.d/startup.sh and put the following:

tail -f /docker/homeassistant/cmdpipe | sh

remember to chmod +x it

Step 4:
Get the script to startup with ubuntu

Edit your crontab sudo crontab -e, and add the following:
@reboot /etc/init.d/startup.sh > /var/log/startupscript.log 2>&1

Step 5:
Now we need to modify your configuration in home assistant. Add a shell command to echo the update command into the file pipe we created. This is what mine looks like

shell_command:
  update_ha: "echo '/docker/homeassistant/up.sh' > cmdpipe"

Then restart home assistant. You can now call this shell command, and your docker image should be updated from within home assistant!

Optional Step 6:
I also added a button that appears on my love lace ui when there is an update available:-

card:
  entity: sensor.hass_update_available
  hold_action:
    action: more-info
  icon: 'mdi:alert-decagram'
  icon_height: 50px
  name: Update Home Assistant
  show_icon: true
  show_name: true
  tap_action:
    action: call-service
    service: shell_command.update_ha
  type: button
conditions:
  - entity: binary_sensor.updater
    state: 'on'
type: conditional

I then use this integration: https://www.home-assistant.io/integrations/updater/.

This then gives me a nice button like this that I can click to update home assistant when I’m ready:

image

This is way more complicated than simply using ssh and running 4 commands

1 Like

Alternatively if you run portainer, you click recreate, select download new image and that’s it

lol… dude… all of this is way more complicated than just going to flip a switch :slight_smile: