Hi,
I would appreciate help with configuring a REST full sensor to extract multiple sensors from one REST call using templates.
I can extract any value, e.g. temperatur from the first element of the array with below configuration.
However struggle to figure out how I can access any attribute of the second element of the array.
For example the value for JSON Path $.[?(@.etagenname=="OG")].raeume[?(@.name=="Bad")].temperatur
Here is my configuration
sensor:
- platform: rest
resource: http://192.168.2.3/get/json/v1/1/temps
scan_interval: 60
name: temperatur_sensor
value_template: 'OK'
json_attributes:
- temperature
- raeume
- platform: template
sensors:
wohnzimmer_ist_temperatur_neu:
device_class: temperature
unit_of_measurement: "Ā°C"
value_template: "{{ states.sensor.temperatur_sensor.attributes.raeume[0].temperatur|round(2) }}"
which returns 17.73 as desired.
My JSON looks like below:
[
{
"etagenname": "DG",
"id": 1,
"raeume": [
{
"total_offset": 0.2,
"solltemperatur": 12,
"temperatur": 17.725490196078432,
"name": "Bad"
},
{
"total_offset": 0.2,
"solltemperatur": 18,
"temperatur": 19.137254901960784,
"name": "Lena"
}
]
},
{
"etagenname": "OG",
"id": 2,
"raeume": [
{
"total_offset": -0.11529411764705755,
"solltemperatur": 19.9,
"temperatur": 16.764705882352942,
"name": "Bad"
},
{
"total_offset": 0.08,
"solltemperatur": 16,
"temperatur": 18.352941176470587,
"name": "Schlafzimmer"
}
]
}
]