Update Home Assistant Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
wodian

Update Home Assistant

Post by wodian »

Hi all,

Short question. How do I manually update Home Assistant to the newest version?

Kind Regards,
Wodian
wodian

Re: Update Home Assistant

Post by wodian »

For anyone else who wants to upgrade:
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

wodian wrote:For anyone else who wants to upgrade:
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant
Very useful, thanks. One question, why do you need the 'sudo su -s' if you are logged in as root?
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

wodian wrote: source /srv/homeassistant/bin/activate
Unfortunately this does not work as 'activate' does not exist in that directory.

Any suggestions on how to activate the virtualenv?
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

So I have managed it but not really sure what all these commands actually do to achieve that!

First login as the 'homeassistant' user

Code: Select all

sudo su -s /bin/bash homeassistant
Next navigate to the homeassistant folder

Code: Select all

cd /srv/homeassistant/
Execute this command - found in the homeassistant-start.sh file used by systemctl. Not too sure what this does!

Code: Select all

export PATH="/home/homeassistant/.pyenv/bin:$PATH"; eval "$(pyenv init -)"; eval "$(pyenv virtualenv-init -)"
You should see a prompt like this indicating you are in the virtual environment.

Code: Select all

(homeassistant-3.6.3) homeassistant@
Execute the pip3 command to update homeassistant.

Code: Select all

pip3 install --upgrade homeassistant
Exit out of the su session

Code: Select all

Exit
Restart the homeassistant service

Code: Select all

systemctl restart home-assistant
I think this homeassistant-start.sh might be specific to DietPi and if so perhaps I could suggest a specific upgrade script?

HTH
sytone
Posts: 6
Joined: Wed Jul 19, 2017 4:05 am

Re: Update Home Assistant

Post by sytone »

Here you go, there will be a homeassistant-update.sh in that directoy at some point, have not had time to get to it. Put this in a updatehs.sh file and run it.

Code: Select all

#!/bin/bash

HA_USER="homeassistant"
HA_USERROOT="/home/$HA_USER"
HA_SRVROOT="/srv/homeassistant"
HA_PYENV_ACTIVATION="export PATH=\"$HA_USERROOT/.pyenv/bin:\$PATH\"; export PYENV_VIRTUALENV_DISABLE_PROMPT=1; eval \"\$(pyenv init -)\"; eval \"\$(pyenv virtualenv-init -)\""
HA_PYTHON_VERSION="3.6.3"

echo "Stopping HA..."
systemctl stop home-assistant.service

echo "Updating HA"
su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv activate homeassistant-$HA_PYTHON_VERSION; pip3 install --upgrade homeassistant" $HA_USER

echo "Starting HA..."
systemctl start home-assistant.service

echo "Checking to see if up (Localhost must be in http trusted_networks)"
start=$(date '+%s')

until curl --silent --show-error --connect-timeout 1 -X GET -H "Content-Type: application/json" -k https://127.0.0.1:8123/api/ | grep -q 'API running'; do
    date '+[%Y-%m-%d %H:%M:%S] --- Home Assistant is starting, please wait...'
    systemctl status home-assistant.service
    sleep 10
done

dur=$(($(date '+%s') - start))

echo -e "\e[00;32mHome Assistant is ready! ($dur second delay)\e[00m"
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

Looks good, thanks. I'll give it a go next time I need to update :)
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

sytone wrote:Here you go, there will be a homeassistant-update.sh in that directoy at some point, ....
Just tried this and it stalled at the first hurdle, stopping the service (I get the message "stopping HA.." then nothing). Tried the command from the command line and it worked OK.

So I just followed my other instructions and updated successfully.
Sparky
Posts: 2
Joined: Sat Jan 20, 2018 2:38 am

Re: Update Home Assistant

Post by Sparky »

Using systemctl with HomeAssistant that was installed with the DietPi menu system requires referencing the service as:
home-assistant
So:
systemctl stop home-assistant.service
will not work. This works:
systemctl stop home-assistant

Same story for systemctl start, restart & status.
I modified your code below with fixes, I can't currently test it since I'm running hass.io. When mosquitto, samba and home assistant installs are fixed for rpi0w, I will go back to dietpi.
sytone wrote:Here you go, there will be a homeassistant-update.sh in that directoy at some point, have not had time to get to it. Put this in a updatehs.sh file and run it.

Code: Select all

#!/bin/bash

HA_USER="homeassistant"
HA_USERROOT="/home/$HA_USER"
HA_SRVROOT="/srv/homeassistant"
HA_PYENV_ACTIVATION="export PATH=\"$HA_USERROOT/.pyenv/bin:\$PATH\"; export PYENV_VIRTUALENV_DISABLE_PROMPT=1; eval \"\$(pyenv init -)\"; eval \"\$(pyenv virtualenv-init -)\""
HA_PYTHON_VERSION="3.6.3"

echo "Stopping HA..."
systemctl stop home-assistant

echo "Updating HA"
su --shell /bin/bash --command "cd $HA_SRVROOT; $HA_PYENV_ACTIVATION; pyenv activate homeassistant-$HA_PYTHON_VERSION; pip3 install --upgrade homeassistant" $HA_USER

echo "Starting HA..."
systemctl start home-assistant

echo "Checking to see if up (Localhost must be in http trusted_networks)"
start=$(date '+%s')

until curl --silent --show-error --connect-timeout 1 -X GET -H "Content-Type: application/json" -k https://127.0.0.1:8123/api/ | grep -q 'API running'; do
    date '+[%Y-%m-%d %H:%M:%S] --- Home Assistant is starting, please wait...'
    systemctl status home-assistant
    sleep 10
done

dur=$(($(date '+%s') - start))

echo -e "\e[00;32mHome Assistant is ready! ($dur second delay)\e[00m"
Sparky
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Update Home Assistant

Post by baz123 »

Sparky wrote:Using systemctl with HomeAssistant that was installed with the DietPi menu system requires referencing the service as:
home-assistant
So:
systemctl stop home-assistant.service
will not work. This works:
systemctl stop home-assistant

Same story for systemctl start, restart & status.
I modified your code below with fixes, I can't currently test it since I'm running hass.io. When mosquitto, samba and home assistant installs are fixed for rpi0w, I will go back to dietpi.
Ok, thanks. v160 is due soon and I'll test it then.

I'm also running an instance of Hass.io but in a docker installed in DietPi on a VM!
Post Reply