Smart home on Home Assistant with add-ons (Zigbee2MQTT,Portainer…) on any PC
In this article, we will cover the installation of Home Assistant with some addons on both supported and not officially supported systems (32 bit).
Nowadays, smart homes are becoming more and more popular among consumers. This is due to rapidly advancing technology that allows the creation of devices and systems capable of controlling various aspects of home life such as lighting, heating, air conditioning, security and entertainment. In addition, smart homes reduce energy costs and increase the level of comfort and convenience of life.
In this article, we will talk about how to create a smart home on the Home Assistant platform. Home Assistant is a free and open home device management system that allows you to integrate various devices and services to automate and manage life in your home.
The advantages of Home Assistant over smart home systems from other manufacturers (Xiaomi, Tuya, etc.) is the ability to use devices from different manufacturers with different types of connection (WiFi, MQTT, Zigbee, Bluetooth) without being tied to the ecosystem of a particular manufacturer.
We will need a computer or laptop with 512+ MB of RAM
If your computer or laptop has a 64-bit processor, installing Home Assistant is much easier, as detailed instructions are available at official website.
However, if you have a device with a 32-bit processor and i386 architecture, then installing add-ons to work with external sensors can be difficult due to the lack of official support. However, do not despair, as in this article we will look at how to install on such devices. (It is important to note that these methods can also be applied on 64-bit systems, but they are more difficult than the official ones to implement).
1. System installation
Almost any Linux distribution will work for a smart home server, but Debian is recommended. In this article, I will use Debian itself.
Let’s start with the installation. This process is the same for almost any system.
Download latest ISO version.
I chose the “Small” image as it includes most of the files in the image, which requires less download during the installation process.Download Balena Etcher, a tool to burn ISO images to a USB flash drive. If you are on a linux system, you can use dd instead.
Connect the downloaded USB stick to the system and boot from the USB.
Follow the installation process.
Most of the process is following the default settings and just clicking the Continue button.Don’t forget to enter the credentials for the root user and the non-administrator user.
If you plan to use your computer for smart home use only, make sure you Not install a graphical user interface (GUI), and Necessarily install SSH server.
Once the installation is complete, log in via SSH, or directly from the PC using the credentials of a normal user (not root).
2. Install Docker and Docker Compose
Even though Docker and Docker engine do not officially support 32-bit systems, it can be installed using this repository on GitLab:
wget https://gitlab.com/docker-32bit/debian/raw/i386/build-image.sh
sudo bash build-image.sh
Docker Compose can be installed with the command:
sudo apt install docker-compose
3. (Optional) Install Portainer
Portainer can be useful for more convenient management of future Docker containers.
To install Portainer, let’s create a docker-compose.yaml configuration file:
cd /opt
sudo nano docker-compose.yaml
Don’t forget to update the timezone in the config below.
Also, I keep all my Docker config and volumes in this folder. This makes backup easier. These volumes will store the data from the Docker image locally so that the data is not lost when the container is rebuilt (for example, when upgrading) /opt
Here we pass a file containing our local time settings so that Portainer knows what time it is (for log timestamps) and a socket that controls Docker so Portainer can do things in Docker.
version: '3.0'
services:
portainer:
container_name: portainer
image: bigbugcc/portainer-ce
restart: unless-stopped
ports:
- "9000:9000/tcp"
- "9443:9443/tcp"
environment:
- TZ=Asia/Novosibirsk
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
- /opt/portainer/data:/data
Permissions
We will also allow our non-administrator user to modify this file. Again, to make life a little easier for us.
sudo chown root:docker docker-compose.yaml
sudo chmod g+w docker-compose.yaml
Check configuration
Want to make sure you don’t make any configuration mistakes? Run the following command and Docker will show you what will be launched, as well as any errors in your config and warnings.
docker-compose -f docker-compose.yaml config
launch
docker-compose up -d
Run it and Docker will download the latest Portainer image and set everything up. After that, we can open the Portainer web interface by going to (you will get a warning about a self-signed certificate) or (unencrypted connection).
https://<ip компьютера>:9443
http://<ip компьютера>:9000
When visiting this portal for the first time, it will ask us to create a user account.
4. Install Home Assistant
If you missed the previous point, then you will need the initial setup of Docker Compose to work:
cd /opt
sudo nano docker-compose.yaml
Next, we write the container configuration to a file (do not forget to specify your time zone for the correct time display in the interface and logs):
version: '3.0'
services:
[...]
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:stable"
restart: unless-stopped
environment:
- TZ=Asia/Novosibirsk
volumes:
- /opt/homeassistant/config:/config
- /etc/localtime:/etc/localtime:ro
privileged: true
network_mode: host
Create a folder for the Homeassistant configuration files and run it:
cd /opt
sudo mkdir -p homeassistant/config
docker-compose up -d
Docker will now pull the Home Assistant image and set everything up.
Setting up Home Assistant
Now that the container is up and running, we need to set up the Home Assistant instance itself.
Open a browser and go to http://<ip компьютера>:8123
Initial setup of Home Assistant
Choose a username and password for your Home Assistant account. This account will also be “administrator”.
Next, go through setting up your home zone. During the setup process, Home Assistant will even show you devices that it has already discovered and that you can integrate from the start.
Once the setup is complete, you will be in the Home Assistant dashboard. If you set up any devices in the previous step, they will be displayed on the home screen.
Control Portainer from Home Assistant
Once we start adding add-ons, we’ll want to be able to quickly view them quite often without having to open additional browser windows.
To do this, we will use the iframe panel. This integration will add Portainer to the Home Assistant sidebar.
cd /opt/homeassistant/config
sudo nano configuration.yaml
To add an iframe for Portainer, add the following code to the file configuration.yaml
:
panel_iframe:
portainer:
title: Portainer
url: "https://192.168.10.106:9443"
icon: mdi:docker
require_admin: true
5. Installing the Mosquitto broker for MQTT and Zigbee devices
In this part, we will add our first addition. The Mosquitto MQTT broker will allow us to connect to a wide range of devices and I highly recommend installing it.
Let’s update the configuration docker-compose.yaml
:
services:
[...]
homeassistant:
[...]
depends_on:
- mosquitto
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto
restart: unless-stopped
ports:
- "1883:1883/tcp"
environment:
- TZ=Asia/Novosibirsk
volumes:
- /opt/mosquitto/config:/mosquitto/config
- /opt/mosquitto/data:/mosquitto/data
- /opt/mosquitto/log:/mosquitto/log
stdin_open: true
tty: true
We have added lines stdin_open
And tty
so that we can later connect to the container’s terminal to execute some commands.
Note that we have also added a dependency on the mosquitto container for our Home Assistant container. This way, our broker will be online before Home Assistant starts and we can be sure that our connection will not be interrupted.
mosquitto.conf configuration file
When we start the Mosquitto container with docker-compose up -d
errors will appear in the logs about the inability to open the configuration file /mosquitto/config/mosquitto.conf
. To fix this, we can download the default configuration file and store it in the newly created directory config
:
cd /opt/mosquitto/config/
sudo wget https://raw.githubusercontent.com/eclipse/mosquitto/master/mosquitto.conf
However, we will make a few changes. You can add the following lines to the end of the config file since all settings are commented out by default (default settings).
sudo nano mosquitto.conf
# Добавьте следующие строки в конец
# Listen on port 1883 on all IPv4 interfaces
listener 1883
socket_domain ipv4
# save the in-memory database to disk
persistence true
persistence_location /mosquitto/data/
# Log to stderr and logfile
log_dest stderr
log_dest file /mosquitto/log/mosquitto.log
# Require authentication
allow_anonymous false
password_file /mosquitto/config/mqttuser
Mosquitto Users
Next, we will create a user in Home Assistant to connect to the broker.
Ideally, we will create a new user for each device (family) later. For example, one account for Shelly devices, one for Zigbee2MQTT, etc.
Run the following command to create a user named homeassistant. Note that the -c option will create a new password file and overwrite any existing files. So drop this option if you want to create a second account.
docker exec -it mosquitto mosquitto_passwd -c /mosquitto/config/mqttuser homeassistant
If you now check the contents of the newly created file mqttuser
you will find your username and hashed password:
cat /opt/mosquitto/config/mqttuser
homeassistant:$7$101$q7VtJJ/E*******7$1I******************************************b/G**************************************A==
Now we can restart the Mosquitto container to load our changes:
sudo docker-compose restart mosquitto
The logs should show that the Mosquitto container is running:
sudo cat /opt/mosquitto/log/mosquitto.log
1662413136: mosquitto version 2.0.15 starting
1662413136: Config loaded from /mosquitto/config/mosquitto.conf.
1662413136: Opening ipv4 listen socket on port 1883.
1662413136: mosquitto version 2.0.15 running
Setting up MQTT in Home Assistant
We can now connect Home Assistant to our MQTT broker so it can start subscribing to topics and sending messages. Since there are no other connected MQTT clients yet, Home Assistant will not add new devices yet.
We’re adding a new MQTT integration to Home Assistant and entering the credentials we set up a minute ago for authentication.
The MQTT container logs confirm the successful Home Assistant connection:
sudo cat /opt/mosquitto/log/mosquitto.log
1662413136: mosquitto version 2.0.15 running
1662414198: New connection from 192.168.10.106:43153 on port 1883.
1662414198: New client connected from 192.168.10.106:43153 as 4atvQWWEyf2XpG3yy0kgOW (p1, c1, k60, u'homeassistant').
1662414198: Client 4atvQWWEyf2XpG3yy0kgOW disconnected.
1662414198: New connection from 192.168.10.106:39605 on port 1883.
1662414198: New client connected from 192.168.10.106:39605 as 5gNbahjfE5DulEufquYcaa (p2, c1, k60, u'homeassistant').
6. Installing Zigbee2MQTT to connect sensors and other smart home devices using the Zigbee protocol
To do this, you will need to purchase a separate Zigbee coordinator that connects to your computer via USB. I used this in your system.
Find a Zigbee Coordinator
In the Docker compose configuration, we will need to assign a Zigbee coordinator, which will be connected via USB, to the Docker container.
Connect your Zigbee coordinator (eg Conbee II, Sonof Zigbee 3.0 Plus, …) to your machine. Then run the following command to get the unique path to the device.
ls -l /dev/serial/by-id/
usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_eexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx52-if00-port0 -> ../../ttyUSB0
Later we will use this unique by-id path in our configuration instead of the typical /dev/ttyUSB0 because there is always a risk that the device will get a new TTY after a reboot, especially when other devices are connected.
docker-compose
We extend our docker-compose.yaml with the configuration for the Zigbee2MQTT container.
services:
[...]
zigbee2mqtt:
container_name: zigbee2mqtt
image: koenkk/zigbee2mqtt
restart: unless-stopped
ports:
- "8099:8099/tcp"
environment:
- TZ=Asia/Novosibirsk
volumes:
- /opt/zigbee2mqtt/data:/app/data
- /run/udev:/run/udev:ro
devices:
- /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_eexxxxxxxxxxxxxxxxxxxxxxxxxxxx52-if00-port0:/dev/ttyACM0
Please note that I have changed the port mapping for this container. Port 8080 is already in use by the admin, so I changed the Zigbee2MQTT frontend port to 8099 (see below) and specified it in the Docker config.
We won’t be running our container just yet, as we first need to set up our configuration.
Create an MQTT User
When we set up the Mosquitto MQTT broker, I said that I prefer to create an MQTT user for each service. So let’s create a user for our Z2M container.
docker exec -it mosquitto mosquitto_passwd /mosquitto/config/mqttuser z2m_mqtt
Password: # Enter a password
Reenter password: # Repeat the password
cat mosquitto/config/mqttuser
[...]
z2m_mqtt:$7$101$1xcB1yrF********$O$XR******************2/N************************************************************g==
Zigbee2MQTT config
To get a copy of the default config, run sudo wget https://raw.githubusercontent.com/Koenkk/zigbee2mqtt/master/data/configuration.yaml
in the folder where the config will be stored (/opt/zigbee2mqtt/data
). Then open and edit it with sudo nano /opt/zigbee2mqtt/data/configuration.yaml.
We will tell Z2M to connect to our MQTT broker, use the syntax Home Assistant understands to discover devices, set up a web server, and let Z2M generate some keys used to set up the Zigbee network.
# Adapter settings
serial:
port: /dev/ttyACM0
# MQTT
mqtt:
base_topic: zigbee2mqtt
server: '!secret server'
user: '!secret user'
password: '!secret password'
client_id: zigbee
# Zigbee network
permit_join: false # Do not allow random devices to connect automatically
# Webserver
frontend:
port: 8099 # Custom port
url: 'http://<ip.of.our.box>:8099' # Update IP here
# Devices and groups
# Extract config to separate files
devices: devices.yaml
groups: groups.yaml
# Home Assistant integration
homeassistant: true
If you check the logs through Portainer or docker-compose logs zigbee2mqtt
you will see that our container started up just fine:
Using '/app/data' as data directory
Zigbee2MQTT:info 2022-10-04 12:09:47: Logging to console and directory: '/app/data/log/2022-10-04.12-09-47' filename: log.txt
Zigbee2MQTT:info 2022-10-04 12:09:47: Starting Zigbee2MQTT version 1.28.0 (commit #03ba647)
Zigbee2MQTT:info 2022-10-04 12:09:47: Starting zigbee-herdsman (0.14.62)
Zigbee2MQTT:info 2022-10-04 12:09:48: zigbee-herdsman started (resumed)
Zigbee2MQTT:info 2022-10-04 12:09:48: Coordinator firmware version: '{"meta":{"maintrel":1,"majorrel":2,"minorrel":7,"product":1,"revision":20220219,"transportrev":2},"type":"zStack3x0"}'
Zigbee2MQTT:info 2022-10-04 12:09:48: Currently 0 devices are joined:
Zigbee2MQTT:info 2022-10-04 12:09:48: Zigbee: disabling joining new devices.
Zigbee2MQTT:info 2022-10-04 12:09:48: Connecting to MQTT server at mqtt://<ip.of.our.box>:1883
Zigbee2MQTT:info 2022-10-04 12:09:48: Connected to MQTT server
Zigbee2MQTT:info 2022-10-04 12:09:48: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload '{"state":"online"}'
Zigbee2MQTT:info 2022-10-04 12:09:48: Started frontend on port 0.0.0.0:8099
Zigbee2MQTT:info 2022-10-04 12:09:48: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload '{"state":"online"}'
Let’s add Z2M to the Home Assistant sidebar:
The process is similar to adding Portainer:
panel_iframe:
portainer:
[...]
zigbee2mqtt:
title: Zigbee2MQTT
icon: mdi:zigbee
url: http://192.168.10.106:8099
require_admin: true
After restarting Home Assistant (docker-compose restart homeassistant
) we get something like this:
IN given The video shows in detail and clearly how to use Zigbee2MQTT. If this is your first time working with him, I recommend you to watch it.
End
Thank you for your attention, there are still many additions that can be added, so the article will be supplemented.
If you have any questions or suggestions – write in the comments, I’m glad for any activity.