diff --git a/source/_components/sensor.template.markdown b/source/_components/sensor.template.markdown index f5aad22eb5e..2d9352ce426 100644 --- a/source/_components/sensor.template.markdown +++ b/source/_components/sensor.template.markdown @@ -36,6 +36,7 @@ Configuration variables: - **friendly_name** (*Optional*): Name to use in the Frontend. - **unit_of_measurement** (*Optional*): Defines the units of measurement of the sensor, if any. - **value_template** (*Required*): Defines a [template](/topics/templating/) to extract a value from the event bus. + - **icon_template** (*Optional*): Defines a [template](/topics/templating/) for the icon of the sensor. - **entity_id** (*Optional*): Add a list of entity IDs so the sensor only reacts to state changes of these entities. This will reduce the number of times the sensor will try to update it's state. @@ -136,3 +137,18 @@ sensor: unit_of_measurement: 'kB/s' ``` +### {% linkable_title Change the icon %} + +This example shows how to change the icon based on the day/night cycle. + +```yaml +sensor: + - platform: template + sensors: + day_night: + friendly_name: 'Day/Night' + value_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}Day{% else %}Night{% endif %}'{% endraw %} + icon_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}mdi:weather-sunny{% else %}mdi:weather-night{% endif %}'{% endraw %} + +``` +