Installing home-assistant on a Raspberry Pi 2

Home automation is something I have been trying to pursue for many years. As a person that is technical but sometimes not very savvy I have tried other open source solutions and met with defeat. This is my successful attempt at installing Home Assistant on the Raspberry Pi 2. I also included the steps to install Z-Wave support because I have some Z-Wave devices, and the Aeotek Z-Stick which I wanted to integrate into this system.

The documentation on the site is easy to read, but not consistent across pages. I wanted to really understand what the software needed, so I did not use the Hassbian image. Initially I had tried using the All-In-One Installer, but something failed in the middle of its very long process and I could not figure out how to recover. What I ended up with was a combination of instructions from the Raspberry Pi installation instructions and the virtual environment instructions. For general operating Home Assistant tutorials I found the videos from the BRUH Automation channel useful.

To begin, start with a fresh installation of Rasbian. Follow the Rasbian instructions on how to get it onto your SD card, for me I follow the Linux instructions. Many of these steps take a very long time to run on a Raspberry Pi 2, so running another SSH window and running the “top” command is a nice way to monitor that the processes are running.

For a headless Raspberry Pi, enable SSH by creating an empty file called “ssh” in the “boot” partition of the SD card. After the pi is booted then ssh into the Pi and run raspi-config.

# SSH into pi
$ ssh pi@raspberrypi
# password is "raspberry"
# run raspi-config and update hostname (example: home-assistant.local)
# change the password, locale, expand the file system, etc.
$ sudo raspi-config
# reboot

Update Rasbian

# update base system
$ sudo apt-get update
$ sudoapt-get upgrade -y

Install Home Assistant

# install dependencies
$ sudo apt-get install python3 python3-venv python3-pip
# -r => system account, -m => create home directory
$ sudo useradd -rm homeassistant
$ sudo mkdir /srv/homeassistant
$ sudo chown homeassistant:homeassistant /srv/homeassistant
# become homeassistant user
$ sudo su -s /bin/bash homeassistant
# start and activate a virtual environment at the given directory
$ python3 -m venv /srv/homeassistant
(homeassistant) $ source /srv/homeassistant/bin/activate
(homeassistant) $ pip3 install --upgrade homeassistant
(homeassistant) $ hass

Open a browser to http://home-assistant.local:8123 or http://home-assistant:8123 depending on how your local router is setup and what hostname you chose during raspi-config. If you see the Home Assistant user interface then it worked!

To auto start Home Assistant when the Raspberry Pi boots, and to use “systemctl” commands to start/stop/restart Home Assistant.

# setup autostart
$ sudo nano -w /etc/systemd/system/home-assistant@homeassistant.service

Within “nano” paste the following and then save and exit.

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

Now reload the systemctl, enable Home Assistant, and start using systemctl commands. This assumes that Home Assistant is not currently running, if it is then replace the “start” with “stop” or “restart”. I verified that the process started using the correct user by watching the “top” output in a separate SSH session.

$ sudo systemctl --system daemon-reload
$ sudo systemctl enable home-assistant@homeassistant
$ sudo systemctl start home-assistant@homeassistant

Install Python OpenZWave for Home Assistant

# Install ZWave
$ sudo apt-get install cython3 libudev-dev python3-sphinx python3-setuptools git
$ sudo systemctl stop home-assistant@homeassistant
$ sudo su -s /bin/bash homeassistant
$ source /srv/homeassistant/bin/activate
(homeassistant) $ pip3 install --upgrade cython==0.24.1
(homeassistant) $ mkdir /srv/homeassistant/src
(homeassistant) $ cd /srv/homeassistant/src
(homeassistant) $ git clone https://github.com/OpenZWave/python-openzwave.git
(homeassistant) $ cd python-openzwave
(homeassistant) $ PYTHON_EXEC=$(which python3) make build
(homeassistant) $ PYTHON_EXEC=$(which python3) make install
# path is /srv/homeassistant/src/python-openzwave/openzwave/config
# reboot raspberry pi
# verify path to device /dev/ttyACM0

Next edit the Home Assistant Configuration to add zwave support

$ sudo nano /home/homeassistant/.homeassistant/configuration.yaml

Be sure to use the correct number of spaces to indent “usb_path” and “config_path”, in my configuration.yaml file it is using 2 spaces to indent.

zwave:
usb_path: /dev/ttyACM0
config_path: /srv/homeassistant/src/python-openzwave/openzwave/config

To allow the “homeassistant” user to access the USB Z-Wave Stick add to the dialout group

# allow user to use USB ZWave stick
$ sudo usermod -G dialout -a homeassistant

Now that Z-Wave has been configured and setup, plug in the Z-Wave USB Stick, and reboot the Raspberry Pi. If everything went as it should then the Z-Wave Network Management section should be visible in the user interface.

My next step was to allow time for the Z-Wave devices to be discovered, and then to add some automation rules, but that is a different topic. I hope these instructions are useful, and look forward to my new adventures in home automation!

Leave a Reply

Your email address will not be published. Required fields are marked *