Problem with wait_for_trigger (ha 2023.11.03)

Hello, I use an automation like this to be warned when my washer finishes his work.

...
trigger:
  - platform: numeric_state
    entity_id: sensor.plug_lavatrice_power
    above: "100"
    for: "00:01:00"
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_local() }}"
      message: start
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.plug_lavatrice_power
        below: "1"
        for: "00:10:00"
    timeout: "10:00:00"
    continue_on_timeout: false
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_local() }}"
      message: end

But it never write “end”… Months ago it was ok.
Some help?

Does the power go below 1 (check the sensor history)?

Yess… I have graph. I am becoming crazy.

immagine

Check the automation trace:

Triggered by the numeric state of sensor.plug_lavatrice_power at 3 dicembre 2023 alle ore 08:04:11

Stopped because only a single execution is allowed at 3 dicembre 2023 at hour 08:04:11 (runtime: 0.00 seconds)

what does it means?

It means your power went above 100, triggering the automation.

Then it went below 100, but not below 1. So the wait for trigger did not occur.

Then while still waiting in the wait for trigger the power went above 100 again. This re-triggered your automation.

Your automation does not have a mode specified, so it would be using the default mode of “single” which only allows a single instance of the automation to run at any one time. What should happen is that the automation should reject the second trigger, log a warning, and continue waiting in the wait for template. However I believe there there is a bug that actually stops the automation when this occurs. This is not the first time I have seen this sort of thing reported.

You can report this as a new issue here:

Include your automation config and the downloaded automation trace.

Another way to approach this would be to use a template binary sensor to trigger your automation. This sensor should not turn off until the power goes below 1.

template:
  - binary_sensor:
      - name: "Washer Running"
        icon: "mdi:washing-machine"
        state: >
          {% if states('sensor.plug_lavatrice_power')|float(0) > 100 %}
            {{ true }}
          {% elif states('sensor.plug_lavatrice_power')|float(0) < 1 %}
            {{ false }}
          {% else %}
            {{ this.state|bool }}
          {% endif %}
        availability: "{{ has_value('sensor.plug_lavatrice_power') }}"
        delay_off: 600 # 10 minutes
        delay_on: 60 # 1 minute

You can then replace your automation with this:

trigger:
  - platform: state
    entity_id: binary_sensor.washer_running
    to: "on"
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_local() }}"
      message: start
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.washer_running
        to: "off"
    timeout: "10:00:00"  # you really shouldn't be waiting this long in an automation. 
    continue_on_timeout: false
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_local() }}"
      message: end
1 Like

Honestly, I had mistakenly understood that I could wait for the first trigger above 100W to start, and then ignore it and wait for the next event when the trigger remains below 1W for 10 consecutive minutes. It’s possible?
However, if I inserted the template / binary sensor, to have it available, would I have to do a complete reboot or would the quick one be enough?
Thank you very much anyway for the sensor already supplied, ready and working :slight_smile:

no news? and my questions? i am curious

Now I have

alias: lavatrice - voce a termine lavaggio
description: choose condition wait_for_trigger
trigger:
  - platform: state
    entity_id: binary_sensor.washer_running
    to: "on"
    id: "started-washing"
  - platform: state
    entity_id: binary_sensor.washer_running
    to: "off"
    id: "ended-washing"
condition: []
action:
  - if:
      - condition: trigger
        id: "started-washing"
    then:
      - service: notify.persistent_notification
        data:
          title: "{{ now().timestamp() | timestamp_local() }}"
          message: started
  - if:
      - condition: trigger
        id: "ended-washing"
    then:
      - service: input_datetime.set_datetime
        target:
          entity_id: input_datetime.data_ultima_lavatrice
        data_template:
          date: "{{ now().strfdate('%d/%m/%Y') }}"
      - service: input_datetime.set_datetime
        target:
          entity_id: input_datetime.ora_lavatrice_fine
        data_template:
          time: "{{ now().strftime('%H:%M:%S') }}"
      - service: telegram_bot.send_message
        data:
          title: HA
          message: stop
          target: 768037992

with:

template:
- binary_sensor:
- name: "Washer Running"
unique_id: temp_washer_running
icon: "mdi:washing-machine"
state: >
{% if states('sensor.plug_lavatrice_power')|float(0) > 60 %}
{{ true }}
{% elif states('sensor.plug_lavatrice_power')|float(0) < 1 %}
{{ false }}
{% else %}
{{ this.state|bool }}
{% endif %}
availability: "{{ has_value('sensor.plug_lavatrice_power') }}"
delay_off: 600 # 10 minutes
delay_on: 60 # 1 minute

(space are not indicated)

and It does not detect end-washing

I have also sensor history:

immagine