Template sensor with for time condition

I’ve created the below template sensor which works fine, but annoyingly the z-wave smoke alarm doesn’t distinguish between smoke detection and pressing the test button on the device.

So what I’d like to do is add to the value template so that smoke_alarm_status is only Smoke detected if binary_sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_sensor has been on for 10 seconds or more.

Similar to a “for” condition in an automation, is there a way to do this?

# Smoke alarm
- platform: template
  sensors:
    smoke_alarm_status:
      friendly_name: Smoke alarm
      value_template: >-
          {%- if is_state('binary_sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_sensor', 'off') %}
              Idle
          {%- elif is_state('binary_sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_sensor', 'on') %}
              Smoke detected
          {% else %}
              Unknown
          {%- endif %}
      icon_template: >-
          {%- if is_state('sensor.smoke_alarm_status', 'Idle') %}
              mdi:smoke-detector
          {%- elif is_state('sensor.smoke_alarm_status', 'Smoke detected') %}
              mdi:fire
          {%- elif is_state('sensor.smoke_alarm_status', 'Unknown') %}
              mdi:alert-octagram
          {%- endif %}

I would not do this. Every second counts in a fire situation.

See my solution in your other topic.

Testing your smoke alarms regularly is a very wise idea. Simply toggling an input boolean to enter a test mode before doing this is not onerous.