DEV Community


Posted on • Originally published at on

Installing Home Assistant

For quite some time now I’ve been plotting to put a Raspberry Pi 3 model B to work as some kind of home automation/”smart” home thingy. After looking at a few options, I’ve more or less settled on Home Assistant- aka “Hass”. It seems to check all the boxes: open-source, optionally offline, just-works™, and not fugly. An official Android app was also recently announced.

Before getting started, install Raspbian or some other distribution of your choice.


Installing Hass is easy. The top-level install instructions list three ways to do it:

Here we’ll go through the manual route also referencing additional instructions for the Raspberry Pi. If you’re unfamiliar with Python/pip/venv, read “Installing packages using pip and virtual environments”.

# Install pre-requisites
sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev

# Create `homeassistant` user Hass will run as
sudo useradd -rm homeassistant -G dialout,gpio,i2c,audio
cd /srv
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant
# Switch to `homeassistant` user
sudo -u homeassistant -H -s

# Create python virtual environment and switch to it
cd /srv/homeassistant
python3 -m venv .
source bin/activate

# Install Home Assistant in venv and run once to complete setup
venv$ python3 -m pip install wheel
venv$ pip3 install homeassistant
venv$ hass
Enter fullscreen mode Exit fullscreen mode

The first time it runs a bunch of additional packages will be installed. Once the following text appears installation has completed:

INFO (MainThread) [homeassistant.core] Timer:starting
Enter fullscreen mode Exit fullscreen mode

Auto Start

Additional instructions are provided to make Hass start automatically at boot.

As super-user create /etc/systemd/system/home-assistant@YOUR_USER.service (where YOUR_USER is the name of the user you created above, in this case homeassistant):

Description=Home Assistant

ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"
# Restart on failure

Enter fullscreen mode Exit fullscreen mode

For example:

sudo vim /etc/systemd/system/home-assistant@homeassistant.service
## Paste the above configuration then `:wq`

# Reload systemd and enable to start automatically at boot
sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant@homeassistant
# Start it now
sudo systemctl start home-assistant@homeassistant
Enter fullscreen mode Exit fullscreen mode

For help debugging Hass installs:

sudo systemctl status home-assistant@homeassistant
# Stop Home Assistant
sudo systemctl stop home-assistant@homeassistant
# Restart Home Assistant
sudo systemctl restart home-assistant@homeassistant
# View log output
sudo journalctl -f -u home-assistant@homeassistant
Enter fullscreen mode Exit fullscreen mode


My Pi is tucked inside the official 7” Touch Display, and I’d like to have it launch the Hass GUI as a dashboard to serve as a control panel for my entire flat. The two main approaches are:

  • systemd
  • autostart

There’s a few more ideas in this forum thread.


I first tried the solution from this post about starting a dashboard on a Raspberry Pi 4. It didn’t work for me, but I didn’t spend much time debugging it so I plan to come back to it.

As super-user create /etc/systemd/system/dashboard.service:

Description=Chromium Dashboard


Enter fullscreen mode Exit fullscreen mode

Create ~/

#!/usr/bin/env bash

# Prevent putting screen to sleep
xset s noblank
xset s off
xset -dpms

# Hide mouse cursor
unclutter -idle 0.5 -root &

# Ignore "unclean" Chrome shutdowns
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

# Open Home Assistant dashboard
/usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:8123 &

# Make the script executable
chmod +x ~/
# Install helper
sudo apt-get install unclutter
# Enable the service
sudo systemctl enable dashboard.service
# Optionally, view log output
sudo journalctl -f -u dashboard.service
Enter fullscreen mode Exit fullscreen mode


The solution that did work for me was following a sparkfun tutorial covers using autostart to launch a program at startup. Create ~/.config/autostart/dashboard.desktop:

[Desktop Entry]
Enter fullscreen mode Exit fullscreen mode

Here using the same from above.

End Result

The default GUI is servicable:

During Hass initial setup it automatically detected the Philips Hue “smart lighting” in my home. You can turn lights on and off, adjust the brightness, etc. And by supplying my location there’s a weather widget with the local weather and forecast.

This serves as a good starting point. Next I’ll be looking at doing some actual automation and getting some other features working.

Common Problems

If you don’t install ffi, pip install homeassistant will fail with:

c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
       #include <ffi.h>
                ^ ~~~~~~
Enter fullscreen mode Exit fullscreen mode

There are issues installing hass without venv:

2019-10-04 03:16:59 INFO (MainThread) [homeassistant.setup] Setting up recorder
Exception in thread Recorder:
Traceback (most recent call last):
  File "/usr/lib/python3.6/", line 916, in _bootstrap_inner
  File "/usr/local/lib/python3.6/dist-packages/homeassistant/components/recorder/", line 211, in run
    from .models import States, Events
  File "/usr/local/lib/python3.6/dist-packages/homeassistant/components/recorder/", line 6, in <module>
    from sqlalchemy import (
ModuleNotFoundError: No module named 'sqlalchemy'

2019-10-04 03:17:09 WARNING (MainThread) [homeassistant.setup] Setup of recorder is taking over 10 seconds.
Enter fullscreen mode Exit fullscreen mode

If not using venv and python3 -m pip install without sudo or --user:

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/'
Consider using the `--user` option or check the permissions.
Enter fullscreen mode Exit fullscreen mode

If you ssh in without -X, hass --open-ui gets stuck without UI:

2019-10-04 22:02:40 INFO (MainThread) [homeassistant.core] Timer:starting
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

deciduously profile image
Ben Lovy

Timely - I was already planning this exact project/product in the next few weeks! Thanks for the write-up, this will be very useful.

jeikabu profile image

There's actually another good one here on Living with Smart Home Automation for a Year

On a related note, your post on robot vacuums spurned me to get one of my own. I'm not 100% sure, but I'm pretty sure I can do some basic "smart home" integration.

deciduously profile image
Ben Lovy

Ah, I hadn't even thought of that! Ours is just set to run once every 24h at a set time, but there's definitely potential for tuning there. Thanks for the link!

Thread Thread
jeikabu profile image

See, I've got static schedules: morning alarm, work tasks, lighting, now vacuuming, etc., but I always need at least one more level of logic. It's the exceptions: I come home early, take PTO, etc. that break "dumb" smart homes.