MQTT JSONPATH Issue with changing exising values to null

Im having an issue with ZbBridge running tasmota. I have a number of devices registered to the bridge but they all send updates on the same MQTT publish path.

When it publishes on this path
tele/tasmota_zbGateway1/SENSOR = {“ZbReceived”:{“0x7294”:{“Device”:“0x7294”,“Name”:" Office_Temp",“Temperature”:23.88,“Humidity”:65.49,“Endpoint”:1,“LinkQuality”:157}}}

I get my temperature updated in openhab and it works fine until another device updates.
tele/tasmota_zbGateway1/SENSOR = {“ZbReceived”:{“0xFF6C”:{“Device”:“0xFF6C”,“Name”:" Wardrobe_PIR",“Illuminance”:6,“Occupancy”:1,“Endpoint”:1,“LinkQuality”:13}}}

At this point the first temp value goes to null as it received an update on the published path but there was no entry for the temperature so in openhab they all go blank.

My Items are as follows any help would be great as there are no errors listed in the logs.

Number ZbWardrobe_Occupancy “Wardrobe PIR [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.Occupancy)]" }
Number ZbWardrobe_Illuminance “Wardrobe PIR Illuminance [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.Illuminance)]" }
Number ZbWardrobe_LinkQA “Wardrobe PIR Link Quality [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.LinkQuality)]" }
Number ZbWardrobe_BatteryVoltage “Wardrobe PIR Battery Volts [%.2f V]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.BatteryVoltage)]" }
Number ZbWardrobe_BatteryPercentage “Wardrobe PIR Battery [%d %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.BatteryPercentage)]" }

Number ZbOffice_Temp “Office Temp [%.1f C]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.Temperature)]" }
Number ZbOffice_Humidity “Office Humidity [%.2f %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.Humidity)]" }
Number ZbOffice_LinkQA “Office Link Quality [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.LinkQuality)]" }
Number ZbOffice_BatteryVoltage “Office Temp Battery Volts [%.2f V]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.BatteryVoltage)]" }
Number ZbOffice_BatteryPercentage “Office Temp Battery [%d %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.BatteryPercentage)]" }

It looks like you are using the V1 MQTT binding, rather than V2. Did you mean to do that? If you’re just starting you should use V2, as for configuration will then be valid for the upcoming openHAB 3.

Assuming you change to the V2 binding, you can chain two transformations together: REGEX first then JSONPATH. See: MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters

Yes im using V1 binding but i cant see how V2 will fix this issue, Is this working as expected? If a Json message does not include a value for an item does OPENHAB then change it to null?

It doesn’t change it to null for me - openHAB just complains with a warning in the logs, but leaves the existing value of the Item alone.

Use MQTT v2 it will help alot let us know if you need help

Number ZbWardrobe_Occupancy “Wardrobe PIR [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.Occupancy)]" }
Number ZbWardrobe_Illuminance “Wardrobe PIR Illuminance [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.Illuminance)]" }
Number ZbWardrobe_LinkQA “Wardrobe PIR Link Quality [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.LinkQuality)]" }
Number ZbWardrobe_BatteryVoltage “Wardrobe PIR Battery Volts [%.2f V]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.BatteryVoltage)]" }
Number ZbWardrobe_BatteryPercentage “Wardrobe PIR Battery [%d %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0xFF6C.BatteryPercentage)]" }

Number ZbOffice_Temp “Office Temp [%.1f C]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.Temperature)]" }
Number ZbOffice_Humidity “Office Humidity [%.2f %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.Humidity)]" }
Number ZbOffice_LinkQA “Office Link Quality [%d]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.LinkQuality)]" }
Number ZbOffice_BatteryVoltage “Office Temp Battery Volts [%.2f V]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.BatteryVoltage)]" }
Number ZbOffice_BatteryPercentage “Office Temp Battery [%d %%]” { mqtt="<[DOCKERMQTT:tele/tasmota_zbGateway1/SENSOR:state:JSONPATH($…0x7294.BatteryPercentage)]" }

