ZigBeeForDomoticZ plugin Wiki

Install the plugin with Docker

This page installs Domoticz and the plugin with Docker, for example on a Raspberry Pi. It builds a custom Domoticz image, based on the official domoticz/domoticz stable image, with the Python modules of the plugin already installed, so the container starts quickly.

The plugin, the Domoticz database and the scripts live in a host folder mapped into the container, so they survive container rebuilds and restarts.

1. Prerequisites

2. Get the plugin

The image build needs the plugin, so clone it first, into the userdata/plugins folder that will be mapped into the container:

mkdir -p /opt/domoticz/userdata/plugins
cd /opt/domoticz/userdata/plugins
git clone --filter=blob:none https://github.com/zigbeefordomoticz/Domoticz-Zigbee.git

3. The Dockerfile and the compose file

The plugin ships both files in its Docker folder. Copy them to /opt/domoticz:

cd /opt/domoticz
cp userdata/plugins/Domoticz-Zigbee/Docker/dockerfile .
cp userdata/plugins/Domoticz-Zigbee/Docker/docker-compose.yml .

The dockerfile builds the custom image: it starts from domoticz/domoticz:stable, sets the time zone (TZ=Europe/Paris, change it if needed), installs a few tools (ping, vim, ssh for git pull), and installs the Python modules listed in the plugin requirements.txt into the Domoticz virtual environment of the image (/opt/venv). This is the virtual environment Domoticz already uses: there is none to create or configure. Use the file of the plugin as is; you only need to rebuild the image when the plugin’s Python requirements change.

The docker-compose.yml runs the container. Adapt it to your installation; it should look like this:

services:
  domoticz:
    build:
      context: .
      dockerfile: dockerfile
    image: domoticz/domoticz:stable-custom
    container_name: domoticz
    restart: unless-stopped

    # Pass devices to container
    devices:
       - "/dev/serial/by-id/usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220715103321-if00:/dev/ttyUSB-zigbee"

    ports:
      - "8080:8080"
      - "9440:9440"

    volumes:
      - ./userdata:/opt/domoticz/userdata

    logging:
      driver: "journald"

4. Find the serial port of the coordinator

ls -l /dev/serial/by-id/
lrwxrwxrwx 1 root root 13 Dec 11 22:19 usb-ITEAD_SONOFF_Zigbee_3.0_USB_Dongle_Plus_V2_20220715103321-if00 -> ../../ttyUSB0

Use this /dev/serial/by-id/… path, which doesn’t change after a reboot, on the host side of devices. The container side is a name of your choice, for example /dev/ttyUSB-zigbee: this is the Serial Port you will give to the plugin.

5. Use the plugin start script

When the container starts, the Domoticz image runs /opt/domoticz/userdata/customstart.sh if it exists. The plugin provides one, which, the first time a new container starts, reinstalls the tools and the plugin Python modules in the image virtual environment /opt/venv (through Tools/plugin-auto-upgrade.sh). Link it, so that plugin updates bring its updates too:

ln -s /opt/domoticz/userdata/plugins/Domoticz-Zigbee/Tools/customstart.sh /opt/domoticz/userdata/customstart.sh

6. Build and start

cd /opt/domoticz
docker compose build
docker compose up -d

Domoticz is then available at http://<host>:8080.

7. Add the plugin in Domoticz

Follow Plugin settings. For a USB coordinator, the Serial Port is the container path chosen in step 4 (/dev/ttyUSB-zigbee in the example). Then open the WebUI at http://<host>:9440/z4d/.

Updating

Alternative: keep the Python modules in the userdata volume

Optional. The setup above, with customstart.sh, is the recommended one: you have nothing to configure, and the image handles Python.

The virtual environment of the image (/opt/venv) is part of the container, not of the volume. When the container is recreated (image update, Reset or project rebuild in Synology Container Manager), the plugin modules are gone, and customstart.sh installs them again when the new container first starts. That first start takes longer, and it only happens when you change the image, typically for a new Domoticz version.

If that reinstallation fails on your system (for example, no network yet when the NAS boots), you can instead keep a virtual environment in the userdata volume. Weigh the trade-off first:

It works with the plain domoticz/domoticz image, without building a custom one. The commands below use the container name domoticz; adapt them.

  1. Open a shell in the container:

    docker exec -it domoticz bash
    
  2. Create the virtual environment in the volume. The python3 of the image is the one Domoticz uses, so the versions match:

    python3 -m venv /opt/domoticz/userdata/venv
    
  3. Install the plugin modules in it, still from the container shell:

    /opt/domoticz/userdata/venv/bin/python3 -m pip install \
      -r /opt/domoticz/userdata/plugins/Domoticz-Zigbee/requirements.txt
    

    Do it now, from the shell: with an empty virtual environment, the plugin can’t start, so its WebUI (and its Upgrade button) isn’t available.

  4. Add VIRTUAL_ENV and PATH to the environment of the compose file (on Synology, in the Container Manager project), and remove any PYTHONPATH:

        environment:
          VIRTUAL_ENV: /opt/domoticz/userdata/venv
          # Written in full: Compose would replace $PATH with the PATH of the host
          PATH: /opt/domoticz/userdata/venv/bin:/opt/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    

    The virtual environment of the volume comes first in PATH: Domoticz looks for its Python there.

  5. Recreate the container (docker compose up -d) and check the Domoticz log. The plugin writes VIRTUAL_ENV is set to: /opt/domoticz/userdata/venv, then starts normally.

Afterwards:

Troubleshooting

References