Different icons for open and closed window, the same way as for door

Hello,

when I use door sensor, it has different icon for open door and different for closed door. I am unable to do the same with window, how to do it please?

Thanks, Jan

If you look up template in the docs, it gives this example for changing the icon according to a sensor’s 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 %}

Or even easier,

device_class: window

Yes device class did it, thanks! I really hate to edit yaml and then restart HA, because I lose cached states. Luckily there is entity customization possible in settings, where I can add parameter device class and value window wihout HA restart. Super!