MQTT thing setup with json HELP!

Good Evening,

I have received a Sonoff Zigbee bridge as a gift for christmas.
Today i flashed it with Tasmota and im trying to link the mqtt data to items in openhab.
Heres my current setup but it doesnt seem to be working.

Tasmota outputs this.

17:15:06.934 RSL: tele/Zigbee_Bridge/SENSOR = {"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","Temperature":20.84,"Humidity":50.18,"Endpoint":1,"LinkQuality":92}}}

Items

Number Kids_Bedroom_Temperature  "Temperature [%.2f Ā°C]"  <temperature>   { channel="mqtt:topic:Kids_Bedroom_Sensor:temperature" }
Number Kids_Bedroom_Humidity     "Humidity [%.2f %%]"     <humidity>      { channel="mqtt:topic:Kids_Bedroom_Sensor:humidity" }

Things

Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.Temperature" ]
        Type number : humidity           [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.Humidity" ]
        Type number : voltage            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.voltage" ]
        Type number : battery            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.battery" ]
        Type number : linkquality        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.linkquality" ]

Sitemap

Text item=Kids_Bedroom_Temperature label="Bedroom Temperature [%.1f Ā°C] " icon="temperature"
Text item=Kids_Bedroom_Humidity label="Humidity [%.1f %%]" icon="humidity"

Can anyone see what im doing wrong?

Based on

{
   "ZbReceived":{
      "0xB85C":{
         "Device":"0xB85C",
         "Name":"Kids_Bedroom_Sensor",
         "Temperature":20.84,
         "Humidity":50.18,
         "Endpoint":1,
         "LinkQuality":92
      }
   }
}

Your transformation needs to be

transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Temperature"

and so on for your other properties. That would make your Thing

Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Temperature" ]
        Type number : humidity           [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Humidity" ]
        Type number : linkquality        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.LinkQuality" ]

I have removed battery and voltage because they donā€™t exist in your JSON stringā€¦

1 Like

I am currently running 2.4.0-1

Openhab logs are showing no activity regarding this item and thing apart from being added and linked.

All my other mqtt devices and working as they should so its not a broker or connection issue.

I have altered my files and will see what happens when the next string is sent.

Note Iā€™ve just changed your last Channel as it had capitalisation errors.

In the things fule should the type ā€˜numberā€™ be a differet colour like it would be if it was a switch say for instance?

Depends on your code editor and plugins, I assume. Iā€™m using Visual Studio Code with the openHAB plugin, and hereā€™s an example from mine:

image

Iā€™ve just tried your setup

Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature [
            stateTopic="tele/Zigbee_Bridge/SENSOR",
            transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Temperature"
        ]
        Type number : humidity [
            stateTopic="tele/Zigbee_Bridge/SENSOR",
            transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Humidity"
        ]
        Type number : linkquality [
            stateTopic="tele/Zigbee_Bridge/SENSOR",
            transformationPattern="JSONPATH:$.ZbReceived.0xB85C.LinkQuality"
        ]
}

with Items

Number Temperature "Number value" {channel="mqtt:topic:Kids_Bedroom_Sensor:temperature"}
Number Humidity "Number value" {channel="mqtt:topic:Kids_Bedroom_Sensor:humidity"}
Number Linkquality "Number value" {channel="mqtt:topic:Kids_Bedroom_Sensor:linkquality"}

And itā€™s all working fine for me when sending your JSON string to tele/Zigbee_Bridge/SENSOR

something in my setup still is not working correctly and i cant put my finger on it!
i wonder if i need to use the friendly name rather than the device name?

Your OP showed your Things file configuration with a missing final }

I presumed that was just a copy/paste error - maybe something to check?

i think this is correct?

Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.0xB85C.Temperature" ]
        Type number : humidity           [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.Kids_Bedroom_Sensor.0xB85C.Humidity" ]
        Type number : voltage            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.BatteryVoltage" ]
        Type number : battery            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.BatteryPercentage" ]
        Type number : linkquality        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.LinkQuality" ]
        
}

@Taffy - in your original post the data shown doensā€™t include any data for ā€œVoltageā€ or ā€œBatteryā€, so if it isnā€™t in the data being sent by your sensor, you are not going to be able to parse it out of the air. This was mentioned already by @hafniumzincin his first post.

You also still have all of your transformations incorrect. @hafniumzinc showed them correct per your posted data in two different posts. Iā€™d suggest using those.

it sends battery Percentage and voltage on a seperate line. this is why i didnt include it.
i have also tried the transformations @hafniumzinc showed me and they unfortunatly didnt work so i was just trying a few combinations.

heres is my setup after altering fully from what @hafniumzinc said

tasmota output

19:43:18.809 MQT: tele/Zigbee_Bridge/SENSOR = {"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","Temperature":21.09,"Humidity":61.57,"Endpoint":1,"LinkQuality":100}}}
19:43:24.512 MQT: tele/Zigbee_Bridge/SENSOR = {"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","BatteryVoltage":3.2,"BatteryPercentage":100,"Endpoint":1,"LinkQuality":105}}}

items

Number Kids_Bedroom_Temperature  "Temperature [%.1f Ā°C]"  <temperature>   { channel="mqtt:topic:Kids_Bedroom_Sensor:temperature" }
Number Kids_Bedroom_Humidity     "Humidity [%.1f %%]"     <humidity>      { channel="mqtt:topic:Kids_Bedroom_Sensor:humidity" }
Number Kids_Bedroom_LinkQuality  "Link Quality [%d]"      <network>       { channel="mqtt:topic:Kids_Bedroom_Sensor:linkquality" }
Number Kids_Bedroom_Voltage      "Voltage [%d mV]"        <energy>        { channel="mqtt:topic:Kids_Bedroom_Sensor:voltage" }
Number Kids_Bedroom_Battery      "Battery [%.1f %%]"      <battery>       { channel="mqtt:topic:Kids_Bedroom_Sensor:battery" }

things

Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Temperature" ]
        Type number : humidity           [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.Humidity" ]
        Type number : voltage            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.BatteryVoltage" ]
        Type number : battery            [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.BatteryPercentage" ]
        Type number : linkquality        [ stateTopic="tele/Zigbee_Bridge/SENSOR",  transformationPattern="JSONPATH:$.ZbReceived.0xB85C.LinkQuality" ]
        
}

sitemap

Text item=Kids_Bedroom_Temperature label="Bedroom Temperature [%.1f Ā°C] " icon="temperature"
               Text item=Kids_Bedroom_Humidity label="Humidity [%.1f %%]" icon="humidity"

still no activity in openhab. using MQTTOOL to make sure messages are being sent and received, which they are so the problem must lie in my configs.

You may be hitting the known bug where Things files arenā€™t correctly parsed by openHAB, especially as youā€™re still on OH2.4. Easiest thing to do is restart openHAB.

Thank you for that, it is now showing all relevant data.
im only on 2.4 still because when i tried to update to latest stable version all the mqtt items wouldnt work as id not brought them all upto date, which im currently in the process of doing.

Glad to hear you now have this working. One thing further:

This seems very strange to me. You are sending different data to the same mqtt topic? I think what is going to happen here is this:

1.You receive the first data on ā€œtele/Zibbee_Bridge/SENSRā€ as

{"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","Temperature":21.09,"Humidity":61.57,"Endpoint":1,"LinkQuality":100}}}

You will populate temp, humidity, and link quality, but have errors trying to transform voltage and battery since they donā€™t exist in your data

2 You recevie the second data on ā€œtele/Zigbee_Bridge/SENSORā€ as

{"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","BatteryVoltage":3.2,"BatteryPercentage":100,"Endpoint":1,"LinkQuality":105}}}

You will populate voltage, battery and link quality, but receive errors trying to transform temp and humidity since those donā€™t exist in your data.

I would suggest creating two separate topics for these two data sets.

Or you could use the REGEX Transformation Service to filter the incoming JSON, to that only the relevant strings get sent to the JSONPATH Transformation.

For one of the transformations, this would look like:

transformationPattern="REGEX:(.*Temperature.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.Temperature"
2 Likes

Didnā€™t know that was a thingā€¦ Thanks for sharing!

so if i was to use this Regex for say Humidity would i just change the two parts that say Temperature to Humidity?

Yes - change them to the exact spelling of what you want to extract from your JSON file.

1 Like

Found myself a new issue now!
I have added additional sensors to the zigbee bridge. All sensors are outputting mqqt data from the bridge. I was reading the tasmota zigbee documentation and it stated by using the command SetOption89 1 each sensor could have its own mqtt topic which is great but now nothing is reporting like it should on the openhab side. nothing even pops up on the log when there is incoming mqqt data.

So here is the tasmota outputs

17:46:27.058 MQT: tele/Zigbee_Bridge/CD15/SENSOR = {"ZbReceived":{"0xCD15":{"Device":"0xCD15","Name":"Living_Room_Sensor","Humidity":60.82,"Endpoint":1,"LinkQuality":58}}}
17:44:52.771 MQT: tele/Zigbee_Bridge/B85C/SENSOR = {"ZbReceived":{"0xB85C":{"Device":"0xB85C","Name":"Kids_Bedroom_Sensor","Temperature":18.41,"Endpoint":1,"LinkQuality":86}}}

things

Thing mqtt:topic:Living_Room_Sensor "Living Room Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic=" tele/Zigbee_Bridge/CD15/SENSOR",  transformationPattern="REGEX:(.*Temperature.*)āˆ©JSONPATH:$.ZbReceived.0xCD15.Temperature" ]
        Type number : humidity           [ stateTopic=" tele/Zigbee_Bridge/CD15/SENSOR",  transformationPattern="REGEX:(.*Temperature.*)āˆ©JSONPATH:$.ZbReceived.0xCD15.Humidity" ]
        Type number : voltage            [ stateTopic=" tele/Zigbee_Bridge/CD15/SENSOR",  transformationPattern="REGEX:(.*BatteryVoltage.*)āˆ©JSONPATH:$.ZbReceived.0xCD15.BatteryVoltage" ]
        Type number : battery            [ stateTopic=" tele/Zigbee_Bridge/CD15/SENSOR",  transformationPattern="REGEX:(.*BatteryPercentage.*)āˆ©JSONPATH:$.ZbReceived.0xCD15.BatteryPercentage" ]
        Type number : linkquality        [ stateTopic=" tele/Zigbee_Bridge/CD15/SENSOR",  transformationPattern="REGEX:(.*LinkQuality.*)āˆ©JSONPATH:$.ZbReceived.0xCD15.LinkQuality" ]
        
}
Thing mqtt:topic:Kids_Bedroom_Sensor "Kids Sensor" (mqtt:broker:MQTTBroker) {
    Channels:
        Type number : temperature        [ stateTopic="tele/Zigbee_Bridge/B85C/SENSOR",  transformationPattern="REGEX:(.*Temperature.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.Temperature" ]
        Type number : humidity           [ stateTopic="tele/Zigbee_Bridge/B85C/SENSOR",  transformationPattern="REGEX:(.*Humidity.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.Humidity" ]
        Type number : voltage            [ stateTopic="tele/Zigbee_Bridge/B85C/SENSOR",  transformationPattern="REGEX:(.*BatteryVoltage.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.BatteryVoltage" ]
        Type number : battery            [ stateTopic="tele/Zigbee_Bridge/B85C/SENSOR",  transformationPattern="REGEX:(.*BatteryPercentage.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.BatteryPercentage" ]
        Type number : linkquality        [ stateTopic="tele/Zigbee_Bridge/B85C/SENSOR",  transformationPattern="REGEX:(.*LinkQuality.*)āˆ©JSONPATH:$.ZbReceived.0xB85C.LinkQuality" ]
        
}

items

Number Kids_Bedroom_Temperature  "Temperature [%.1f Ā°C]"  <temperature>   { channel="mqtt:topic:Kids_Bedroom_Sensor:temperature" }
Number Kids_Bedroom_Humidity     "Humidity [%.1f %%]"     <humidity>      { channel="mqtt:topic:Kids_Bedroom_Sensor:humidity" }
Number Kids_Bedroom_LinkQuality  "Kids Bedroom Link Quality [%d]"      <network> (gALLLinkQuality)      { channel="mqtt:topic:Kids_Bedroom_Sensor:linkquality" }
Number Kids_Bedroom_Voltage      "Kids Bedroom Voltage [%d mV]"        <energy>  (gALLBatteryVoltage)      { channel="mqtt:topic:Kids_Bedroom_Sensor:voltage" }
Number Kids_Bedroom_Battery      "Kids Bedroom Battery [%.1f %%]"      <battery> (gALLBatteryPercentage)     { channel="mqtt:topic:Kids_Bedroom_Sensor:battery" }
Number Living_Room_Temperature  "Temperature [%.1f Ā°C]"  <temperature>   { channel="mqtt:topic:Living_Room_Sensor:temperature" }
Number Living_Room_Humidity     "Humidity [%.1f %%]"     <humidity>      { channel="mqtt:topic:Living_Room_Sensor:humidity" }
Number Living_Room_LinkQuality  "Living Room Link Quality [%d]"      <network> (gALLLinkQuality)      { channel="mqtt:topic:Living_Room_Sensor:linkquality" }
Number Living_Room_Voltage      "Living Room Voltage [%d mV]"        <energy>  (gALLBatteryVoltage)      { channel="mqtt:topic:Living_Room_Sensor:voltage" }
Number Living_Room_Battery      "Living Room Battery [%.1f %%]"      <battery> (gALLBatteryPercentage)     { channel="mqtt:topic:Living_Room_Sensor:battery" }

All sensors output data for all things stated just at different times as stated in an earlier post so i used a regex transformation as explained by @hafniumzinc

I had this working perfectly with just one sensor but since adding the second and using seperate mqqt topics i dont seem to get anything?

Note that your JSON string doesnā€™t contain both temperature and humidity. Is that what you expect?