So, i’ve been learning how to extract JSON values, and I can get some of the values from the data below from the code below, but when I look at the states under Dev Tools I can see some of my sensors are ok while others (like kitchen_humidity_local) says ‘unavailable’, but when I try the same template from the yaml code in Developer Tools it works ok, I’m a little confused, any help.
json data…
{
“wh25”: [
{
“intemp”: “19.8”,
“unit”: “C”,
“inhumi”: “74%”,
“abs”: “29.64 inHg”,
“rel”: “29.64 inHg”
}
],
“ch_aisle”: [
{
“channel”: “1”,
“name”: “”,
“battery”: “0”,
“temp”: “20.0”,
“unit”: “C”,
“humidity”: “70%”
},
{
“channel”: “2”,
“name”: “”,
“battery”: “0”,
“temp”: “21.2”,
“unit”: “C”,
“humidity”: “66%”
},
{
“channel”: “3”,
“name”: “”,
“battery”: “0”,
“temp”: “19.6”,
“unit”: “C”,
“humidity”: “78%”
},
{
“channel”: “4”,
“name”: “”,
“battery”: “0”,
“temp”: “19.7”,
“unit”: “C”,
“humidity”: “75%”
}
],
“ch_soil”: [
{
“channel”: “1”,
“name”: “”,
“battery”: “1”,
“humidity”: “–”
}
]
}
code
- platform: rest
name: gw1100a-wifif673_local
json_attributes:
- wh25
- ch_aisle
resource: http://192.168.1.167/get_livedata_info
scan_interval: 60
method: GET
value_template: "OK"
- platform: template
sensors:
study_temp_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'wh25')[0]['intemp'] }}"
unit_of_measurement: "°C"
study_humidity_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'wh25')[0]['inhumi'] }}"
bedroom_temp_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'ch_aisle')[0]['temp'] }}"
unit_of_measurement: "°C"
bedroom_humidity_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'ch_aisle')[0]['humidity'] }}"
unit_of_measurement: "%"
kitchen_temp_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'ch_aisle')[1]['temp'] }}"
unit_of_measurement: "°C"
kitchen_humidity_local:
value_template: "{{ state_attr('sensor.gw1100a_wifif673_local', 'ch_aisle')[1]['humidity'] }}"
unit_of_measurement: "%"