如果有json 回傳, 希望用 rest + template 讀取 Sensor, yaml 應怎寫?
YAML
sensor:
- platform: rest
name: 'airsensors'
scan_interval: '300'
resource: 'http://10.0.0.1/sensors'
value_template: 'OK'
json_attributes:
- result
- platform: template
sensors:
co2:
value_template: '{{ states.sensor.airsensors.attributes["result"]["datas"]["co2"] }}'
unit_of_measurement: 'ppm'
Json
{
"rc":{
"c":0,
"p":"操作成功"
},
"result":[
{
"battery":"92",
"charge":1,
"cityId":0000,
"datas":{
"co2":1042.0,
"co2Desc":"浓度较高",
"co2Level":1,
"detectTime":1590935809000,
"humidity":50.0,
"humidityDesc":"舒适",
"humidityLevel":0,
"pm25":0.0,
"pm25Desc":"优",
"pm25Level":0,
"temp":33.0,
"tempDesc":"偏热",
"tempLevel":1
},
"hardwareType":3,
"prompts":[
{
"desc":"不适宜给婴儿洗澡",
"tips":"室内二氧化碳浓度较高,不适宜婴儿长待,建议开启新风换气。"
},
{
"desc":"不适宜学习",
"tips":"室内二氧化碳浓度较高,令人昏昏欲睡,建议开启新风换气。"
},
{
"desc":"适宜室外运动",
"tips":"室外气象条件很好,适宜运动。"
}
],
"visible":1
}
]
}
|