The deconz-cli-plugin provides an API to access devices with ZigBee Home Automation (HA) and ZigBee Light Link (ZLL). It can be used as command line interface (cli) to send and receive raw ZigBee commands with deCONZ software.
As hardware the RaspBee ZigBee Shield for Raspberry Pi is used to directly communicate with the ZigBee devices.
The deconz-cli-plugin requires the deCONZ software.
The deconz-cli-plugin opens a socket on port TCP 5008 and listens for incoming connections. The plugin allows to send commands and receive responses to and from ZigBee devices like Philips Hue lights. The plugin translates the incoming commands to APS-Data and passes the data to the RaspBee firmware.
In the standard Raspbian Linux distribution the serial interface /dev/ttyAMA0 is set up as a serial console, i.e. for boot message output. Since the RaspBee ZigBee firmware uses the same interface to communicate with the control software, the following changes must be done to “free” the UART.
In the file /boot/cmdline.txt:
If present remove the text console=serial0,115200
or console=ttyAMA0,115200
Raspbian wheezy: comment out the following line in /etc/inittab
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Raspian jessie:
sudo systemctl disable serial-getty@ttyAMA0.service
Raspberry Pi3 jessie: in the file /boot/config.txt add the line
enable_uart=1
Reboot
Download and install Qt 4.8
sudo apt-get install libqt4-core
-
Download deCONZ package
wget http://www.dresden-elektronik.de/rpi/deconz/deconz-latest.deb -or- wget http://www.dresden-elektronik.de/rpi/deconz/deconz-2.04.35.deb
-
Install deCONZ package
sudo dpkg -i deconz-2.04.35.deb
-
Download deCONZ development package
wget http://www.dresden-elektronik.de/rpi/deconz-dev/deconz-dev-latest.deb -or- wget http://www.dresden-elektronik.de/rpi/deconz-dev/deconz-dev-2.04.35.deb
-
Install deCONZ development package
sudo dpkg -i deconz-dev-2.04.35.deb
-
Install Qt4 development packages
sudo apt-get install qt4-qmake libqt4-dev
-
(Optional) Install GCFFlasher tool to install new firmware or restart RaspBee
wget http://www.dresden-elektronik.de/rpi/gcfflasher/gcfflasher-latest.deb -or- wget http://www.dresden-elektronik.de/rpi/gcfflasher/gcfflasher-2.10.deb sudo dpkg -i gcfflasher-2.10.deb
-
Compile the plugin
cd libs/zigbee qmake-qt4 && make
-
Copy the plugin to the deConz plugins folder
cp libpilight_plugin.so /usr/share/deCONZ/plugins
-
Optional remove or move the existing rest plugin (because for some strange reason the rest plugin removes bindings on all devices which makes reporting impossible)
mv /usr/share/deCONZ/plugins/libde_rest_plugin.so /usr/share/deCONZ/libde_rest_plugin.so_NOT_USED
-
Copy startup script
sudo cp deconz /etc/init.d sudo chmod +x /etc/init.d/deconz sudo update-rc.d deconz defaults
-
Start deConz (parameter --dbg-info=1 only needed for debug messages). It might be necessary to start with UI when starting and forming the ZigBee network for the first time. Thereafter the UI is not needed anymore.
with UI (requires X-server)
deCONZ --dbg-info=1
without UI
sudo service deconz start
-or-
DISPLAY=:0.0 deCONZ --dbg-info=1
The plugin is started when the deConz software is started. The deConz software must be running before starting pilight.
Run netcat to connect to port 5008. Type help
to show usage.
nc localhost 5008
Command | Description |
---|---|
r <shortaddr> <ep> <cluster> <attrid> |
read attributes |
b <shortaddr> <ep> |
read basic attributes |
b <shortaddr> <ep> <cluster> |
read basic attributes on cluster |
m <profile> <cluster> |
send match descriptor request (discover cluster) |
p <shortaddr> |
permit Joining on device (coordinator = 0) |
zclattr <shortaddr> <ep> <cluster> <command> |
send ZCL attribute request |
zclcmd <shortaddr> <ep> <cluster> <command> |
send ZCL command request |
zclcmdgrp <groupaddr> <ep> <cluster> <command> |
send ZCL command request to group |
zdpcmd <shortaddr> <cluster> <command> |
send ZDP command request |
zclattrmanu <shortaddr> <ep> <cluster> <manufacturer id> <command> |
send ZCL attribute request manufacturer specific |
zclcmdmanu <shortaddr> <ep> <cluster> <manufacturer id> <command> |
send ZCL command request manufacturer specific |
Response | Description |
---|---|
<-LQI 0x84182600xxxxxxxx 06 0 1 0x001FEE00xxxxxxxx 0x4157 1 1 2 01 02 56 | LQI neighbor reponse |
<-ZCL attribute report 0x001FEE00xxxxxxxx 0x0006 1 00 00 10 00 | ZCL attribute report (from cluster 0x0006) |
<-ZCL serverToClient 0x00124B00xxxxxxxx 1 for cluster 0x0500 10 00 00 00 00 00 | ZCL attribute (with extaddr) |
<-ZCL serverToClient 0x3B58 1 for cluster 0x0500 10 00 00 00 00 00 | ZCL attribute (with shortaddr) |
<-APS attr 0x001FEE00xxxxxxxx 5 0x0702 0x0000 0x25 0E DA 76 57 00 00 00 04 00 2A 00 00 00 | APS data |
<-LQI [source addr] [neighborTableEntries] [start] [count] [extaddr] [shortaddr] [device type] [rxOnWhenIdle] [relationship] [permitJoin] [depth] [lqi]
<-APS attr [source extaddr] [endpoint] [cluster] [attributeid] [typeid] [attr value] [...more attributes]
LQI | Description |
---|---|
source addr | LQI neighbor table from |
neighborTableEntries | total table entries |
start | current table entry start index |
count | number of table entries in this frame |
extaddr | table entry extended address |
shortaddr | table entry short address |
device type | 0 = coordinator, 1 = router, 2 = end device, 3 = unknown |
rxOnWhenIdle | receiver on when idle 0 or 1 |
relationship | relationship 0 = neighbor is the parent, 1 = child, 2 = sibling, 3 = None of the above, 4 = previous child |
permitJoin | permit Join 0 = neighbor is not accepting join requests, 1 = accepting join requests |
depth | The tree depth of the neighbor device |
lqi | The estimated link quality (range 0x00 - 0xff) |
Successfully tested with follwing ZigBee devices.
Device | Vendor |
---|---|
Light Philps Hue White | Philips, LWB006 |
Light | OSRAM, Classic B40 TW - LIGHTIFY |
Smart Plug | OSRAM, Plug 01 |
Movement Sensor | Bitron Home, 902010/22 |
Motion Sensor | Philips Hue motion sensor |
Smoke Detektor with siren | Bitron Home, 902010/24 |
Smart Plug with Metering | Bitron Home, 902010/25 |
Thermostat | Bitron Home, 902010/32 |
Switch | ubisys, S2 (5502) |
Button | Philips Hue dimmer switch |
Button | Xiaomi Smart Wireless Switch |
Temperature | Xiaomi Temperature and Humidity Smart Sensor |
Philips Hue Light Can I factory reset a Hue light with the Hue dimmer switch? Yes you can, press and hold the ON and OFF button simultaneously until the LED light on the dimmer switch turns green (Note: the lamp is blinking during this process. Hue Beyond and Hue Phoenix are excluded).
Osram Lightify Light turn the light on and off five times and wait 5 seconds inbetween.
Bitron Video Press and hold the button for 10 seconds.
After a while (rarely and randomly) a device keeps responding with an error status 0xD0 when reading attributes or sending other commands. Sometimes this just gets resolved without doing anything but waiting. However, sometimes it turns out that the device shortaddress has changed for some unknown reason. Oberserving the LQI neibortable entries shows the new shortaddress.
zclattr 0x4157 5 0x0702 0000000004 --> send OK <-APS-DATA.confirm FAILED status 0xD0, id = 0x25, srcEp = 0x01, dstcEp = 0x05, dstAddr = 0x4157 <-LQI 0x00178801xxxxxxxx 07 0 1 0x001FEE00xxxxxxxx 0xA855 1 1 3 01 01 F7 zclattr 0xA855 5 0x0702 0000000004 --> send OK
sudo service deconz stop; sudo GCFFlasher -r; sudo service deconz start
g++ -c -pipe -Wno-attributes -Wall -O2 -Wall -W -D_REENTRANT -fPIC -DDECONZ_DLLSPEC=Q_DECL_IMPORT -DARCH_ARM -DARCH_ARMV7 -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../.. -I../../common -isystem /usr/include -isystem /usr/include/arm-linux-gnueabihf/qt5 -isystem /usr/include/arm-linux-gnueabihf/qt5/QtGui -isystem /usr/include/arm-linux-gnueabihf/qt5/QtNetwork -isystem /usr/include/arm-linux-gnueabihf/qt5/QtCore -Irelease -I/usr/lib/arm-linux-gnueabihf/qt5/mkspecs/linux-g++ -o release/deconz_cli_plugin.o deconz_cli_plugin.cpp
In file included from /usr/include/c++/6/bits/stl_algo.h:59:0,
from /usr/include/c++/6/algorithm:62,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qglobal.h:94,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qnamespace.h:43,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qobjectdefs.h:48,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qobject.h:46,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/qplugin.h:43,
from /usr/include/arm-linux-gnueabihf/qt5/QtCore/QtPlugin:1,
from deconz_cli_plugin.cpp:8:
/usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^
compilation terminated.
Generated Makefile should be modified in the following way:
INCPATH = -I. -isystem /usr/include --> new INCPATH = -I. -I/usr/include
unix:INCLUDEPATH += /usr/include --> new unix:INCLUDEPATH += -I/usr/include
g++ -c -pipe -Wno-attributes -Wall -O2 -Wall -W -D_REENTRANT -fPIC -DDECONZ_DLLSPEC=Q_DECL_IMPORT -DARCH_ARM -DARCH_ARMV7 -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../.. -I../../common -I/usr/include -isystem /usr/include/arm-linux-gnueabihf/qt5 -isystem /usr/include/arm-linux-gnueabihf/qt5/QtGui -isystem /usr/include/arm-linux-gnueabihf/qt5/QtNetwork -isystem /usr/include/arm-linux-gnueabihf/qt5/QtCore -Irelease -I/usr/lib/arm-linux-gnueabihf/qt5/mkspecs/linux-g++ -o release/deconz_cli_plugin.o deconz_cli_plugin.cpp