MQTT warnings with Theengs Gateway generated JSON messages

I am using the Theengs Gateway to query BLE data from my different sensors and sending to OpenHAB through MQTT. I use OH 3.4 installed with openhabian on a raspberry pi v3.

For some of my sensors (Ie.g. a MiFlora plant monitor) the Theengs Gateway sends MQTT messages with different contents: sometimes there’s only temperature, some other there’s also luminosity and so on.

This behaviour floods my openhab log of messages similar to the following

2022-12-28 15:06:02.782 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.lux' in '{"name":"Flower care","id":"C4:7C:8D:65:F5:E6","rssi":-86,"brand":"Xiaomi/VegTrug","model":"MiFlora","model_id":"HHCCJCY01HHCC","moi":0}

where, in this case, the JSONPATH transform complains that in the incoming message there is no lux field.

The configuration of the mqtt thing (I am doing through the UI) is as follows

UID: mqtt:topic:OH-prodBroker:SensorMiflora
label: SensorMiflora
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:OH-prodBroker
location: Mansarda
channels:
  - id: temperature
    channelTypeUID: mqtt:number
    label: temperature
    description: ""
    configuration:
      stateTopic: home1/TheengsGateway/C47C8D65F5E6
      transformationPattern: JSONPATH:$.tempc
      unit: °C
  - id: light
    channelTypeUID: mqtt:number
    label: Light Intensity
    description: Light Intensity
    configuration:
      stateTopic: home1/TheengsGateway/C47C8D65F5E6
      transformationPattern: JSONPATH:$.lux
      unit: lx

The data is transferred to the items correctly. Is there a way to avoid all of these warnings in openhab.log?

EDIT: previously this warning did not occur as I used python scripts that were sending json messages always containing all of the fields.

I asked this previously below but did not get an answer:

Thank you for your quick answer.
It is unfortunate that there is no way to deal with this problem.
Wouldn’t it be possible to broadcast one message per json field?
Instead of sending

{"name":"MJ_HT_V1","id":"4C:65:A8:D0:5E:CE","rssi":-73,"brand":"Xiaomi","model":"Mi Jia round","model_id":"LYWSDCGQ","tempc":20.6,"tempf":69.08,"hum":62.5}

to

home1/TheengsGateway/4C65A8D05ECE

Send each field separately as

home1/TheengsGateway/4C65A8D05ECE/name = MJ_HT_V1
home1/TheengsGateway/4C65A8D05ECE/id = "4C:65:A8:D0:5E:CE"
home1/TheengsGateway/4C65A8D05ECE/rssi = -73
...

Clearly this would imply an increase of traffic, but it could be limited to a list of predefined sensors.

So basically the problem is that the value sometimes gets transmitted, but sometimes it is missing in the JSON, correct?
I have faced a similar issue with some Tuya zigbee buttons that only from time to time provide the battery SOC in the messages causing zigbee2mqtt to send a message without the value.
You may try to use a REGEX and an intersection to ensure your value is present.
Something like:

REGEX:(.*lux.*)∩JSONPATH:$.lux

This way I do not get the warnings in the log as the REGEX prevents the processing of the JSONPATH expression if there is no match.
Feel free to use a more precise pattern, but this was the simplest way to get it working in that situation.

Let’s hope this works for you
Thomas

2 Likes

You can do this by using simplePublishing, note that auto discovery will not work with it.

is it possible to do this with TheengsGateway instead of OMG?
the many warnings in the log are driving me crazy

Not for now, we have very little use of simplePublishing and we are not planning to integrate it into Theengs gateway.
We need to find another way to avoid these warnings.

1 Like