Hi,
I have this json array I wish to extract one value from:
[
{
"label": "amdgpu 1",
"value": 42,
"unit": "C",
"type": "temperature_core",
"key": "label"
},
{
"label": "amdgpu 2",
"value": 31,
"unit": "C",
"type": "temperature_core",
"key": "label"
},
{
"label": "k10temp 1",
"value": 42,
"unit": "C",
"type": "temperature_core",
"key": "label"
}
]
I created a rest sensor and used this in value template:
value_template: "{{ value_json[2].value }}"
This works as intended but I would like to not rely on hardcoded constant in case this array changes order (devices might be added or removed).
Is there a way to seek the array based on a certain key value? I would like to get the “value” key from the entry containing the “k10temp 1” label. Is there a way with jinja2 to seek an array based on a certain key value?
Sorry if I’m not using the proper terminology here. I’m a real noob when it comes to REST and JSON.
The key lines “key”: “label” in every members of the array is perplexing to me. Feels like something that would instruct on how to seek this particular array. But then again, noob here. I’m way over my head on this!
Thanks!