本帖最后由 zg990725 于 2023-8-3 10:36 编辑
在PY或yaml中
怎么取到json中 的值 "name":"CO DRIVER DOOR AJAR STATUS"
{
"commandResponses":{
"size":"10",
"next":"10",
"commandResponse":[
{
"requestTime":"2023-08-02T12:32:57.653Z",
"completionTime":"2023-08-02T12:33:34.534Z",
"url":"http,xxx",
"status":"success",
"type":"diagnostics",
"body":{
"diagnosticResponse":[
{
"name":"DOOR AJAR STATUS",
"diagnosticElement":[
{
"name":"CO DRIVER DOOR AJAR STATUS",
"status":"NA",
"message":"na",
"value":"false"
},
{
"name":"DRIVER DOOR AJAR STATUS",
"status":"NA",
"message":"na",
"value":"false"
},
{
"name":"LEFT REAR DOOR AJAR STATUS",
"status":"NA",
"message":"na",
"value":"false"
},
{
"name":"RIGHT REAR DOOR AJAR STATUS",
"status":"NA",
"message":"na",
"value":"false"
}
]
},
]
}
},
]
}
}
value_template: >
{{ value_json["commandResponses"]["commandResponse"][0]["body"]["diagnosticResponse"][0]["name"] }}
json_attributes:
- commandResponses
- platform: template
sensors:
onstar_zhuangtai:
value_template: '{{states.sensor.onsta_state.attributes.commandResponses.commandResponse[0].requestTime}}'
friendly_name: '诊断时间'
unit_of_measurement: "kM"
unique_id: "sensor_completionTime"
|