Autostart
Warning
This is a fast moving field. This information will be out of date in some detail even before you read it.
OK it needs to autostart and I want it to be easy to start, stop and restart
it too.
My procedure to start things up at this point was was:
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
source bin/activate
hass
When I typed this in line by line this just worked. If I ran it as a script I
end up back at the /home/pi folder and it didn't start up. Annoyingly the
instructions on how to do this are a bad link...
Then I found it at: https://home-assistant.io/docs/autostart/systemd/
which send me off to understand services.
So I made a systemd template:
/etc/systemd/system/home-assistant@homeassistant.service
This tells the systemd process to go to folder the
/home/homeassistant/.homeassistant and run /srv/homeassistant/bin/hass as a
service so it will just run in background and we will control it through the
web interface.
[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"
[Install]
WantedBy=multi-user.target
You need to reload systemd to make the daemon aware of the new configuration.
sudo systemctl --system daemon-reload
To have Home Assistant start automatically at boot, enable the service.
sudo systemctl enable home-assistant@homeassistant
To disable the automatic start, use this command.
sudo systemctl disable home-assistant@homeassistant
From now on, provided it is enabled, if the pi starts then hass starts.
To manually start Home Assistant now, use the command:
sudo systemctl start home-assistant@homeassistant
There are 'stop' and 'restart' versions too. The 'restart' is useful when you
write a configuration file that blows it all away and you want a second chance
to test the edits (or run the restored backup) without rebooting the Pi.
I tested the start, ran the enable and rebooted it.
Its web interface was there within 10 to 15 seconds.
It's obviously tea time again.

by Nigel Hewitt