Duration-based template binary sensor state trigger never triggering

Context: my dishwasher is starting to fail randomly, it’s cycles do not finish every time (and it continues to heat for hours); i have a connected metering smart plug on it, so i figured i would notify myself and/or cut power if the cycle takes longer than expected.

To do this, i created a template binary sensor helper using the UI, with the following template, so that a binary state reflects whether the dishwasher is consuming power:

{% if states('sensor.lave_vaisselle_power') | int > 0 %} {{ true }} {% else %} {{ false }} {% endif %}

The full yaml from .storage/core.config_entries is the following:

        "entry_id": "b81da1ef5aaea9ff5716d706efdb1958",
        "version": 1,
        "domain": "template",
        "title": "Lave vaisselle actif",
        "data": {},
        "options": {
          "template_type": "binary_sensor",
          "name": "Lave vaisselle actif",
          "state": "{% if states('sensor.lave_vaisselle_power') | int > 0 %} {{ true }} {% else %} {{ false }} {% endif %}",
          "device_class": "running"
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": null,
        "disabled_by": null

This sensor works as expected:

Then i wanted to trigger some action (e.g. notification) when this binary sensor turns to “on” for more than 3 hours.

alias: dishwasher debug
description: ""
  - platform: state
      - binary_sensor.lave_vaisselle_actif
      hours: 3
      minutes: 0
      seconds: 0
    to: "on"
condition: []
  - service: notify.mobile_app_me
      message: Dishwasher is taking too long !
mode: single

However, this is never triggering (despite having reached the right duration on the sensor, as seen in the history and state change journal.

There is probably something really obvious here, but what am i missing here ? Thanks a lot for your help.

PS: running 2023.9.2

You can simplify your template to

{{ states('sensor.lave_vaisselle_power') | int > 0 }}

This will already return true or false

Regarding the automation, could it be that the binary sensor was already on when you created the automation? It has to change from to on before the 3 hours start counting.
Furthermore a change to the automation in the GUI, or a HA restart will cancel the automation, and then in needs to change to on again to start

Thanks for the suggestion.

I don’t understand why but now it works…