MQTT ignore if json path missing

Tags: #<Tag:0x00007f17446acef0> #<Tag:0x00007f17446ace28>

Hi,
I’m using the MQTT binding to monitor the temperature of my kettle that’s running Tasmota.

It works well, but Tasmota doesn’t include the temperature with every update to the topic.

For example, here is an example with the temperature included (DpType2Id5).

tele/tasmotaKettle/RESULT {"TuyaReceived":{"Data":"55AA0007001C010100010005020004000000216501000100660400010067040001008F","Cmnd":7,"CmndData":"01010001000502000400000021650100010066040001006704000100","DpType1Id1":0,"1":{"DpId":1,"DpIdType":1,"DpIdData":"00"},"DpType2Id5":33,"5":{"DpId":5,"DpIdType":2,"DpIdData":"00000021"},"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"}}}

and here is an example of an update to the same topic that doesn’t include the temperature.

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

I tend to think this is an issue with Tasmota not being consistant, but the issue is, it’s causing my Openhab logs to fill with the following error.

2021-01-18 15:29:36.934 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.TuyaReceived.DpType2Id5' in '{"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}'

Is there a way to tell Openhab not to error if DpType2Id5 is missing from the MQTT data?

A bit of extra info, in case it helps.

My thing is:

   Thing topic KettleTemp "KettleTemp" {
   Channels:
      Type number : PowerUsage  [ stateTopic="tele/tasmotaKettle/RESULT", transformationPattern="JSONPATH:$.TuyaReceived.DpType2Id5" ]
   }

and my item is:

Number KettleTemp { channel="mqtt:topic:MQTTBroker:KettleTemp:PowerUsage" }

root@openhab2.walker.home:~$ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)

root@openhab2.walker.home:~$ apt-cache policy openhab2
openhab2:
  Installed: 2.5.10-1

root@openhab2.walker.home:~$ apt-cache policy openhab2-addons
openhab2-addons:
  Installed: 2.5.10-1

It’s only a WARN, not an error, so you can safely ignore it.

However, you can get openHAB to filter out using REGEX. Check this thread:

Instead of filtering out the logs which will likely suppress this warning at other times where you might want it, chain a REGEX transformation to look to see if the element is present before the JSONPATH transformation. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters.

Am I shadow banned?!

I don’t think there is such a thing on this forum. What are you seeing that makes you think something is wrong?

Oh, wait, I replied and didn’t see that you posted the same thing already. Maybe that is what you are referring to?

Yes, that’s right!