STATE BASED BINARY SENSOR - CHANGE THE ICON WHEN A STATE CHANGES
This example demonstrates how to use template to change the icon as its state changes. This icon is referencing its own state.
template:
- binary_sensor:
- name: Sun Up
state: >
{{ is_state("sun.sun", "above_horizon") }}
icon: >
{% if is_state("binary_sensor.sun_up", "on") %}
mdi:weather-sunset-up
{% else %}
mdi:weather-sunset-down
{% endif %}