Automation for washing machine using wait_for_trigger?

I would like to have an automation like that:

  • trigger, when the power gets below 5W.
  • check, if the power stays for at least 2 minutes below 5W
    • if it stays below 5W for two minutes, send me a notification
    • if it goes above 5W within that two minutes, stop the automation

I think, that wait_for_trigger could be a thing, but I dont know, how I can do an action, only if a timeout occurs. I would like to have something like that:

alias: Waschmaschine fertig
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.keller_waschmaschine_power
    below: 5
condition: []
  - wait_for_trigger:
      - platform: numeric_state
        entity_id:
          - sensor.keller_waschmaschine_power
        above: 5
    timeout:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
    continue_on_timeout: true
    if_timeout:
        then:
      - device_id: abcdefghij*****
        domain: mobile_app
        type: notify
        message: Washing mashine done!
        title: Washing mashine
    else:
      - stop: ""

I don’t know of a way to do that. But what you could do is start a timer, and cancel it if the right conditions occur. You can see if timers are running when a trigger happens too.

1 Like

@Edwin_D
How would that code look like? Would this be two automations with a global timer?

Well, probably a lot different. I avoid wait for triggers, because they do not survive restarts. Timers do restore after restarts.

But looking back at your question, you do not need timers at all. You can create an automation with a trigger: power is below 5 for two minutes. It will not trigger if the power is below 5 for less time. That trigger also implies it was above it before that, so it basically that covers all. Unless you really want to know it was less long.

trigger:
  - platform: numeric_state
    entity_id: sensor.keller_waschmaschine_power
    below: 5
    for:
      minutes: 2

If you do want to do different things based on timeout or not, you could simply test the state again after the wait for. If the state is not what you waited for, it timed out.

1 Like

You have misunderstood the triggers a bit.

You should set a trigger to first trigger when the power gets below 5W and have stayed there for 2 minutes. This is a common trigger setup.

This eliminates first and last bullet point in your list.

Great, I didnt know the “for” statement in the trigger. That should solve my problem. Thank you very much! :slight_smile:

1 Like

FWIW, a Wait action populates a variable wait that can be used for this purpose. The condition for a Wait for Trigger timing out is as follows:

condition: template
value_template: '{{ wait.trigger is none }}'
1 Like