Understanding "Trigger-based template sensors"

Hi, I have set up a sensor, which indicates, if I can open a window. (-> not wanting to increase humidity inside…)

I used the following in my sensor.yaml. Then, I realised that the icon in my dashboard changes, whenever the “d1mini_wohnzimmer_window” changes its state. In automations, there is an option “delay_on”, but it is not allowed in sonsors.

  - platform: template
    sensors:
      d1mini_wohnzimmer_window:
        friendly_name: "Fenster"
        value_template: >-
          {% if states('sensor.d1mini_wohnzimmer_am2301_temperature')|float > 18.0   and  states('sensor.d1mini_wohnzimmer_am2301_dewpoint')|float > ( states('sensor.openweathermap_dew_point')|float + 0.5 )  %}
            öffnen
          {% else %}
            schliessen
          {% endif %}
        icon_template: >
          {% if is_state("sensor.d1mini_wohnzimmer_window", "öffnen") %}
            mdi:window-open-variant
          {% else %}
            mdi:window-closed-variant
          {% endif %}
#        delay_on: 00:15:00   -> https://community.home-assistant.io/t/sensor-delay-possible/43299/7

In the documentation I read about “Trigger-based template sensors”.

I added this to my configuration.yaml

template: !include template_triggered_sensors.yaml

Then, in template_triggered_sensors.yaml, I added this code, but it does not work. Could anyone explain, how to use trigger-based template sensors? Is this the right way to do it?

  - trigger:
      - platform: time_pattern
        hours: 0
        minutes: 15
      - platform: state
        entity_id:
          - d1mini_wohnzimmer_window
    sensor:
      - name: d1mini_wohnzimmer_window
        friendly_name: "Fenster"
        state: >-
          {% if states('sensor.d1mini_wohnzimmer_am2301_temperature')|float > 18.0   and  states('sensor.d1mini_wohnzimmer_am2301_dewpoint')|float > ( states('sensor.openweathermap_dew_point')|float + 0.5 )  %}
            öffnen
          {% else %}
            schliessen
          {% endif %}
        icon_template: >
          {% if is_state("sensor.d1mini_wohnzimmer_window", "öffnen") %}
            mdi:window-open-variant
          {% else %}
            mdi:window-closed-variant
          {% endif %}

Any help is very much appreciated.

You need a binary sensor. See the section in the documentation:

https://www.home-assistant.io/integrations/template/#binary_sensor

delay_on
The amount of time (ie 0:00:05) the template state must be met before this sensor will switch to on. This can also be a template.

delay_off
The amount of time the template state must be not met before this sensor will switch to off. This can also be a template.