Bash script to update Homeassistant

Hi everyone, first time posting here. I wanted to share a little bash script I made to update my Homessistant installation on Python Venv. Hope it’ll be useful to someone:

Let me know what you think and if you have any suggestions or want to contribute feel free to open an issue on Github!

Hi
perhaps a variable for the homeassistant folder at the top of the file and use that when activating the venv?

I created a new venv last year when I updated from python 3.8 to 3.9 and will likely do the same next weekend when creating a venv for python 3.10. About time to do that, I think Python 3.9 will no longer be supported with 2023.3
Currently the folder on my system is “/srv/homeassistant2”, the new venv will for example be in “/srv/homeassistant310” and I’ll keep both for a while in case I run into issues with 3.10.

To switch between venv I alter the folder in the systemd config file for the homeassistant service

Armin

Thanks for the suggestion, I’ll try to implement it soon, it shouldn’t be too difficult.
Btw I’ve just finished upgrading my Python to 3.10, everything for now seems to work fine.

Davide

ok, cool
I did my test system on a Pi4 8GB last week, compiling Python took a while, but the rest was rather simple, stop old HA, create and activate new venv, install HA, start new HA and wait for the dependencies to be loaded… done. Runs stable so far.

Armin

Hi, I’ve just finished implementing the option to add a custom Homeassistant installation path, the new release is on Github, let me know what you think. I’ve also added an help menu.

Davide

Upgrade to python 3.10 on a RPi was pain in the a**.

Because Python 3.10 doesn’t support FFMpeg 4.
And of course, this is needed if you have cameras in your HA instance.

But I don’t like the warning in HA that tells me that Python 3.9 will no longer be supported in 2023.3.
So, I had to compile and install Python 3.10 then compile and install FFMpeg 5

God I wish Debian will follow more closely the releases of Python and other products.
Or you chose the so called unstable branch

pi@hassbian:~ $ apt-cache madison python3
   python3 |   3.10.6-3 | http://deb.debian.org/debian unstable/main armhf Packages
   python3 |    3.9.2-3 | http://raspbian.raspberrypi.org/raspbian bullseye/main armhf Packages
pi@hassbian:~ $ apt-cache madison ffmpeg
    ffmpeg | 7:5.1.2-1 | http://deb.debian.org/debian unstable/main armhf Packages
    ffmpeg | 7:4.3.5-0+deb11u1+rpt2 | http://archive.raspberrypi.org/debian bullseye/main armhf Packages
    ffmpeg | 7:4.3.5-0+deb11u1 | http://raspbian.raspberrypi.org/raspbian bullseye/main armhf Packages

Hi, just updated my test system to 2012.5.
worked just fine, also when specifying the HA-Folder as parameter

thanks for the script, saving a bit of time because I don’t have to check my notes for the steps or doing stupid things like running pip3 for the upgrade without activating the venv first.

Armin

sorry Davide to hijack your thread for general topics around running HA in a Venv :slight_smile:

Olivier, thanks for lettings us know. Right now I do not have cameras in my setup. I installed Python 3.10 from the source tgz manually, looked around for a 3.10 package in bullseye, found nothing, then took the good old way to “./configure” and “make altinstall”

Armin

I don’t think it is a real hijack.
As it might be an issue with the script.

You see, I did what the script is doing a long time ago, without all prompts and stuffs but with the option to take the --pre (as I’m active on the beta branch).
And as the warning in the first beta of 2022.12 was anoying me, I did the old way ./configure and sudo make altinstall but that completly broke my venv.
The pip3 install --upgrade homeassistant failed miserably

So I think that it could be a nice feature to detect that this is failing and maybe propose to revert with
pip3 install --upgrade homeassistant==<version installed prior to the script>
This wouldn’t have change the result of my poor strategy of never backing-up my stuffs before experimenting but it could save life of others.

Also, a feature in my script, that could be included in this script, is a check of the configuration after the upgrade.
hass --script check_config -c ~homeassistant/.homeassistant/

Not sure about the path, is it always that one or should it be part of the script parameters as well?

When changing the Python version I create a new venv with the new version and do a normal install for homeassistant as described in the installation docs. The config folder remains unchanged and homeassistant pulls and installs all the missing dependencies during the first start, takes a while ( 15-20 minutes if I recall correctly), but I can always switch back to the old venv.
And nothing here in my “smart” home really fully depends on HA, I can still operate heating, lights using alternative ways.

For backup of the config folder I have a local gitea server running and commit changes to the config folder once in a while.

Armin

Don’t worry for the “hijack”, as Olivier said these are nice features that I could add in the future to make a sort of shell utility capable of updating hass with lots of options and checks to make it better, i.e. a feature to rollback, configuration checking and so on.

I’m happy that you have found this small script to be useful, because as you said every new update I had to do the same commands again and again, so I came up with the idea to make this little utility to speed up the process. Thanks again for all the suggestions and the feedback!

Davide

Could be a menu at the start.

  1. Backup current Home Assistant configuration
  2. Upgrade Home Assistant to latest release
  3. Rollback to the previously saved configuration (if any)
  4. Check configuration before restart
  5. Restart Home Assistant
  6. Quit

Please select what you want to do [1-6]:

But then there will be no params. Or it could be an option of the script like -gui
I’m just throwing ideas, don’t feel like you have to do this (or pick things you like)

EDIT: Here are some aliases that I’m using:

alias halog='sudo journalctl -f -u home-assistant@homeassistant'
alias harestart='sudo systemctl restart home-assistant@homeassistant'
alias hashell='sudo su homeassistant'
alias hastart='sudo systemctl start home-assistant@homeassistant'
alias hastatus='netstat -an | grep 8123 | grep LISTEN; sudo systemctl status home-assistant@homeassistant'
alias hastop='sudo systemctl stop home-assistant@homeassistant'

Those were available, long time ago, when hassbian was a thing so I recreated them (yes, I’m very old in Home Asssistant, here since 0.64.0, when lovelace did not exist yet).