INSTAR Deutschland GmbH

Home Assistant on Debian



Installation of Home Assistant on a Debian Stretch Server

Installation of dependencies:

sudo apt update
sudo apt install python3-dev python3-pip python3-venv
sudo pip3 install --upgrade virtualenv

Home Assistant with your INSTAR IP Camera

Create a user and group

Give the user access to serial lines (zwave, insteon, etc):

sudo adduser --system homeassistant
sudo addgroup homeassistant
sudo adduser homeassistant dialout

Home Assistant with your INSTAR IP Camera

  1. Create a directory to install HA in and set its ownership and permissions.
sudo mkdir /opt/homeassistant
sudo chown homeassistant:homeassistant /opt/homeassistant

Home Assistant with your INSTAR IP Camera

  1. Change to the homeassistant user to do the installs.
sudo su -s /bin/bash homeassistant

Install Home Assistant

  1. Install a virtual env to sandbox the Home Assistant software and dependencies and activate it so further installs are done here.
cd /opt/homeassistant
python3 -m venv /opt/homeassistant
source bin/activate

Home Assistant with your INSTAR IP Camera

  1. Install HA from pip. You might get some pip install errors that do not cause an issue later on:
pip3 install --upgrade homeassistant

Home Assistant with your INSTAR IP Camera

  1. Open another terminal and login with your default (sudo enabled) user and open the Home Assistant port 8123 in your Firewall:
sudo firewall-cmd --permanent --zone=public --add-port=8123/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

Home Assistant with your INSTAR IP Camera

Then switch back to the homeassistant user.

  1. To keep all the config and log files in the same directory (rather than having them in /home/homassistant) we can run Home Assistant with the following command:
mkdir config
./bin/hass -c /opt/homeassistant/config --log-file /opt/homeassistant/hass.log

Home Assistant with your INSTAR IP Camera

  1. You can now access Home Assistants web interface by opening the following URL (exchange the IP address 192.168.2.111 with the IP of your Linux Server) inside your webbrowser http://192.168.2.111:8123/:

Home Assistant with your INSTAR IP Camera

  1. Type in your preferred login credentials and click to create the account:

Home Assistant with your INSTAR IP Camera

  1. And login to the Home Assistant web interface using your credentials:

Home Assistant with your INSTAR IP Camera

  1. Hit ctrl-c to stop Home Assistants. The config directory now contains a bunch of sample config files for you to edit.

Run Home Assistant as a Service

  1. Assuming it works, exit the homeassistant user, change to the /etc/systemd/system/ directory and create a service to start Home Assistant automatically.
exit
cd /etc/systemd/system/
sudo nano homeassistant.service
  1. Create the following systemd init file:

Home Assistant with your INSTAR IP Camera

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

[Service]
Type=simple
User=homeassistant
ExecStart=/opt/homeassistant/bin/hass -c /opt/homeassistant/config --log-file /opt/homeassistant/hass.log

[Install]
WantedBy=multi-user.target



Note:

Home Assistant comes with an embedded MQTT broker. Since we already installed the Mosquitto MQTT Broker with Node-RED we need to deactivate this secondary Broker. We do this by adding the After line in the systemd script, that makes sure that the Home Assistant service is started after the Mosquitto broker. And we will configure Home Assistant to use this broker instead.

  1. Exit the homeassistant user, copy the service file to the system, and update systemd to run the service.
sudo systemctl --system daemon-reload
sudo systemctl enable homeassistant
sudo systemctl start homeassistant
  1. If something goes wrong with the start command, check the logs:
sudo systemctl status homeassistant

Home Assistant with your INSTAR IP Camera

Finally, to make it easier to edit config files and try out code changes, give your regular user write permissions in the homeassistant directory. For this we need to assign both our regular user - in my case this is the nodeadmin - and the homeassistant user to the homeassistant group.

sudo groupadd homeassistant
sudo usermod -a -G homeassistant nodeadmin
sudo usermod -a -G homeassistant homeassistant

Make sure that both users are inside the created group:


Home Assistant with your INSTAR IP Camera

sudo chgrp -R homeassistant /opt/homeassistant
sudo chmod -R g+w /opt/homeassistant/

Configuring Home Assistant

We set up Home Assistant to be installed in /opt/homeassistant. The configuration file can be found in the config subfolder. Let's open up the file to take a look at it:

sudo nano /opt/homeassistant/config/configuration.yaml

Adding the MQTT Broker


Home Assistant with your INSTAR IP Camera

The first thing we should do, is adding our Mosquitto server (192.168.2.111) as MQTT broker. We can do this by adding the following lines at the end of the document:

# MQTT Communication

mqtt:
  broker: 192.168.2.111
  port: 1883
  user: debian
  password: mysecretpassword

Note:

Home Assistant comes with an Embedded MQTT broker. Since we already installed the Mosquitto MQTT Broker with Node-RED we deactivated this secondary Broker by adding the configuration above - as well as making sure that the Mosquitto Service is run before Home Assistant.


If you don't plan on using Mosquitto skip this step and Embedded MQTT Broker will be started instead.



To verify that we did not mess up the configuration we can go to the Configuration Tab in Home Assistant:


Home Assistant with your INSTAR IP Camera

Open the General section:


Home Assistant with your INSTAR IP Camera

Click on Check Config and - when it passes - click on Restart Server:


Home Assistant with your INSTAR IP Camera