From 1db6e1fed825fc3d33f76e08806a2d6dd8aa8cab Mon Sep 17 00:00:00 2001 From: pavoni Date: Sat, 6 Feb 2016 22:51:18 +0000 Subject: [PATCH 1/2] Add more complex sensor.template example. --- source/_components/sensor.template.markdown | 24 ++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/_components/sensor.template.markdown b/source/_components/sensor.template.markdown index 7cfdcd83afc..a26501a14bb 100644 --- a/source/_components/sensor.template.markdown +++ b/source/_components/sensor.template.markdown @@ -41,7 +41,7 @@ In this section you find some real life examples of how to use this sensor. ### {% linkable_title Sun angle %} -This example shows the sun angle in the frontend. +This example shows the sun angle in the frontend. ```yaml sensor: @@ -53,5 +53,27 @@ sensor: unit_of_measurement: '°' ``` +### {% linkable_title Multi line example with an if test %} + +This example shows a multiple line template with and is test. It looks at a sensing switch and shows on/off in the frontend. + +```yaml +sensor: + platform: template + sensors: + kettle: + friendly_name: 'Kettle' + {% raw %}value_template: >- + {%- if is_state("switch.kettle", "standby") or + is_state("switch.kettle", "off") %} + off + {% elif is_state("switch.kettle", "on") %} + on + {% else %} + failed + {%- endif %}{% endraw %} + +``` +(please note the blank line to close the multi-line template) From 550ee46abb147dac6bb330c16b41faf91e6e87a2 Mon Sep 17 00:00:00 2001 From: pavoni Date: Sun, 7 Feb 2016 00:00:08 +0000 Subject: [PATCH 2/2] Add a number comparison to the example. --- source/_components/sensor.template.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/_components/sensor.template.markdown b/source/_components/sensor.template.markdown index a26501a14bb..533221a100c 100644 --- a/source/_components/sensor.template.markdown +++ b/source/_components/sensor.template.markdown @@ -64,9 +64,10 @@ sensor: kettle: friendly_name: 'Kettle' {% raw %}value_template: >- - {%- if is_state("switch.kettle", "standby") or - is_state("switch.kettle", "off") %} + {%- if is_state("switch.kettle", "off") %} off + {% elif states.switch.kettle.attributes.kwh < 1000 %} + standby {% elif is_state("switch.kettle", "on") %} on {% else %}