From f8349115ffc18b6a0f8bf9f119825b13e1597cd2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 28 May 2019 08:16:45 -0400 Subject: [PATCH] adding icon_template example (#9527) --- .../binary_sensor.template.markdown | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source/_components/binary_sensor.template.markdown b/source/_components/binary_sensor.template.markdown index a5648394bca..71cb01894b7 100644 --- a/source/_components/binary_sensor.template.markdown +++ b/source/_components/binary_sensor.template.markdown @@ -215,3 +215,30 @@ binary_sensor: or is_state('binary_sensor.family_room_144', 'on') }} ``` {% endraw %} + +### {% linkable_title Change the icon when state changes %} + +This example demonstrates how to use `icon_template` to change the entity's +icon as its state changes, it evaluates the state of its own sensor and uses a +conditional statement to output the appropriate icon. + + +{% raw %} +```yaml +sun: +binary_sensor: + - platform: template + sensors: + sun_up: + entity_id: + - sun.sun + value_template: >- + {{ is_state("sun.sun", "above_horizon") }} + icon_template: >- + {% if is_state("binary_sensor.sun_up", "on") %} + mdi:weather-sunset-up + {% else %} + mdi:weather-sunset-down + {% endif %} +``` +{% endraw %}