Unless I really misunderstand JSON, you can’t extract the temperature based on the ID attribute - they are not related other than being at the same level. You can visualise the levels like so:
{
"Time": "2020-06-20T13:35:52",
"DS18B20_1": {
"Id": "3C01A8160EFB",
"Temperature": 34.4
},
"DS18B20_2": {
"Id": "3C01A8162221",
"Temperature": 28.3
},
"DS18B20_3": {
"Id": "51D7FD1D64FF",
"Temperature": 35.5
},
"TempUnit": "C"
}
As you can see, DS18B20_1
is the ‘name’ of a group of attributes, which are Id
and Temperature
. Using transformationPattern
to extract temperature, you need:
$.DS18B20_1.Temperature
To be clear, you can’t extract Temperature
using Id
.
EDIT:
To perhaps give you more to work with, see my thing below. This is a Sonoff Basic switch with a DHT22 sensor attached, flashed with Tasmota. My MQTT broker is Mosquitto, which I have defined in a separate things file and is referenced in the (mqtt:broker:MosquittoMqttBroker)
part of the thing definition.
// Switch Bedroom Desk Light
Thing mqtt:topic:swBedroomDeskLight "Switch Bedroom Desk Light" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type switch : switch "Power Switch" [
stateTopic="stat/swBedroomDeskLight/POWER",
commandTopic="cmnd/swBedroomDeskLight/POWER",
on="ON",
off="OFF"
]
Type switch : reachable "Reachable" [
stateTopic = "tele/swBedroomDeskLight/LWT",
on="Online",
off="Offline"
]
Type number : temperature "Temperature" [
stateTopic="tele/swBedroomDeskLight/SENSOR",
transformationPattern="JSONPATH:$.AM2301.Temperature"
]
Type number : humidity "Humidity" [
stateTopic="tele/swBedroomDeskLight/SENSOR",
transformationPattern="JSONPATH:$.AM2301.Humidity"
]
Type string : tempunit "TempUnit" [
stateTopic="tele/swBedroomDeskLight/SENSOR",
transformationPattern="JSONPATH:$.TempUnit"
]
Type switch:state "State" [
stateTopic="tele/swBedroomDeskLight/STATE",
transformationPattern="JSONPATH:$.POWER",
on="ON",
off="OFF"
]
}
The JSON string received on tele/swBedroomDeskLight/SENSOR
looks very similar to yours:
{"Time":"2020-06-20T07:43:44","AM2301":{"Temperature":21.1,"Humidity":65.1},"TempUnit":"C"}
Because Temperature
is within the group AM2301
, my transformationPattern
is:
JSONPATH:$.AM2301.Temperature