Add json_attributes_path configuration for command_line sensor (#32241)

This commit is contained in:
atlflyer 2024-07-06 13:01:16 -04:00 committed by GitHub
parent 1de6d759e2
commit 048e26f723
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.
required: false
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:
description: Name of the command sensor.
required: false
@ -635,6 +639,26 @@ command_line:
```
{% 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
### Change the icon when a state changes