Precheck the MQTT payload / problem with jsonpath

Hi Folks,

i have a small issue using Xiaomi Sensors with Sonoff ZbBridge and receiving the sensor date via MQTT in OpenHAB 3.

The Thing and Channel configuration is working fine i can receive the data.
Im Using JSONPATH to receive the needed value from the json string.

transformationPattern: JSONPATH:$.ZbReceived.Tp_GstKlo.Contact

…one of the behavior of Tasmota is that it is sending payloads for different “events” on the same MQTT topic!
The result is, that there are not always the expected values in the payload.

Here is an example:
Expected payload with the needed “Contact” value:
{ "ZbReceived": { "Fr_GsKlo": { "Device": "0xA8D1", "Name": "Fr_GsKlo", "Contact": 1, "Endpoint": 1, "LinkQuality": 92 } } }

and then there are sometimes payloads like this:
{ "ZbReceived": { "Fr_GsKlo": { "Device": "0xA8D1", "Name": "Fr_GsKlo", "BatteryVoltage": 3, "BatteryPercentage": 98, "Endpoint": 1, "LinkQuality": 63 } } }

As you can see there is no “Contact” value.
The result is that i get a lot of warnings like this:
Executing the JSONPATH-transformation failed: Invalid path '$.ZbReceived.Fr_GsKlo.Contact' in '{"ZbReceived":{"Fr_GsKlo": "Device":"0xA8D1","Name":"Fr_GsKlo","BatteryVoltage":3,"BatteryPercentage":98,"Endpoint":1,"LinkQuality":63}}}'

Now my question is:
is it somehow possible to “pre-check” the payload and discard the payload in case the needed value is not there?
I would really like to get rid of these warnings.


1 Like

Yes, use the REGEX Transformation Service, then chain the JSONPATH Transformation Service afterwards.


you have to chain with REGEX transformation.
First a REGEX transformation of the payload and then the JSON transformation afterwards.
I don’t have the exact nomenclature at hand, but if Noone else can support, I will look into it tomorrow.

1 Like

Hey guys,

many thanks for the replay!
And dear god it seems like i was to stupid to search for the the right stuff here.
Sorry for creating double threads…

Anyway the hint with REGEX seems to work fine:
transformationPattern: REGEX:(.*Contact.*)∩JSONPATH:$.ZbReceived.Tp_GstKlo.Contact


1 Like