From 048e26f723361ed692ffbe5aec15ccc849cc6757 Mon Sep 17 00:00:00 2001 From: atlflyer <31390797+atlflyer@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:01:16 -0400 Subject: [PATCH] Add json_attributes_path configuration for command_line sensor (#32241) --- source/_integrations/command_line.markdown | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/_integrations/command_line.markdown b/source/_integrations/command_line.markdown index 4e2c2050c10..ead1db28fe6 100644 --- a/source/_integrations/command_line.markdown +++ b/source/_integrations/command_line.markdown @@ -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