mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-24 17:57:14 +00:00
Add json_attributes_path configuration for command_line sensor (#32241)
This commit is contained in:
parent
1de6d759e2
commit
048e26f723
@ -187,6 +187,10 @@ command_line:
|
|||||||
description: Defines a list of keys to extract values from a JSON dictionary result and then set as sensor attributes.
|
description: Defines a list of keys to extract values from a JSON dictionary result and then set as sensor attributes.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [string, list]
|
||||||
|
json_attributes_path:
|
||||||
|
description: A [JSONPath](https://goessner.net/articles/JsonPath/) that references the location of the `json_attributes` in the JSON content.
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
name:
|
name:
|
||||||
description: Name of the command sensor.
|
description: Name of the command sensor.
|
||||||
required: false
|
required: false
|
||||||
@ -635,6 +639,26 @@ command_line:
|
|||||||
```
|
```
|
||||||
{% endraw%}
|
{% endraw%}
|
||||||
|
|
||||||
|
[JSONPlaceholder](https://jsonplaceholder.typicode.com/) provides sample JSON data for testing. In the below example, JSONPath locates the attributes in the JSON document. [JSONPath Online Evaluator](https://jsonpath.com/) provides a tool to test your JSONPath.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
command_line:
|
||||||
|
- sensor:
|
||||||
|
name: JSON user
|
||||||
|
command: python3 -c "import requests; print(requests.get('https://jsonplaceholder.typicode.com/users').text)"
|
||||||
|
json_attributes_path: "$.[0].address"
|
||||||
|
json_attributes:
|
||||||
|
- street
|
||||||
|
- suite
|
||||||
|
- city
|
||||||
|
- zipcode
|
||||||
|
value_template: "{{ value_json[0].name }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
## Example switch platform
|
## Example switch platform
|
||||||
|
|
||||||
### Change the icon when a state changes
|
### Change the icon when a state changes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user