Ignore mqtt messages if json doesn't match

Hi all,

I’ve got Tasmota on my kettle and it sends the current temperature to Openhab using mqtt. I’m using the mqtt1 binding. I know I should migrate to the new one. It’s on my list of things to do, but I’m hoping there’s a quick fix to this in the meantime.

The problem I have is, the temperature is sent in the tele/tasmotaKettle/RESULT topic and the temperature itself is the DpType2Id5 field.

The kettle doesn’t include the DpType2Id5 field in all the messages to the tele/tasmotaKettle/RESULT topic though.

The messages look like.

tele/tasmotaKettle/RESULT {"TuyaReceived":{"Data":"55AA0007001C0101000100050200040000002565010001006604000100670400010093","Cmnd":7,"CmndData":"01010001000502000400000025650100010066040001006704000100","DpType1Id1":0,"1":{"DpId":1,"DpIdType":1,"DpIdData":"00"},"DpType2Id5":37,"5":{"DpId":5,"DpIdType":2,"DpIdData":"00000025"},"DpType1Id101":0,"101":{"DpId":101,"DpIdType":1,"DpIdData":"00"},"DpType4Id102":0,"102":{"DpId":102,"DpIdType":4,"DpIdData":"00"},"DpType4Id103":0,"103":{"DpId":103,"DpIdType":4,"DpIdData":"00"}}}

tele/tasmotaKettle/RESULT {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}

Everything works, but when the shorter messages are received, Openhab throws the following error.

2020-08-05 23:21:16.698 [WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: Invalid path '$.TuyaReceived.DpType2Id5' in '{"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}'
        at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
        at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:137) [bundleFile:?]
        at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [bundleFile:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [org.eclipse.paho.client.mqttv3-1.1.0.jar:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]

The item is configured as

Number KettleTemp {mqtt="<[localhost:tele/tasmotaKettle/RESULT:state:JSONPATH($.TuyaReceived.DpType2Id5)]"}

Is there any way to make Openhab ignore the messages that don’t include DpType2Id5?

yes.

…or - just ignore the warnings until you’ve migrated to V2…!