No it doesn’t.
I don’t think it would actually move us any further forward, but the ‘void’ state for an Item is either NULL or UNDEF.
NULL usually signifies the Item has been reinitialized for some reason, while UNDEF is generally what a binding should set to indicate “unknowable” because there was bad comms or suchlike. So it can be useful distinguishing which exactly.

However I would not like to assume v1 MQTT binding follows these guidelines. Your events.log should show you what is really going on, but I don’t think it helps.

This thread covers the same ground

The number of people who will be able to help with MQTT v1 issues left is small and getting smaller by the day. But I do know that the MQTT 1 binding config supports an optional REGEX filter you can define at the end of the config. If the message doesn’t match the REGEX the message will be ignored for that Item.

The link hafniumzinc posted is how to achieve the same thing in the 2.x version of the binding.

It used to be the case that if the JSONPATH didn’t match anything it would return the whole JSON String. I don’t know if that is still the case.

How do you set tasmota to send each zb device out on its own topic?

Thank you all I will migrate to v2, I just have a heap of devices so it was going to take a while to migrate

v2 MQTT will help you.

It’s a pain to migrate, but once it’s done it is much more flexible.

You can use direct JSONpath transformation for each channel and the problem will be gone!

Check out the V1 to V2 migration information on this page:

Here is an example of how it may look like and work.

You need the regex and jsonpath transformations installed.

Things file

Bridge mqtt:broker:MyServer [ host ="192.168.1.128", secure =false, username ="open", password ="wide" , clientID ="dentist" ]
{

    Thing topic Office "Zigbee Gateway Office" @ "Office" [ availabilityTopic ="tele/tasmota_zbGateway1/LWT", payloadAvailable ="Online", payloadNotAvailable ="Offline"] {
    Channels:
        Type number : temperature "Office Temperature [%.0f °C]"          [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0x7294.*)∩JSONPATH:$.ZbReceived.0x7294.Temperature"  ]
        Type number : Humidity "Office Humidity [%.2f %%]"                [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0x7294.*)∩JSONPATH:$.ZbReceived.0x7294.Humidity"  ]
        Type number : LinkQA "Office Link Quality [%d]"                   [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0x7294.*)∩JSONPATH:$.ZbReceived.0x7294.LinkQuality"  ]
        Type number : BatteryVoltage "Office Temp Battery Volts [%.2f V]" [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0x7294.*)∩JSONPATH:$.ZbReceived.0x7294.BatteryVoltage"  ]
        Type number : BatteryPercentage "Office Temp Battery [%d %%]"     [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0x7294.*)∩JSONPATH:$.ZbReceived.0x7294.BatteryPercentage"  ]
      }

    Thing topic Wardrobe "Zigbee Gateway Wardrobe" @ "Office" [ availabilityTopic ="tele/tasmota_zbGateway1/LWT", payloadAvailable ="Online", payloadNotAvailable ="Offline"] {
    Channels:
        Type number : temperature "Wardrobe Temperature [%.0f °C]"          [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0xFF6C.*)∩JSONPATH:$.ZbReceived.0xFF6C.Temperature"  ]
        Type number : Humidity "Wardrobe Humidity [%.2f %%]"                [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0xFF6C.*)∩JSONPATH:$.ZbReceived.0xFF6C.Humidity"  ]
        Type number : LinkQA "Wardrobe Link Quality [%d]"                   [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0xFF6C.*)∩JSONPATH:$.ZbReceived.0xFF6C.LinkQuality"  ]
        Type number : BatteryVoltage "Wardrobe Temp Battery Volts [%.2f V]" [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0xFF6C.*)∩JSONPATH:$.ZbReceived.0xFF6C.BatteryVoltage"  ]
        Type number : BatteryPercentage "Wardrobe Temp Battery [%d %%]"     [ stateTopic ="tele/tasmota_zbGateway1/SENSOR", transformationPattern ="REGEX:(.*0xFF6C.*)∩JSONPATH:$.ZbReceived.0xFF6C.BatteryPercentage"  ]
      }
}

