Setup Homeassistant on a Raspberry Pi 3

28/02/2018 - Home Assistant, Raspbian, Stretch, Z-Wave, RFLink

This is a collection of steps I used to setup Home Assistant on a Raspberry Pi 3 running Raspbian Stretch. It includes some steps to setup a Z-Wave USB stick and an RFLink gateway.

The below assumes that user user1234 will be used to run Home Assistant.

Z-Wave

More details here. Install required libraries:

sudo apt install libudev-dev

Add the user that will run Home Assistant to the dialout group:

sudo usermod -a -G dialout user1234

Install Home Assistant in a Python 3 virtual environment

Create the virtual environment, activate it and install Home Assistant.

sudo apt install python3-virtualenv python3-dev build-essential
mkdir homeassistant
cd homeassistant && python3 -m virtualenv -p python3 ha_env
. ha_env/bin/activate
pip install homeassistant

Fix Z-Wave and RFLink device names

To have fixed names, for example /dev/zwave instead of /dev/ttyACM0 to use in the Home Assistant configuration files. Guide is available here.

Use lsusb to find the idVendor:idProduct of the devices, for example:

$ lsusb
Bus 001 Device 008: ID 2341:0042 Arduino SA Mega 2560 R3 (CDC ACM)
Bus 001 Device 012: ID 0658:0200 Sigma Designs, Inc. 

Use udevadm to find serial numbers. Here ttyACM1 is the RFLink gateway - the Z-Wave USB stick does not seem to have a serial number.

$ udevadm info -a -n /dev/ttyACM1 | grep '{serial}' | head -n1
    ATTRS{serial}=="4393331383732310B132"

Create file 99-usb-serial.rules in directory /etc/udev/rules.d/:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="zwave"
SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0042", ATTRS{serial}=="4393331383732310B132", SYMLINK+="rflink"

Disconnect and reconnect devices and the links should appear in /dev:

$ ls -l /dev/rflink /dev/zwave
lrwxrwxrwx 1 root root 7 Mar  1 22:20 /dev/rflink -> ttyACM1
lrwxrwxrwx 1 root root 7 Mar  1 22:20 /dev/zwave -> ttyACM0

Service for autostart

Create file [email protected] in directory /etc/systemd/system:

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

[Service]
Type=simple
User=%i
ExecStart=/path/to/homeassistant/virtualenv/ha_env/bin/hass -c "/path/to/homeassistant/config/dir"

[Install]
WantedBy=multi-user.target

To enable at startup:

sudo systemctl enable [email protected]

To start:

sudo systemctl start [email protected]

To see the log file output:

sudo journalctl -u [email protected]

To tail the log file output:

sudo journalctl -f -u [email protected]