Migrated to MQTT 2.4 binding and had to add things and change item definitions. It took me some time to test it all out and convert the files. Below the new file content as a reference and help to others.
I’m using Zigbee2MQTT (https://koenkk.github.io/zigbee2mqtt/) to bridge Aqara ZigBee sensors to MQTT and bind them to items in OpenHAB.
Currently I’m using:
- motion sensors (RTCGQ11LM)
- contact sensors (MCCGQ11LM)
- water sensors (SJCGQ11LM)
- weather sensors (WSDCGQ11LM)
Please note I’ve changes the names of the MQTT topics under which the ZigBee messages are published using NodeRed with the ZigBee2MQTT Admin panel (or you could do it manually on the filesystem in the config file) see: https://github.com/ben423423n32j14e/zigbee2mqttadminpanel .
MQTT.things
Bridge mqtt:broker:broker “MQTT Broker” [ host=“localhost”, port=1883, secure=false, clientID=“openHAB2” ]
{
// Contact sensors
Thing topic contactsensorlivingroomdoor “ContactSensorLivingRoomDoor” {
Channels:
Type contact : contact “Contact” [ stateTopic=“zigbee2mqtt/ContactLivingRoomDoor”, transformationPattern=“JS:getZigbeeContact2Contact.js”]
Type number : voltage “Voltage” [ stateTopic=“zigbee2mqtt/ContactLivingRoomDoor”, transformationPattern=“JSONPATH:$.voltage”]
Type number : battery “Battery” [ stateTopic=“zigbee2mqtt/ContactLivingRoomDoor”, transformationPattern=“JSONPATH:$.battery”]
}
// Weather sensors
Thing topic weathersensorentrancehallway "WeatherSensorEntranceHallway" {
Channels:
Type number : temperature "Temperature" [ stateTopic="zigbee2mqtt/WeatherEntranceHallway", transformationPattern="JSONPATH:$.temperature"]
Type number : humidity "Humidity" [ stateTopic="zigbee2mqtt/WeatherEntranceHallway", transformationPattern="JSONPATH:$.humidity"]
Type number : pressure "Pressure" [ stateTopic="zigbee2mqtt/WeatherEntranceHallway", transformationPattern="JSONPATH:$.pressure"]
Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/WeatherEntranceHallway", transformationPattern="JSONPATH:$.voltage"]
Type number : battery "Battery" [ stateTopic="zigbee2mqtt/WeatherEntranceHallway", transformationPattern="JSONPATH:$.battery"]
}
//Motion sensors
Thing topic motionsensorentrancehallway "MotionSensorEntranceHallway" {
Channels:
Type switch : motion "Motion" [ stateTopic="zigbee2mqtt/MotionEntranceHallway", transformationPattern="JS:getZigbeeOccupancy2Switch.js"]
Type number : brightness "Brightness" [ stateTopic="zigbee2mqtt/MotionEntranceHallway", transformationPattern="JSONPATH:$.illuminance"]
Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/MotionEntranceHallway", transformationPattern="JSONPATH:$.voltage"]
Type number : battery "Battery" [ stateTopic="zigbee2mqtt/MotionEntranceHallway", transformationPattern="JSONPATH:$.battery"]
}
//Water Sensors
Thing topic watersensormeteringcloset "WaterSensorMeteringCloset" {
Channels:
Type contact : contact "Contact" [ stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JS:getZigbeeLeak2Contact.js"]
Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JSONPATH:$.voltage"]
Type number : battery "Battery" [ stateTopic="zigbee2mqtt/LeakageMeteringCloset", transformationPattern="JSONPATH:$.battery"]
}
}
getZigbeeContact2Contact.js
(function(x){
var result = "";
var json = JSON.parse(x);
if (json.contact)
{
result="CLOSED";
}
else
{
result="OPEN";
}
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)
getZigbeeLeak2Contact.js
(function(x){
var result = "";
var json = JSON.parse(x);
if (json.leak)
{
result="OPEN";
}
else
{
result="CLOSED";
}
return result;
})(input)
MQTT.items
Contact ContactLivingRoomDoor "Woonkamerdeur Contact [%s] " <contact> (GContact, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:contactsensorlivingroomdoor:contact"}
Number VoltContactSensorLivingRoomDoor "Woonkamerdeur Contact Voltage [%d mV] " <energy> (GVoltage, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:contactsensorlivingroomdoor:voltage"}
Number BatteryContactSensorLivingRoomDoor "Woonkamerdeur Contact Batterij [%.1f %%] " <batterylevel> (GBattery, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:contactsensorlivingroomdoor:battery"}
Number TemperatureEntranceHallway "Hal Temperatuur [%.1f °C]" <temperature> (GTemperature, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:weathersensorentrancehallway:temperature"}
Number HumidityEntranceHallway "Hal Vochtigheid [%d %%] " <humidity> (GHumidity, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:weathersensorentrancehallway:humidity"}
Number PressureEntranceHallway "Hal Luchtdruk [%d mbar] " <pressure> (GPressure, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:weathersensorentrancehallway:pressure"}
Number VoltWeatherSensorEntranceHallway "Hal Weersensor Voltage [%d mV] " <energy> (GVoltage, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:weathersensorentrancehallway:voltage"}
Number BatteryWeatherSensorEntranceHallway "Hal Weersensor Batterij [%.1f %%] " <batterylevel> (GBattery, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:weathersensorentrancehallway:battery"}
Switch MotionEntranceHallway "Hal Beweging [%s]" <motion> (GMotion, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:motionsensorentrancehallway:motion" }
Number BrightnessEntranceHallway "Hal Lichtsterkte [%d lumen]" <sun> (GBrightness, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:motionsensorentrancehallway:brightness"}
Number VoltMotionSensorEntranceHallway "Hal Bewegingsensor Voltage [%d mV] " <energy> (GVoltage, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:motionsensorentrancehallway:voltage"}
Number BatteryMotionSensorEntranceHallway "Hal Bewegingsensor Batterij [%.1f %%] " <batterylevel> (GBattery, GEntranceHallway, GZigbee) {channel="mqtt:topic:broker:motionsensorentrancehallway:battery"}
Contact LeakageMeteringCloset "Meterkast Lekkage [%s]" <water> (GWater, GMeteringCloset, GZigbee) {channel="mqtt:topic:broker:watersensormeteringcloset:contact"}
Number VoltWaterSensorMeteringCloset "Meterkast Lekkagesensor Voltage [%d mV] " <energy> (GVoltage, GMeteringCloset, GZigbee) {channel="mqtt:topic:broker:watersensormeteringcloset:voltage"}
Number BatteryWaterSensorMeteringCloset "Meterkast Lekkagesensor Batterij [%.1f %%] " <batterylevel> (GBattery, GMeteringCloset, GZigbee) {channel="mqtt:topic:broker:watersensormeteringcloset:battery"}
Kind regards, Bas