Adding condition "for more than X seconds" to sensor template

Hi,
I’m trying to create a sensor (sensor.wash_status) to track washing machine status through its power consumption (sensor.wash_power).

I created it as helper + template sensor and added the following code in the State Template Option field:

{% if states(‘sensor.wash_power’)|float(0) == 0 %}
OFF
{% elif states(‘sensor.wash_power’)|float(0) > 0
and
states(‘sensor.wash_status’) == ‘OFF’ %}
STAND-BY
{% elif states(‘sensor.wash_power’)|float(0) > 50
and
states(‘sensor.wash_status’) == ‘STAND-BY’ %}
WASHING
{% else %}
unknown
{% endif %}

I need to add a condition in the bold line so that it is true if power goes above 50 for more than X seconds.
Can you please help?

Thank you very much!
Davide

You should format your code using </> not ´´
Try this

(now()|as_timestamp() - states['sensor.wash_power'].last_updated|default(0,true)|as_timestamp()|default(0,true)) > X

Thanks so much for your super quick answer.
I’ll give it a try and I’ll let you know in a couple of days.