deCONZ REST plugin Documentation

repository·master·Indexed 24 days ago

https://github.com/dresden-elektronik/deconz-rest-plugin

A REST-API plugin for managing and controlling Zigbee 3.0, ZHA, and ZLL devices from manufacturers such as Xiaomi Aqara, IKEA TRÅDFRI, Philips Hue, innr, and Samsung. Requires compatible hardware like RaspBee or ConBee USB dongles. Documentation covers installation, headless configuration on Linux, build instructions for Linux (Qt5/Qt6), Windows (MSYS2), and macOS, as well as device-specific troubleshooting for IKEA, Lutron, Terncy, and Xiaomi hardware.

Tokens
3.9K
Snippets
8
Records
22
Agent score
84%

What's inside deCONZ REST plugin

  1. Overview of deCONZ REST plugin

    master

    The deCONZ REST plugin provides a REST-API to control Zigbee 3.0 (Z30), Zigbee Home Automation (ZHA), and Zigbee Light Link (ZLL) devices. It supports various vendors including Xiaomi Aqara, IKEA TRÅDFRI, Philips Hue, innr, and Samsung.

    To use the plugin, you must have compatible Zigbee hardware such as a RaspBee/RaspBee II shield for Raspberry Pi or a ConBee/ConBee II/ConBee III USB dongle.

  2. Build the deCONZ REST-API plugin with CMake on Linux (Qt5)

    master

    Use CMake to build the plugin on older Debian versions using Qt5.

    Prerequisites

    Install the following dependencies via apt-get. Note: On newer Ubuntu versions, qt5-default is unavailable; use qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools instead.

    apt-get update && \
    apt-get install --no-install-recommends -y \
    qt5-default \
    lsb-release ca-certificates build-essential pkg-config git \
    libqt5serialport5-dev  libqt5websockets5-dev qtdeclarative5-dev  \
    sqlite3 libsqlite3-dev libgpiod-dev libssl-dev curl cmake ninja-build

    Build Steps

    1. Clone the repository:
      git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    2. Compile using Ninja and specify Qt5:
      cmake -DCMAKE_INSTALL_PREFIX=/usr -DQT_VERSION_MAJOR=5 -G Ninja -B build
      cmake --build build
    3. Install to a local temporary directory to adjust RPATH:
      cmake --install build --prefix tmp

    The resulting plugin is located at: tmp/share/deCONZ/plugins/libde_rest_plugin.so

    git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    cmake -DCMAKE_INSTALL_PREFIX=/usr -DQT_VERSION_MAJOR=5 -G Ninja -B build
    cmake --build build
    cmake --install build --prefix tmp
  3. Build the deCONZ REST-API plugin on Windows

    master

    Building on Windows requires the MSYS2 MINGW32 environment.

    Prerequisites

    1. Install MSYS2 from https://msys2.org.
    2. Open the MSYS2 MINGW32 shell and install the following packages via pacman:
    pacman -Sy mingw-w64-i686-qt5 mingw-w64-i686-openssl mingw-w64-i686-sqlite3

    Build Steps

    1. Clone the repository:
      git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    2. Navigate to the source directory in the MSYS2 MINGW32 shell:
      cd /c/src/deconz-rest-plugin
    3. Compile using CMake:
      cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/mingw32/lib/cmake -B build
      cmake --build build

    The resulting plugin is de_rest_plugin.dll located in the build directory.

    git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    cd /c/src/deconz-rest-plugin
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/mingw32/lib/cmake -B build
    cmake --build build
  4. Build the deCONZ REST-API plugin on macOS

    master

    Currently, macOS support is limited to Intel Macs (x86_64).

    Prerequisites

    Install dependencies using Homebrew:

    brew install qt@5 ninja cmake

    Build Steps

    1. Clone the repository:
      git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    2. Navigate to the source directory:
      cd deconz-rest-plugin
    3. Run the provided build script:
      ./build-macos.sh
    4. Copy the compiled plugin to your deCONZ app bundle:
      cp build/de_rest_plugin.dylib /Applications/deCONZ.app/Contents/Plugins

    The compiled plugin is de_rest_plugin.dylib.

    git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    cd deconz-rest-plugin
    ./build-macos.sh
    cp build/de_rest_plugin.dylib /Applications/deCONZ.app/Contents/Plugins
  5. Install deCONZ on various platforms

    master

    Installation instructions vary based on your hardware (RaspBee vs ConBee) and operating system. Always refer to the official Phoscon website for specific platform/device instructions.

    Important: Before updating from a previous version, always create a backup in the Phoscon App and review the changelog.

  6. Configure headless support for Linux

    master

    The deCONZ package includes a systemd script that allows the service to run without an X11 server (headless mode).

    1. Enable the service at boot

    $ sudo systemctl enable deconz

    2. Disable the deCONZ GUI autostart service

    If you are using a default installation or a dresden elektronik sd-card image, the GUI may autostart. Disable it using:

    $ sudo systemctl disable deconz-gui
    $ sudo systemctl stop deconz-gui
    $ sudo systemctl enable deconz
    $ sudo systemctl disable deconz-gui
    $ sudo systemctl stop deconz-gui
  7. Build the deCONZ REST-API plugin with CMake on Linux (Qt6)

    master

    Use CMake to build the plugin on modern Linux distributions like Debian Trixie that use Qt6. This method automatically pulls headers and sources from deconz-lib, so the deconz-dev package is not required.

    Prerequisites

    Install the following dependencies via apt-get:

    apt-get update && \
        apt-get install --no-install-recommends -y \
        lsb-release \
        ca-certificates \
        build-essential \
        cmake \
        pkg-config \
        git \
        sqlite3 \
        libsqlite3-dev \
        libgpiod-dev \
        libssl-dev \
        qt6-base-dev \
        qt6-base-dev-tools \
        qt6-serialport-dev \
        qt6-websockets-dev \
        qt6-declarative-dev \
        qt6-5compat-dev \
        dpkg-dev \
        fakeroot \
        curl \
        wget

    Build Steps

    1. Clone the repository:
      git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    2. Compile using Ninja and specify Qt6:
      cmake -DCMAKE_INSTALL_PREFIX=/usr -DQT_VERSION_MAJOR=6 -G Ninja -B build
      cmake --build build
    3. Install to a local temporary directory to adjust RPATH:
      cmake --install build --prefix tmp

    The resulting plugin is located at: tmp/share/deCONZ/plugins/libde_rest_plugin.so

    git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    cmake -DCMAKE_INSTALL_PREFIX=/usr -DQT_VERSION_MAJOR=6 -G Ninja -B build
    cmake --build build
    cmake --install build --prefix tmp
  8. Build the deCONZ REST-API plugin with QMake (Deprecated)

    master

    Building via QMake is deprecated and will be removed in the future. This method is only supported on Linux.

    Prerequisites

    Install the deCONZ development package:

    sudo apt install deconz-dev

    Build Steps

    1. Clone the repository:
      git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    2. Checkout your desired branch:
      cd deconz-rest-plugin
      git checkout -b mybranch HEAD
    3. Compile the plugin:
      qmake && make -j2
      Note: If you are on a Raspberry Pi 1, use qmake && make (without the -j2 flag).
    4. Replace the original plugin:
      sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
    git clone https://github.com/dresden-elektronik/deconz-rest-plugin.git
    cd deconz-rest-plugin
    git checkout -b mybranch HEAD
    qmake && make -j2
    sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins
  9. Manage Homebridge integration via deCONZ

    master

    The deCONZ-homebridge.sh script is a background management utility designed to automate the integration between deCONZ and Homebridge on Linux systems. It monitors the deCONZ database for new Zigbee devices and manages the Homebridge configuration, including API keys, bridge IDs, and PINs.

    Core Functionality

    • Automatic Device Discovery: Monitors the deCONZ zll.db for new device timestamps. When new lights are discovered, it waits for discovery to stabilize and then restarts Homebridge to include the new devices.
    • Configuration Management: Automatically generates and maintains the ~/.homebridge/config.json file, ensuring the bridgeid, apikey, and pin match the deCONZ settings.
    • Lifecycle Management: Can transition Homebridge between states: managed, not-managed, disabled, or reset based on database configuration.
    • Service Control: Uses systemctl to manage the homebridge and deconz-homebridge-install services.
  10. Homebridge configuration states in deCONZ database

    master

    The script uses the homebridge key in the deCONZ config2 table to determine how to handle the Homebridge installation. The following values are supported:

    ValueAction
    managedThe script manages the Homebridge configuration, API keys, and service lifecycle.
    not-managedThe script detects an existing Homebridge setup but will not overwrite or manage its configuration.
    disabledThe script stops and disables the homebridge and deconz-homebridge-install services and kills any running Homebridge processes.
    resetThe script stops Homebridge and deletes the persist and config.json files in the Homebridge directory to allow a fresh setup.
    updatedTriggers a restart of the Homebridge process.
  11. Install Homebridge for deCONZ via shell script

    master

    The deCONZ-homebridge-install.sh script automates the installation of the Homebridge environment required to integrate deCONZ with Apple HomeKit.

    Prerequisites

    • deCONZ installed: The script relies on the deCONZ SQLite database (zll.db) to retrieve configuration settings like the REST-API port, proxy settings, and timezone.
    • SQLite3: The script requires sqlite3 to be installed on the system to query the deCONZ database.
    • Internet Connectivity: The script requires access to https://www.phoscon.de to verify connectivity. If a proxy is configured in the deCONZ database, the script will attempt to use it.

    Installation Logic

    The script performs the following tasks:

    1. Environment Check: Verifies if nodejs, npm, homebridge, homebridge-hue, and homebridge-config-ui-x are already installed.
    2. Node.js Management: If Node.js is missing or below version 16.14.2, it installs/updates Node.js using the NodeSource repository.
    3. Component Installation: Uses npm to globally install:
      • homebridge
      • homebridge-lib
      • homebridge-hue
      • homebridge-config-ui-x
      • bonjour-hap (if missing)
    4. Timezone Synchronization: Automatically sets the system timezone to match the timezone stored in the deCONZ database using timedatectl.
    5. Status Reporting: Sends installation status updates (e.g., installing, install-error) back to the deCONZ REST API.