MQTT bindings: how to find out correct topic names

How can I find out the correct topic name of the MQTT State Topic in the Channel config for a MQTT thing. In this case a smart plug being able to measure energy consumption.

Everything seems to work just fine until now

  1. My device is paired with Zigbee2MQTT and I can control it from there
  2. Zigbee2MQTT is connected and writing into my MQTT message broker (mosquitto)
  3. I can see the status updates in a topic called zigbee2mqtt/Blitzwolf Smart Plug 2 using an MQTT explorer

Within that topic I find this structure, including the state attribute:

{"child_lock":"UNLOCK",
"current":0,

"device":
{"applicationVersion":77,
"dateCode":"",
"friendlyName":"Blitzwolf Smart Plug 2",
"hardwareVersion":1,
"ieeeAddr":"0xa4c138a0601c260f",
"manufacturerID":4417,
"manufacturerName":"_TZ3000_amdymr7l",
"model":"TS011F_plug_1",
"networkAddress":22635,
"powerSource":"Mains (single phase)",
"stackVersion":0,
"type":"Router",
"zclVersion":3},

"energy":0.12,
"indicator_mode":"off/on",
"linkquality":120,
"power":0,
"power_outage_memory":"restore",
"state":"ON",
"voltage":228}

What I tried was adding the topic names as:

  • zigbee2mqtt/Blitzwolf Smart Plug 2
  • zigbee2mqtt/Blitzwolf Smart Plug 2/state

But it does not work.

That’s the topic.

That’s one big String in JSON format.

You’ll use zigbee2mqtt/Blitzwolf Smart Plug 2 as the topic and need to create a JSONPATH transform to extract the piece of data from that big message for that one Channel.

There are lots of postings about integrating openHAB with zigbee2mqtt.

1 Like

Hmm I can’t figure it out after research and testing with an online validator where “.voltage” did the trick.

Nothing of the following works, the UI in OH still shows “NULL”. I tried this for the “Incoming Value Transformations” and “Outgoing Value Transformations”

  • JSONPATH:$.voltage
  • JSONPATH:.voltage
  • .voltage

EDIT: I just see that I need to install some transformation service first.

nvm, this was the solution after installing the JSONPATH transformation addon:
Settings -> Other Addons -> Transformation Add-ons -> JSONPath Transformation

Here some tips that might help you:

  • First site to check is zigbee2mqtt.io and search under devices. There you can see all attributes and how they are exposed
  • I recommend to switch zigbee2mqtt to attribute mode so that each attribute is transfered seperately and not as a single json. Everthing is described here with lots of examples https://community.openhab.org/t/zigbee2mqtt-revisited-no-more-ugly-transformations/86362. Your plugs should work just like the OSRAM-examples
  • Another way is to use the autodetect feature of the mqtt-broker in openhab. You can switch it on by turning on “show advanced” in your mqtt-thing and then at the bottom “discovery”. It doesn’t work perfectly with all kinds of devices but maybe it’s an option for you.
1 Like

Indeed a valuable source. Thanks! Noted.

Thanks a ton for that link! I like the option of having the values directly in separated topics without the need of transformations. It worked easily without JSONPATH. The only thing which was not working was updating the Switch state value. Checking your link I saw that the /set is required within the name of the command topic. I would have never thought of that having no topic with that name. Thanks!