From ef860a6255ea75a90c4ac8cdf7e36dee2778246d Mon Sep 17 00:00:00 2001 From: Steven Rollason <2099542+gadgetchnnel@users.noreply.github.com> Date: Wed, 21 Aug 2019 22:41:21 +0100 Subject: [PATCH] Updated documentation for template binary_sensor (#9106) * Updated documentation for template binary_sensor * Update binary_sensor.template.markdown * Updated section header --- .../binary_sensor.template.markdown | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/_components/binary_sensor.template.markdown b/source/_components/binary_sensor.template.markdown index 3eff2ecfb53..e59acefa2a4 100644 --- a/source/_components/binary_sensor.template.markdown +++ b/source/_components/binary_sensor.template.markdown @@ -66,6 +66,15 @@ sensors: 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: map + keys: + "attribute: template": + description: The attribute and corresponding template. + required: true + type: template delay_on: description: The amount of time the template state must be ***met*** before this sensor will switch to `on`. required: false @@ -210,6 +219,35 @@ binary_sensor: ``` {% endraw %} +### Device Tracker sensor with Latitude and Longitude Attributes + +This example shows how to combine an non-GPS (e.g. NMAP) and GPS device tracker while still including latitude and longitude attributes + +{% raw %} +```yaml +binary_sensor: + - platform: template + sensors: + my_device: + value_template: >- + {{ is_state('device_tracker.my_device_nmap','home') or is_state('device_tracker.my_device_gps','home') }} + device_class: 'presence' + 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 %} + ### Change the icon when state changes This example demonstrates how to use `icon_template` to change the entity's