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
My device is paired with Zigbee2MQTT and I can control it from there
Zigbee2MQTT is connected and writing into my MQTT message broker (mosquitto)
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:
"friendlyName":"Blitzwolf Smart Plug 2",
"powerSource":"Mains (single phase)",
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.
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.
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”
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.
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!