How to change sensor status if is value measured for a certain time period

Hello, I have a template sensor based on MULTILINE EXAMPLE WITH AN IF TEST with 3 states displayed - ON, OFF and STBY, it works fine. But I need to show STBY only if measured value is lower than XX for at least 5 min.
Should I do it as automation or it may be within this sensor?

Try a Numeric State trigger in an automation.

I am still beginner :neutral_face:
This is my sensor:

  - platform: template
    sensors:
      wm:
        friendly_name: "WM"
        value_template: >-
          {% if states('sensor.amp') | float > 0.2 %}
            ON
          {% elif states('sensor.amp') | float < 0.2 %}
            {% if states('sensor.amp') | float > 0 %}
              STBY
            {% else %}
              OFF
            {% endif %}
          {% endif %}

it works, providing front end output based on telemetry period. Nonetheless I need to include a condition that value for STBY shall remain within given limit, ie. between 0.2 and 0 for 5 minutes at least.
Question is if it is possible to do it within “sensor” or should I create another “automation”