Items

Number   ZigbeeGatewayOfficeTemperature         "Office temperature [%.0f °c]"         {channel="mqtt:topic:MyServer:Office:temperature"}
Number   ZigbeeGatewayOfficeHumidity            "Office humidity [%.2f %%]"            {channel="mqtt:topic:MyServer:Office:Humidity"}
Number   ZigbeeGatewayOfficeLinkQA              "Office link quality [%d]"             {channel="mqtt:topic:MyServer:Office:LinkQA"}
Number   ZigbeeGatewayOfficeBatteryVoltage      "Office temp battery volts [%.2f v]"   {channel="mqtt:topic:MyServer:Office:BatteryVoltage"}
Number   ZigbeeGatewayOfficeBatteryPercentage   "Office temp battery [%d %%]"          {channel="mqtt:topic:MyServer:Office:BatteryPercentage"}

Number   ZigbeeGatewayWardrobeTemperature         "Wardrobe temperature [%.0f °c]"         {channel="mqtt:topic:MyServer:Wardrobe:temperature"}
Number   ZigbeeGatewayWardrobeHumidity            "Wardrobe humidity [%.2f %%]"            {channel="mqtt:topic:MyServer:Wardrobe:Humidity"}
Number   ZigbeeGatewayWardrobeLinkQA              "Wardrobe link quality [%d]"             {channel="mqtt:topic:MyServer:Wardrobe:LinkQA"}
Number   ZigbeeGatewayWardrobeBatteryVoltage      "Wardrobe temp battery volts [%.2f v]"   {channel="mqtt:topic:MyServer:Wardrobe:BatteryVoltage"}
Number   ZigbeeGatewayWardrobeBatteryPercentage   "Wardrobe temp battery [%d %%]"          {channel="mqtt:topic:MyServer:Wardrobe:BatteryPercentage"}

These items were created automatically using the openhab vscode extension took 10 sec

Thank you guys, after many hours of migrating V2 of MQTT does look like its fixed the issue. My Things file is 180 lines long which is why i think i was putting it off.

Hi, i have tried adding the REGEX to my transforms but still get errors in the logs when anything updates.
can you please confirm the character between the ) and the JSON also?

Also once the REGEX is working i think i get

∩ is not N or n Intersection (set theory) - Wikipedia

Good news is TASMOTA has changed some stuff in the new release so you can change things in tasmota to make it easier. You will no longer need the regex to check

SetOption89

Configure MQTT topic for Zigbee devices (also see SensorRetain)
0 = single tele/%topic%/SENSOR topic (default)
1 = unique device topic based on Zigbee device ShortAddr
Example: tele/Zigbee/5ADF/SENSOR = {“ZbReceived”:{“0x5ADF”:{“Dimmer”:254,“Endpoint”:1,“LinkQuality”:70}}}

SetOption100

remove Zigbee ZbReceived value from {“ZbReceived”:{xxx:yyy}} JSON message
0 = disabled (default)
1 = enabled

{“0x5ADF”:{“Dimmer”:254,“Endpoint”:1,“LinkQuality”:70}}

Channel would look like

Type number : Light "Wardrobe Light [%d %%]" [ stateTopic ="tele/Zigbee/5ADF/SENSOR", transformationPattern ="JSONPATH:$.0x5ADF.Dimmer"  ]

You have an invalid path in the json string

If it can’t find the path that is the error

It can’t find BatteryVoltage in the pir because tasmota is not sending the data

For some reason when i take the ZbReceived out of the JSON path the errors go away so i have removed this and no all of the errors look to have gone.

Thanks for your example

Thanks i will try looking at these options.

Thanks denominator the option 89 has 100% fixed the issue i have no more errors in the logs anymore.

1 Like