ZigBee is a specification for wireless networks with low data volume and low power consumption. The first version came onto the market in 2004 and has been continuously developed since then. In our VanPI system, we use Zigbee2MQTT for communication between the various software components, which is a bridge for devices from various manufacturers. We also need a Zigbee coordinator, for which we use the "Sonoff Zigbee Gateway, ZBDongle-E USB Zigbee 3.0 USB Dongle Plus", which is already pre-flashed with the Zigbee coordinator firmware from the usual online retailers.
This means that nothing stands in the way of wireless communication with many switches and sensors.
Small note: Zigbee2MQTT will be installed by default in the new, soon to be released VAN PI version v1.1.0.
installation
If the coordinator is connected to the Raspberry via USB, we can display the corresponding location for verification using “ls –l /dev/serial/by-id”.
Zigbee2MQTT requires some dependencies, these are already installed because we use them for other software as well. The dependencies are nodejs, git, make, g++ and gcc and can be installed with the commands
sudo curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash –
And
sudo apt-get install -y nodejs git make g++ gcc
installed if needed.
Then we create a new folder for Zigbee2MQTT and pass the rights to our user:
sudo mkdir /opt/zigbee2mqtt
sudo chown -R ${USER}: /opt/zigbee2mqtt
We clone Zigbee2MQTT from the Github repository:
git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
And install the required dependencies with npm:
cd /opt/zigbee2mqtt
npm ci
We can ignore any error messages that may appear.
configuration
Before we start Zigbee2MQTT, we edit the configuration.yaml file to adapt it to our system:
nano /opt/zigbee2mqtt/data/configuration.yaml
The following content goes in there:
homeassistant: false
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://localhost:1883
serials:
port: /dev/ttyACM0
advanced:
network_key: GENERATE
log_level: info
log_output:
- console
frontend:
port: 8099
experimental:
new_api: true
homeassistant_legacy_entity_attributes: false
legacy_api: false
legacy_availability_payload: false
device_options:
legacy: false
Systemd.service
To ensure that Zigbee2MQTT starts automatically during the boot process and runs in the background, we create a system service
sudo nano /etc/systemd/system/zigbee2mqtt.service
And fill this file with the following content:
[Unit]
Description=zigbee2mqtt
After= network.target
[Service]
Environment=NODE_ENV=production
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
DefaultOutput=null
DefaultError=inherit
Restart=always
RestartSec=10s
User=pi
[Install]
WantedBy= multi-user.target
After that we can check our configuration by starting Zigbee2MQTT
sudo systemctl start zigbee2mqtt.service
systemctl status zigbee2mqtt.service
If everything works, we set the service to start automatically when the system boots:
sudo systemctl enable zigbee2mqtt.service
Front-end
We can now access the frontend via the port (8099) that we specified in our configuration.yaml. To do this, we enter the IP address of the Raspberry in the browser, followed by a colon and the port. For example, "192.168.1.131:8099"
Training
To teach Zigbee devices, we need to activate the "Activate teach" function. Devices will then be found automatically as soon as they send data. Some devices need to be woken up for this, such as switches. They will then be automatically recognized by Zigbee2MQTT and made available. We can follow the activities in the "Logs" area.
Node-RED
To process the data in Node-RED, we install "node-red-contrib-zigbee2mqtt" via the palette. In this we configure the MQTT server (localhost), the base topic (zigbee2mqtt) and the port (1833). To do this, we set the connected device whose data we want to receive in a Zigbee2MQTT in-node. We can then communicate with our devices and continue working with them.
Left
Here you can find the configuration.yaml and the systemd.service files that we use in our setup:
https://git.pekaway.de/Vincent/vanpi/-/tree/main/pi4 Devices supported by Zigbee2MQTT:
https://www.zigbee2mqtt.io/supported-devices/
node-red-contrib-zigbee2mqtt: