The Zigbee standard
Zigbee is a low-power wireless mesh network standard targeted at battery-powered devices in wireless control and monitoring applications. Zigbee delivers low-latency communication. Zigbee chips are typically integrated with radios and with microcontrollers.Wikipedia
I first learned about Zigbee when I decided to make my apartment in Zagreb smart. After an initial consultation with a professional in the field, I had my sights set on Z-wave. It turned out that Z-wave was not an open standard. Furthermore, the licence fee manufacturers had to pay was reflected in the final price of the product. In contrast, Zigbee is a fully open, free alternative. Finally, the low barrier to entry results in a rich and vibrant market that offered all types of smart devices.
In order to communicate with and coordinate Zigbee devices,the user needs a hub. This is a device with a Zigbee transceiver that also interfaces with the end user through some other interface, Most often this will be through a WiFi connection with the manufacturers cloud. On the other end, the user will have a mobile application from the manufacturer with which to control the Zigbee devices.
Why make your own Zigbee hub?
Zigbee is an open standard. However, a hub built by a certain manufacturer will almost always only be capable of connecting with devices from that same manufacturer. This is due to the limitation of the software on that hub. In essence, the manufacturer does not want to put in any additional effort. They also do not want to assume the risk of allowing other devices to interact with their ecosystem. With an open-source Zigbee hub you can connect devices from any number of different manufacturers.
The hub itself will connect to a home automation control server like OpenHab or Home Assistant. There the user creates triggers or scripts to orchestrate his or her smart home. To make my own hub, I chose to use the Raspberry Pi Zero 2 W single board computer and a CC2531 USB Zigbee dongle. The Pi Zero 2 comes with a 64 arch CPU and runs the lightweight Raspbian Linux distribution without a GUI.
Use Zigbee2mqtt and Mosquitto
In order for the Zigbee dongle to communicate with its devices and the home automation software, I use two open source projects. Zigbee2mqtt is a project written with Node.js that has drivers for the Zigbee dongle. It use a Mosquitto server to publish information about the Zigbee devices and relay commands to them.
MQTT (originally an initialism of MQ Telemetry Transport[a]) is a lightweight, publish-subscribe, machine to machine network protocol for message queue/message queuing service. It is designed for connections with remote locations that have devices with resource constraints or limited network bandwidth. It must run over a transport protocol that provides ordered, lossless, bi-directional connections—typically, TCP/IP. It is an open OASIS standard and an ISO recommendation (ISO/IEC 20922).Wikipedia
Flashing the Zero 2
The Pi Zero 2 uses an SD card like other computers from the series. I decided to use the same Imager program I used for flashing the Raspberry Pi 4B in my series on home data centers. Instead of Ubuntu Server, I chose the 64-bit Raspbian Light distribution. In addition, I used the advanced configuration options to set my own default user, copy my SSH public key and block password authentication to the server. I also set the WiFi SSID and password for connection. This way the Zero 2 is already connected and its security hardened when it comes online.
Mosquitto come packaged with the Raspbian apt-get package manager. Simply run the command and the program will be installed. The situation with zigbee2mqtt is a little more complex. The standard recommendation from the project developer is to use a docker image. Since the Zero 2 has very low-end hardware specs, I did not want to even attempt a Docker installation. Thankfully, the project website offers instruction for compiling the application from source. Simply follow the steps. The Zero 2 is capable of running all the compilation dependencies.
Configure for remote access
As a final note, the Mosquitto server needs to be configured to allow access from the external network. Please check the project documentation. I needed to add a single line to a configuration file. After that my OpenHab instance could connect to Mosquitto and perform pub/sub operations.
- @ 2023-02-09 21:04