Zigbee2Tasmota - MQTT - JSONPATH

Hey guys,

I need a little help with a new device. I want to use Zigbee devices and I don´t want to stick something like a USB device directly to my server.
I stumbled over the projekt Zigbee2Tasmota. This project can use the sonoff zigbee bridge to act as a zigbee coordinator and turn the values into mqtt messages.
So I bought a sonoff zigbee bridge and a sonoff zigbee tem/hum sensor.
Then I flashed the bridge with the proper tasmota image and it´s working fine, the sensor sends it´s values to the bridge.
But now I´m at a hurdle I cannot step over.

The Zigbee2Tasmota will send all value in strings like this:

12:19:03 MQT: tele/tasmota_zigbee/SENSOR = {"ZbReceived":{"0xB426":{"Device":"0xB426","Name":"TempHumWohnzimmer","Humidity":57.5,"Endpoint":1,"LinkQuality":100}}}

The sensor device adress is 0xB426 and I want to extract the temp and the hum values.
My problem is, that all sensors will use the same mqtt topic “tele/tasmota_zigbee/SENSOR” and the separation has to use the device adress.

By using the PaperUI I made a thing for the Zigbee2Tasmota bridge. And in these thing I tried to make channels for each value I need. I think the separation has to work with JSONPATH but I don´t know how.


Here´s the log entry:
12:32:34.946 [WARN ] [tt.generic.ChannelStateTransformation] - Transformation service “JSONPATH for pattern $.0xB426.Humidity” not found!
12:32:34.948 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Incoming payload ‘{“ZbReceived”:{“0xB426”:{“Device”:“0xB426”,“Name”:“TempHumWohnzimmer”,“Temperature”:23.54,“Humidity”:58.17,“Endpoint”:1,“LinkQuality”:97}}}’ not supported by type ‘NumberValue’

I will thankful for some hints.

Tank you

  • Platform information:
    • Hardware: Intel Pentium (don´t know the exact version)
    • OS: Ubuntu 20.04
    • official Dockerbuild
    • openHAB version: 2.5.10

I can only help you in theory :wink:

First you probably need to install the jsonpath transformation service. in paperui AddOns, Transformation
Second you somehow need to combine a regex with your jsonpath transformation.
Like: Only if json string contains value “0xB426” then use jsonpath to store temp. And another one for hum value. I tried the exact same thing in the past and it didn’t work on my side. No clue why. At least the doc says it’s possible

The chaining does work, but only after restarting the entire OH installation. I had the same issue and found some post on the forum stating that it only worked after a restart of OH. Unlike other changes, reloading the file or tweaking the PaperUI didn’t work. No idea why.

1 Like

See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters

I’m not certain Stefan’s idea will work because if the JSONPATH doesn’t match anything it returns the whole JSON String. You want to return nothing if the device ID isn’t present. To achieve that use the REGEX filter first chained to the JSONPATH.

I could be wrong on that point though. I’ve never tried to chain two JSONPATHs together like this.

Your JSONpath is wrong.

Try this:

$.ZbReceived.0xB426.Temperature

etc.

Other devices should have a different address than 0xB426 so you should be able to easily make all the channels you need.

I like to use this website to check my JSONpath: https://jsonpath.com/

To see the exact messages sent via MQTT, I recommend this software: http://mqtt-explorer.com/

Cheers

Thank you all for the tips, it’s working now.

Nick brought me to the right way and SpaceGlider did even post the hole solution.

Here how the settings for others with the same problem:

My mqtt message is:

12:19:03 MQT: tele/tasmota_zigbee/SENSOR = {"ZbReceived":{"0xB426":{"Device":"0xB426","Name":"TempHumWohnzimmer","Humidity":57.5,"Endpoint":1,"LinkQuality":100}}}

the mqtt is:
tele/tasmota_zigbee/SENSOR

and the right JSONPATH is:
JSONPATH:$.ZbReceived.0xB426.Humidity

As explanation: The mqtt path ends with the word sensor, in the jsonpath every step of {} has to be mentioned. In my case the first step was “ZbReceived”, the second “0xB426” and the last brackets are the values - Humidity or Temperture …

Thank you all, this forum is really great.

Well done!

Note that, if you add more sensors, and they publish on the same topic, your log will start to show warnings for what you’ve just configured because it will read the published message, but not find the right sensor ID. Your can ignore this, but if it bothers you then you will need to implement a chained transformation with REGEX first, then JSONPATH, as mentioned by @rlkoshak in his post above.

OK hafniumzinc,
I’ll keep an eye on that and try to bring the regex to work.

Thank you.

Something like

REGEX:(.*0xB426.*)∩JSONPATH:$.ZbReceived.0xB426.Temperature

∩ is not N or n

1 Like

You may review this https://community.openhab.org/t/success-with-sonoff-zigbee-bridge-and-zigbee-binding/104985/9 - help me a lot.