sudo apt update sudo apt install python3-dev python3-pip python3-venv sudo pip3 install --upgrade virtualenv
Give the user access to serial lines (zwave, insteon, etc):
sudo adduser --system homeassistant sudo addgroup homeassistant sudo adduser homeassistant dialout
- Create a directory to install HA in and set its ownership and permissions.
sudo mkdir /opt/homeassistant sudo chown homeassistant:homeassistant /opt/homeassistant
- Change to the homeassistant user to do the installs.
sudo su -s /bin/bash homeassistant
- 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
- Install HA from pip. You might get some pip install errors that do not cause an issue later on:
pip3 install --upgrade homeassistant
- Open another terminal and login with your default (sudo enabled) user and open the Home Assistant port
8123in your Firewall:
sudo firewall-cmd --permanent --zone=public --add-port=8123/tcp sudo firewall-cmd --reload sudo firewall-cmd --list-all
Then switch back to the homeassistant user.
- 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
- 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
- Type in your preferred login credentials and click to create the account:
- And login to the Home Assistant web interface using your credentials:
- Hit ctrl-c to stop Home Assistants. The config directory now contains a bunch of sample config files for you to edit.
- 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
- Create the following
[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
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.
- Exit the homeassistant user, copy the service file to the system, and
update systemdto run the service.
sudo systemctl --system daemon-reload sudo systemctl enable homeassistant sudo systemctl start homeassistant
- If something goes wrong with the start command, check the logs:
sudo systemctl status homeassistant
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
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:
sudo chgrp -R homeassistant /opt/homeassistant sudo chmod -R g+w /opt/homeassistant/
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
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
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:
Open the General section:
Click on Check Config and - when it passes - click on Restart Server: