How to extract only temperature value from a mqtt subscription

I am sending temperature value using mqtt, along with it i have other information as well including sentenses and numbers, so from this how do i extract my temperature value…
I only need the information in highlighted by the red box actually only the value 50
image

Here’s an example from an ESP8266 for Temp

Number ESP_Easy_Temp "Esp8266 Temp [%.1f °F]" <temperature> (Home_Sensor_Chart)
	{ mqtt="<[pibroker:/Esp/DS/Temp:state:default]" }

What is your mqtt topic? In my example the topic is Esp/DS/Temp.

Looks like your message is JSON data, so you probably need to (install and) use the JsonPath transformation service:

Take a look at the MQTT binding documentation for how to use it for inbound messages:

1 Like

I read through both the documents, The transform file is used in rules. but in my case the data is subscribed from mqtt So i need to store it in a variable I guess, then maybe create a json functionthat will parse this data then return only the temperature value…
How do I go about this…?
Any help is appreciated

If you look closely at the second link (the MQTT binding) you will see that you can use transformation services as part of the item definition.

There is a section with examples where you can find an example of using a JS transform:

Number humidity "humidity [%.1f%%]" {mqtt="<[broker:weatherstation/readings:state:JS(convertPercent.js):humidity=.*]"}

Yes, is it a default function(transform) ?What exactly does it do.

Should i write a transform file to split and extract a specific value

You may have to read the documentation a bit closer.

Anyway, I think you will need to do something along the lines of this:

Number Temperature { mqtt="<[BROKER:application/2/node/0000000000000033/rx:state:JSONPATH($.object.temperature)]" }

Please note that it is a little hard to read the exact syntax of your JSON data from the picture above so my propsal for picking up the temperature value may not be entirely correct. In additon, you need to replace “BROKER” with the name of your broker.

Also note that you need to install the JSONPATH transformation service as well as the MQTT binding…

1 Like

Okay, I was thinking that it needs to be a function… Thank you so much for clarifying,

My items file code is given below, I did as you told me but I’m not getting a value.

Number home_temp "Living Room [%.1f °C]" <temperature> ["CurrentTemperature"] {mqtt="<[mosquitto:application/2/node/0000000000000013/rx:state:JSONPATH($.object.adc)]"}

The data I subscrribe and get is given below… I need the data inn object adc

{
  "applicationID": "2",
  "applicationName": "India-Lecture",
  "deviceName": "0000000000000013",
  "devEUI": "0000000000000013",
  "rxInfo": [
    {
      "mac": "b827ebfffe0edf3b",
      "rssi": -119,
      "loRaSNR": 4.5,
      "name": "wizsen-gateway-b827ebfffe0edf3b",
      "latitude": 37.51135986968409,
      "longitude": 127.056884765625,
      "altitude": 40
    }
  ],
  "txInfo": {
    "frequency": 868500000,
    "dataRate": {
      "modulation": "LORA",
      "bandwidth": 125,
      "spreadFactor": 12
    },
    "adr": true,
    "codeRate": "4/5"
  },
  "fCnt": 139,
  "fPort": 11,
  "data": "MTA3MQ==",
  "object": {
    "adc": "1071"
  }
}

I created a rules file as well , But still not able to display the value in openhab… Any suggestions?
“tem” is just a variable that I crated and I’m using it only in rules file.

rule "Parse Room Temperature"
when
        Item home_temp received update
then
        val tem = transform("JSONPATH", "$.Object.adc", home_temp)
       

       
end