If you want to use zigbee2mqtt with openHAB, please advance to the next level. The following is a far nicer implementation of the same stuff, just with the mqtt2 binding and a new option of zigbee2mqtt
The old stuff, if you prefer the mqtt1 binding and too many tranformations, please go ahead.
Recently io discovered zigbee2mqtt, which made me think of getting rid of my hue bridge and being able to use a large number of cheap sensors. This works pretty well. I already joined 15 devices (including my Osram Smart Plugs which did not behave nicely on the hue bridge.)
I know, openHAB also enjoys a zigbee binding, but i did not try it yet for several reasons. Most important one is my number of devices, this will easily exceed the 35 device limit of the cc2531. With one or more RaspberryPi running Kodi in every floor, i could easily extend to several floor centric zigbee networks.
Back on topic, it works fine. I already ordered some new sensors (about 10€ each) and attached them easily, although the mqtt binding configuration is a bit tricky. (I am no mqtt expert).
As always, hints are welcome.
Here are my results:
- OSRAM Smart+/Lightify Plug:
Switch SmartPlug_TOGGLE "SmartPlug [%s]" <poweroutlet> {mqtt=">[broker:zigbee/SmartPlug/set:command:*:JS(setZigbeeState.js)],<[broker:zigbee/SmartPlug:state:JSONPATH($.state)]"}
- Xiaomi Aqara wireless switch WXKG11LM
String BUTTON_CLICK "BUTTON [%s]" <button> {mqtt="<[broker:zigbee/BUTTON:command:JS(getZigbeeClick.js)]"}
Number BUTTON_VOLTAGE "BUTTON Volt [%d mV]" {mqtt="<[broker:zigbee/BUTTON:state:JSONPATH($.voltage)]"}
Number BUTTON_BATTERY "BUTTON BAT [%.1f %%]" {mqtt="<[broker:zigbee/BUTTON:state:JSONPATH($.battery)]"}
- Xiaomi Aqara water leak sensor SJCGQ11LM
Contact LEAK_STATE "Leak [%s]" <water> {mqtt="<[broker:zigbee/LEAK:state:JS(getZigbeeLeak2Contact.js)]" }
Number LEAK_VOLTAGE "Leak Volt [%d mV]" {mqtt="<[broker:zigbee/LEAK:state:JSONPATH($.voltage)]"}
Number LEAK_BATTERY "Leak BAT [%.1f %%]" {mqtt="<[broker:zigbee/LEAK:state:JSONPATH($.battery)]"}
- Xiaomi Aqara human body movement and illuminance sensor RTCGQ11LM
Switch MD_MOTION "MD Motion [MAP(HM-Sen-MDIR-O-2.map):%s]" <motion> {mqtt="<[broker:zigbee/MD:state:JS(getZigbeeOccupancy2Switch.js)]" }
Number MD_BRIGHTNESS "MD Brightness [%d lumen]" {mqtt="<[broker:zigbee/MD:state:JSONPATH($.illuminance)]"}
- Xiaomi Aqara temperature, humidity and pressure sensor WSDCGQ11LM
Number THPS_TEMP "THPS Temperature [%.1f °C]" <temperature> {mqtt="<[broker:zigbee/THPS:state:JSONPATH($.temperature)]"}
Number THPS_HUMIDITY "THPS Humidity [%d %%]" {mqtt="<[broker:zigbee/THPS:state:JSONPATH($.humidity)]"}
Number THPS_PRESSURE "THPS Pressure [%d mbar]" {mqtt="<[broker:zigbee/THPS:state:JSONPATH($.pressure)]"}
Number THPS_VOLTAGE "THPS Volt [%d mV]" {mqtt="<[broker:zigbee/THPS:state:JSONPATH($.voltage)]"}
Number THPS_BATTERY "THPS Battery [%.1f %%]" {mqtt="<[broker:zigbee/THPS:state:JSONPATH($.battery)]"}
- IKEA TRADFRI LED bulb E27 1000 lumen, dimmable, opal white LED1623G12
Switch IKEAE27_TOGGLE "IKEAE27 [%s]" <light> {mqtt=">[broker:zigbee/IKEAE27/set:command:*:JS(setZigbeeState.js)],<[broker:zigbee/IKEAE27:state:JSONPATH($.state)]", expire="120m,command=OFF"}
Dimmer IKEAE27_DIMM "IKEAE27 Dimm" <light> {mqtt=">[broker:zigbee/IKEAE27/set:command:*:JS(setZigbeeBrightness.js)],<[broker:zigbee/IKEAE27:state:JS(getZigbeeBrightness.js)]"}
I have not converted my other bulbs/lamps (innr, OSRAM, Philips) yet, i need the alert functionality implemented in zigbee2mqtt first.
I will add this one soon:
- Xiaomi Aqara door & window contact sensor MCCGQ11LM
Here are the Javascript transformations (in order of appearance):
- setZigbeeState.js
(function(x){
var result = new Object();
result.state = x;
return JSON.stringify(result);
})(input)
- getZigbeeClick.js
(function(x){
var result = "none";
var json = JSON.parse(x);
try
{
result = json.click;
}
catch(e)
{
result = "none";
}
return result;
})(input)
- getZigbeeLeak2Contact.js
(function(x){
var result = "";
var json = JSON.parse(x);
if (json.leak)
{
result="OPEN";
}
else
{
result="CLOSED";
}
return result;
})(input)
- getZigbeeOccupancy2Switch.js
(function(x){
var result = "";
var json = JSON.parse(x);
if (json.occupancy)
{
result="ON";
}
else
{
result="OFF";
}
return result;
})(input)
- setZigbeeBrightness.js
(function(x){
var brightness = x*255/100;
var result = new Object();
result.brightness = brightness;
return JSON.stringify(result);
})(input)
- getZigbeeBrightness.js
(function(x){
var result;
var json = JSON.parse(x);
result = json.brightness * 100 / 255;
return result;
})(input)