SDB: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. There are 3 methods to install Home-Assistant. Here Method 3, Home Assistant Core, is used.
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 python3 python3-devel python3-pip autoconf libffi-devel libjpeg8-devel libturbojpeg0 liblapacke3 libpcap1 gcc-c++
- useradd -rm -c "Home Assistant User" hass
- passwd hass
- su - hass
- python3 -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.
You may find in the log file a message about missing capabilities. In that case you need to use the following command:
setcap 'cap_net_admin,cap_net_raw+eip' /usr/bin/python3.13
The file /usr/bin/python3.13 must be a real file not a link, which is why the version 13 is present in the file name. Obviously this may later be a higher version, when the default version of Python has a higher version number.
In a server which is dedicated to this service this might be a solution, however it gives the capabilities to all users of that system. Therefor it is better to replace the logical link /home/hass/hassvenv/bin/python3 to this file by a physical copy of that file in that folder and protect that file to be used only by the user hass. The following commands , starting as root, will do that:
su - hass rm hassvenv/bin/python3 cp /usr/bin/python3.13 hassvenv/bin/python3 chmod 700 hassvenv/bin/python3 sudo setcap 'cap_net_admin,cap_net_raw+eip' hassvenv/bin/python3
In case you assigned the capabilities earlier to /usr/bin/python3.13, you can remove these capabilities, as root, with:
setcap -r /usr/bin/python3.13
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 /home/hass/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
Running in a selinux environment
In a selinux environment, default in Leap 16.0 and newest Tumbleweed, starting the home-assistant service needs the following:
zypper install policycoreutils-python-utils semanage fcontext -a -t bin_t /home/hass/bin/hass.sh
Still, it is possible that home-assistant.service does not start due to missing selinux policies. In that case you need to inspect the log file /var/log/audit/audit.log, and look for denied access. Obviously you can solve this by running selinux in permissive mode. But you can also solve this by running the following commands:
ausearch -c 'hass' --raw | audit2allow -M myhass semodule -i myhass.pp
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