From 175ca36db491d47e4259480e36e52965d988c810 Mon Sep 17 00:00:00 2001 From: Alexander Hardwicke Date: Wed, 25 Jul 2018 19:34:45 +0200 Subject: [PATCH 1/2] Add documentation for json_attributes in command --- .../_components/sensor.command_line.markdown | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/_components/sensor.command_line.markdown b/source/_components/sensor.command_line.markdown index ac5b78e301d7..0015f2263b5c 100644 --- a/source/_components/sensor.command_line.markdown +++ b/source/_components/sensor.command_line.markdown @@ -33,6 +33,7 @@ Configuration variables: - **value_template** (*Optional*): Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload. - **scan_interval** (*Optional*): Defines number of seconds for polling interval (defaults to 60 seconds). - **command_timeout** (*Optional*): Defines number of seconds for command timeout (defaults to 15 seconds). +- **json_attributes** (*Optional*): Defines a list of keys to extract values from a JSON dictionary result and then set as sensor attributes. ## {% linkable_title Examples %} @@ -162,3 +163,22 @@ sensor: unit_of_measurement: "Direction" ``` {% endraw %} + + +### {% linkable_title Usage of json_attributes in `command:` %} + +The example shows how you can retrieve multiple values with one sensor (where the additional are attributes) by using value_json and json_attributes. + +{% raw %} +```yaml +# Example configuration.yaml entry +sensor: + - platform: command_line + name: JSON time + json_attributes: + - date + - milliseconds_since_epoch + command: 'python3 /home/pi/.homeassistant/scripts/datetime.py' + value_template: '{{ value_json.time }}' +``` +{% endraw %} From 77ccf2ba1a1ffdbdfdf87869c72108e6795821fb Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 28 Jul 2018 22:53:59 +0200 Subject: [PATCH 2/2] Fix formatting --- source/_components/sensor.command_line.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/_components/sensor.command_line.markdown b/source/_components/sensor.command_line.markdown index 0015f2263b5c..238c46f7f616 100644 --- a/source/_components/sensor.command_line.markdown +++ b/source/_components/sensor.command_line.markdown @@ -165,9 +165,9 @@ sensor: {% endraw %} -### {% linkable_title Usage of json_attributes in `command:` %} +### {% linkable_title Usage of JSON attributes in command output %} -The example shows how you can retrieve multiple values with one sensor (where the additional are attributes) by using value_json and json_attributes. +The example shows how you can retrieve multiple values with one sensor (where the additional are attributes) by using `value_json` and `json_attributes`. {% raw %} ```yaml