Add timedelta to watt sensor

Hi, I have this working sensor but sometimes the wattage will drop to 0 and will ruin my automation, how can I add timedelta to this sensor? I want to be true only if is greater than 5 for at least 20 seconds.

- platform: template
  sensors:
    dishwasher_is_running:
      friendly_name: Dishwasher
      value_template: >-
        {% if states('sensor.dishwasher_power')|float(0) > 5 %}
          Running
        {% else %}
          StandBy
        {% endif %}

Thanks

You need average sensor to get an average of the last 20 seconds and then use this in this template.

I don’t think is ok with average sensor because usually when cycle starts is getting 5-10 watt then back to zero for some time, after that will get to 1000W and I don’t know which value should be average.

Huh??
The average will always be the average. You don’t pick a value as the average.

Yes it will fluctuate, but the average sensor makes sure there is an above 5 value when it’s still running (unless it drops down below 5 for more than 20 seconds).

How exactly the formula should look like?

Just a quick search gave me this:
Statistics - Home Assistant (home-assistant.io)

You need to configure it depending on the sensor.
Sampling size and max age needs to match what rate the sensor sends updates.

I’m not that advanced to implement this but it should be a more simple solution, like:

{% if states('sensor.dishwasher_power')|float(0) > 5 | -timedelta 20 %}

This might work.
Template - Home Assistant (home-assistant.io)