From 8fe77a3e5fea5feb4a92c9d0161c01aa2b5016b6 Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Wed, 3 Apr 2019 17:41:50 +0100 Subject: [PATCH 1/2] Updated documentation for template sensor with attributes --- source/_components/sensor.template.markdown | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/source/_components/sensor.template.markdown b/source/_components/sensor.template.markdown index 581ec0945e8c..5462b3e16502 100644 --- a/source/_components/sensor.template.markdown +++ b/source/_components/sensor.template.markdown @@ -71,6 +71,10 @@ sensor: description: Defines a template for the entity picture of the sensor. required: false type: template + attribute_templates: + description: Defines templates for attributes of the sensor. + required: false + type: list, template device_class: description: Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the `unit_of_measurement`. required: false @@ -249,6 +253,38 @@ sensor: ``` {% endraw %} +### {% linkable_title Add Custom Attributes %} + +This example shows how to add custom attributes. + +{% raw %} +```yaml +sensor: + - platform: template + sensors: + my_device: + value_template: >- + {% if is_state('device_tracker.my_device_nmap','home') %} + Home + {% else %} + {{ states('device_tracker.my_device_gps') }} + {% endif %} + attribute_templates: + latitude: >- + {% if is_state('device_tracker.my_device_nmap','home') %} + {{ state_attr('zone.home','latitude') }} + {% else %} + state_attr('device_tracker.my_device_gps','latitude') + {% endif %} + longitude: >- + {% if is_state('device_tracker.my_device_nmap','home') %} + {{ state_attr('zone.home','longitude') }} + {% else %} + {{ state_attr('device_tracker.my_device_gps','longitude') }} + {% endif %} +``` +{% endraw %} + ### {% linkable_title Working without entities %} The `template` sensors are not limited to use attributes from other entities but can also work with [Home Assistant's template extensions](/docs/configuration/templating/#home-assistant-template-extensions). From f22260c5594fcbcdfa6553fbb893cfdf4d904b66 Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Thu, 22 Aug 2019 08:11:07 +0100 Subject: [PATCH 2/2] Update template.markdown Fix documentation --- source/_components/template.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/_components/template.markdown b/source/_components/template.markdown index 37f83d8dd0e3..17367c9e03a7 100644 --- a/source/_components/template.markdown +++ b/source/_components/template.markdown @@ -71,7 +71,12 @@ sensor: attribute_templates: description: Defines templates for attributes of the sensor. required: false - type: list, template + type: map + keys: + "attribute: template": + description: The attribute and corresponding template. + required: true + type: template device_class: description: Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the `unit_of_measurement`. required: false