SDB:Home-Assistant

Jump to: navigation, search
This article is about the use of a Raspberry Pi for Home Automation with the system Home Assistant

Architecture of Home Assistant

Unlike most application Home Assistant does not come as a normal package to be installed using an installation manager. The system is written in Python3 and runs in a Python Virtual Environment. This means that it first needs an established Virtual Environment and Python pip is used to install the server.

Preparation of Raspberry Pi with Tumbleweed or Leap

Perform the following actions:

  • Do the installation of the JeOS image of Tumbleweed or Leap on the micro-SD card or possibly a USB device. See How to install openSUSE on a Raspberry Pi.
  • Insert the micro-SD card in or connect the USB device to the Raspberry Pi and power it up.
  • Find somehow the IP address of the RPi.
  • From another system start a ssh connection with ssh root@<IP_address>
  • Enter the password linux
  • Perform other configuration work, like changing your password, giving it permanent IP address and a proper hostname, etc.

Preparation of Python Virtual Environment and installation of Home Assistant

Perform the following actions:

  • zypper in bluez python312 python312-devel python312-pip autoconf libffi-devel libjpeg8-devel libturbojpeg0 liblapacke3 libpcap1 gcc-c++
  • useradd -rm -c "Home Assistant User" hass
  • passwd hass
  • su - hass
  • python3.12 -m venv hassvenv

The python virtual environment of the user has has been setup in ~/hassvenv.

  • source hassvenv/bin/activate
  • pip install --upgrade pip
  • pip install wheel aiohttp_fast_zlib zlib_ng isal
  • pip install homeassistant home-assistant-frontend

You may start home-assistant using the command:

hass &

to return to the command prompt. A log file will be made, so you may use

tail -f .homeassistant/home-assistant.log

to inspect the progress of starting up the service.

Controlling the Home Assistant Service

Instead of starting the service shown above with hass &, you can start the service using the following command:

  • systemctl start home-assistant.service

And to start it automatically after a (re)boot:

  • systemctl enable home-asisstant.service

For this you need the following files: /home/hass/bin/hass.sh, and /usr/lib/systemd/system/home-assistant.service:

/home/hass/bin/hass.sh
#!/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

function activate_venv() {
  # Activate Python virtual environment
  VENV="$1"
  if [ ! -f "$VENV/bin/activate" ]
    then
      return 1
  fi
  . $VENV/bin/activate
  return 0
}

function start_hass() {
  cd /home/hass/
  activate_venv hassvenv
  hass
}

start_hass
/usr/lib/systemd/system/home-assistant.service
[Unit]
Description=Home Assistant
After=network.target mysql.service mariadb.service

[Service]
Type=simple
User=hass
ExecStart=/home/hass/bin/hass.sh
SendSIGKILL=no
RestartForceExitStatus=100
# avoid hass amok runs
MemoryHigh=1024M
MemoryMax=2048M

[Install]
WantedBy=multi-user.target

Configuration and use of Home Assistant

Configuration and use of Home Assistant is done from the webpage. Access to the webpage is via:

http://<IP_address>:8123
Icon-warning.png
Warning: The author of this page considers this page as: Work in Progress