adding icon_template example (#9527)

This commit is contained in:
Dylan 2019-05-28 08:16:45 -04:00 committed by Fabian Affolter
parent 13e2a2d0d5
commit f8349115ff

View File

@ -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 %}