Narfel
28 February 2018 06:26
13
Thanks Sparky, the script works like a charm. I’m on an rpi0w/dietpi running mosquitto, samba and home assistant. Since 6.2 all of those work flawless. Before i had problems with mosquitto, but that has since been resolved due to a new binary for arm6l.
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:
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.
#!/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"