Smart Home: Connecting Zigbee Devices to Home Assistant Container via Docker¶
Building a local, cloud-independent smart home is one of the most rewarding projects you can build on a Raspberry Pi. While Wi-Fi smart plugs and sensors are easy to buy, they saturate your router and often depend on external cloud servers (e.g. Tuya, SmartLife).
The Zigbee protocol is the gold standard for smart home sensor networks. Zigbee devices form a low-power, self-healing mesh network, and require no internet access to operate.
This guide walks you through: 1. Setting up a USB Zigbee Coordinator (e.g., Sonoff Zigbee 3.0 USB Dongle Plus). 2. Deploying a containerized stack containing Home Assistant Container, Zigbee2MQTT, and the Mosquitto MQTT Broker using Docker Compose. 3. Pairing a Zigbee sensor and integrating it locally with Home Assistant.
Architecture Overview¶
Step 1: Identify and Prepare the USB Zigbee Dongle¶
Insert your USB Zigbee dongle into one of the blue USB 3.0 ports of your Raspberry Pi. If you are using a Raspberry Pi 4 or 5, it is highly recommended to use a USB 2.0 extension cable (1 meter) to connect the dongle. The USB 3.0 ports and internal circuitry generate high-frequency radio interference that drastically reduces Zigbee range and causes pairing drops.
Find the serial device path of your dongle:
/dev/ttyUSB0 or /dev/ttyACM0. Note the full /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_... path; it is much safer to use in Docker than /dev/ttyUSB0, as it won't change if you plug in other USB devices).
Step 2: Configure Workspace and Zigbee2MQTT Settings¶
Create a dedicated directory structure for the Docker stack configuration files:
1. Configure Mosquitto MQTT Broker¶
Create a configuration file for the broker to allow communication between containers:
2. Configure Zigbee2MQTT¶
Create a configuration file defining the serial adapter path and MQTT broker connection details:
<YOUR_SERIAL_PORT_BY_ID> with the exact path you found in Step 1):
Step 3: Write the Docker Compose Stack¶
This Docker Compose file binds the MQTT broker, Zigbee2MQTT, and Home Assistant together, sharing a common virtual bridge network.
Create the file:
Add the following stack configuration:
devices: section under zigbee2mqtt maps your exact physical serial ID path to /dev/ttyUSB0 inside the container.
Step 4: Deploy and Pair Your First Device¶
Start the stack in the background:
1. Enable Pairing Mode in Zigbee2MQTT¶
- Open your browser and navigate to
http://<your-pi-ip>:8080to access the Zigbee2MQTT Dashboard. - Click Permit join (All) at the top right of the navigation bar. A countdown timer will begin.
- Grab your Zigbee sensor (e.g. Xiaomi, Sonoff, or Tuya Temperature sensor).
- Press and hold the reset/pairing button on the sensor for 5 seconds until the LED starts flashing.
- In the Zigbee2MQTT Web UI, you will see a notification:
Device '0x00158d000...' joined. You can rename this device (e.g.,Living Room Temp) directly in the dashboard.
Step 5: Integrating with Home Assistant¶
Now, let's connect Home Assistant to our MQTT broker so it can automatically discover the paired Zigbee devices.
- Navigate to
http://<your-pi-ip>:8123to open Home Assistant. - Go through the initial setup (create account, set location).
- Navigate to Settings -> Devices & Services.
- Click Add Integration in the bottom right corner, search for MQTT, and select it.
- Set the Broker configuration:
- Broker:
mosquitto(We use the Docker service container name as the hostname) - Port:
1883 - Leave username/password blank (as configured in
mosquitto.conf).
- Broker:
- Click Submit.
Home Assistant will automatically query the MQTT broker. Because homeassistant: true is configured in zigbee2mqtt, your newly paired Zigbee sensor will instantly appear as a device in Home Assistant with all its entities (temperature, humidity, battery percentage) fully exposed!
Troubleshooting & Maintenance¶
Permission Denied on Serial Port¶
If the zigbee2mqtt container logs show a serial connection error, the container may lack host permissions. You can fix this by adding the dialout group permissions on the host:
By leveraging this containerized stack, you have created a completely local, lightning-fast, and highly secure smart home engine on your Raspberry Pi.