I’m currently setting up a new openHAB3 environment.
I decided to use zigbee2mqtt for ZigBee devices and want to create a matching mqtt.things file for openHAB.
This is my mqtt.things file I set up for an air quality sensor:
Bridge mqtt:broker:mosquitto1 [ host="127.0.0.1", secure=false, username="openhab", password="XXX" ]
//Frient Air Quality Sensor - Develco AQSZB-110
Thing mqtt:topic:frientairqual1 "Frient Air Quality Sensor" (mqtt:broker:mosquitto1){
Channels:
Type number : voc "Measured VOC value" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.voc"]
Type number : temperature "Measured temperature value" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.temperature"]
Type number : battery "Remaining battery in %" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.battery"]
Type switch : battery_low "Indicates if the battery of this device is almost empty" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.battery_low"]
Type string : air_quality "Measured air quality" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.air_quality"]
Type number : linkquality "Link quality (signal strength)" [ stateTopic="zigbee2mqtt/0x0015bc00360010b9", transformationPattern="JSONPATH:$.linkquality"]
}
Is it possible to set a “global stateTopic” for a Thing or to use variables? So I need to set the device-id one time per thing?
You can do it with one (!) string channel by linking multiple Items to this channel.
Then add the JSONPATH statement as profile. Type of Item can differ from string, but the channel must be of type string, as it keeps the complete JSON object.