How to: Home Assistant | Set Command to Auto Launch HASS on Boot Up

How to Set HASS to Automatically Load on Start UP

Python virtual environment

Autostart using systemd

If you’ve setup Home Assistant in virtualenv following our manual installation guide for Raspberry Pi 753 (or the Python installation guide 344), the following template should work for you. If Home Assistant install is not located at /srv/homeassistant, please modify the ExecStart= line appropriately. YOUR_USER should be replaced by the user account that Home Assistant will run as (e.g homeassistant).

The file will be called /etc/systemd/system/home-assistant@YOUR_USER.service

[Unit] Description=Home Assistant [Service] Type=simple User=%i WorkingDirectory=/home/%i/.homeassistant ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant" [Install]

Next Steps

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@YOUR_USER

To disable the automatic start, use this command.

sudo systemctl disable home-assistant@YOUR_USER

To start Home Assistant now, use this command.

sudo systemctl start home-assistant@YOUR_USER

You can also substitute the start above with stop to stop Home Assistant, restart to restart Home Assistant, and ‘status’ to see a brief status report as seen below.

$ sudo systemctl status home-assistant@YOUR_USER ● home-assistant@fab.service - Home Assistant for YOUR_USER Loaded: loaded (/etc/systemd/system/home-assistant@YOUR_USER.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2016-03-26 12:26:06 CET; 13min ago Main PID: 30422 (hass) CGroup: /system.slice/system-home\x2dassistant.slice/home-assistant@YOUR_USER.service ├─30422 /usr/bin/python3 /usr/bin/hass └─30426 /usr/bin/python3 /usr/bin/hass [...]

To get Home Assistant’s logging output, simple use journalctl.

sudo journalctl -f -u home-assistant@YOUR_USER

Because the log can scroll quite quickly, you can select to view only the error lines:

sudo journalctl -f -u home-assistant@YOUR_USER | grep -i 'error'

When working on Home Assistant, you can easily restart the system and then watch the log output by combining the above commands using &&

sudo systemctl restart home-assistant@a&& sudo journalctl -f -u home-assistant@YOUR_USER

Automatically restarting Home Assistant on failure

If you want to restart the Home Assistant service automatically after a crash, add the following lines to the [Service] section of your unit file:

Restart=on-failure RestartSec=5s