Dryer finished monitor and notification

Hello,
Newbie here. Of course I try to start with something complicated, to me at least. I have a dumb dryer that I can only monitor the on/off state of. Door open/closed also registers as on/off. I would like for the automation to wait for 15 minutes before running the rest of the automation and cancel if the dryer is not running. This is to account for the door being open to unload clothes. Also, if the dryer cycle is stopped and started, to add clothes say, to continue monitoring. The real trick of it all is making the timers restart proof. Here is my monstrosity of a program. All ideas are welcomed. Thank you.

alias: Dryer Done Monitor
description: Notify when the dryer is done
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_sensor_2
    to: "on"
  - platform: homeassistant
    event: start
condition:
  - condition: state
    entity_id: timer.15_minute_timer
    state: idle
  - condition: state
    entity_id: binary_sensor.dryer_sensor_2
    state: "on"
action:
  - service: timer.start
    target:
      entity_id: timer.15_minute_timer
    data: {}
  - wait_for_trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.15_minute_timer
  - service: timer.start
    target:
      entity_id: timer.30_second_timer
    data: {}
  - wait_for_trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.30_second_timer
  - if:
      - condition: state
        entity_id: binary_sensor.dryer_sensor_2
        state: "off"
    then:
      - service: notify.pushover_to_phone
        data:
          title: Alert
          message: Dryer Finished at {{ now().strftime('%H:%M %A, %B %d, %Y') }}
          data:
            sound: dryer_done
            priority: 0
        alias: Pushover to Phone
    else:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - binary_sensor.dryer_sensor_2
            to: "off"
      - service: timer.start
        target:
          entity_id: timer.30_second_timer
        data: {}
mode: single

I thought that the 30 second timer at the end would trigger the timer finished in the middle to cause a loop, but this does not seem to work.

i’m probably missing something because my answer here is too simple, but does this do what you want?

alias: Dryer Done Monitor
description: Notify when the dryer is done
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_sensor_2
    to: "off"
    from: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - service: notify.pushover_to_phone
    data:
      title: Alert
      message: Dryer Finished at {{ now().strftime('%H:%M %A, %B %d, %Y') }}
      data:
        sound: dryer_done
        priority: 0
    alias: Pushover to Phone
mode: single

isn’t all you want to be notified if the dryer has turned off for 15 minutes?

Thank you for your response. Yes, what you provided does work but will it survive a HA restart? It’s the wait 15 minutes that I think is the problem. I was told that I need to use a timer helper. Unless I am mistaken.

I would like for the dryer to be on for 15 minutes before it starts looking for the dryer to be off. This is because when I open the dryer door it registers as the dryer being on. I want to be able to remove the clothes without getting notified. Only notify when the drying cycle is finished.

we can make that happen, but i don’t understand your logic here. why does it matter if the dryer is on for 15 minutes or not. it only matters if it turns off for a sufficient amount of time. let’s say you open it near the end… which turns the power off while you’re removing a couple pieces of clothing. you happen to open it 10 minutes to the end. if you then close it to let it finish, at which point it turns “on” for only 10 minutes, then you won’t get notified.

i believe my automation is fine for the HA reboot case. the automation is not running from the point of “off” until 15 minutes afterwards. the key issue with reboots is that any automation that’s running is killed and not restarted where it left off. but the trigger i set is checked every minute to see if it has become true. after reboot, it will continue to be checked every minute.

said another way, i believe the system does not “wait” for 15 minutes. i think the system checks regularly instead.

finally, if you respond in these forums, please hit the “reply” button next to the message you’re responding to. not the bottom blue reply button. that way the person (me in this case) will get notified. i almost missed that you replied to me and it may have been days or never that i respond if i didn’t happen to run across it. be kind to your future self by hitting me with a notification that you’ve responded :slight_smile:

Thank you for the reply clarification. Like I said I am a newbie.
15 Minutes is just an arbitrary number. I usually do not stop a cycle in the middle. I just don’t want to be notified when I am taking the clothes out of the dryer. Dryer starting and door open both register as machine on and start the automation. I just want to double check that the machine is actually running and not just the door being open to take clothes out, which would be less than 15 minutes.
As per your explanation, timer helpers are not needed in this case. That would make for easier programing of the automation.
Thank you. I think I will start from scratch and try again.

try the code I gave you and tweak it from there if it doesn’t do what you need… holler back here for help if you need any… Good luck!

I think you have misunderstood how timers are used to help automations survive restart.
In order to have your automation survive a restart you need to restructure it so that the timer event trigger is a normal trigger, not a Wait for trigger. You can either organize it as multiple automations or use a Choose action so you have different action sequences for each trigger.

Once an action in the sequence is passed, it is done. If you want a loop/repeat you need to use one of the available Repeat actions.

Also, using a 30 second timer immediately followed by a Wait for trigger offers no benefit over just using a 30 second delay.

You could use a energie monitoring device like a Shelly plug S to build an automation on it’s power state

Thank you for the timer clarification. I think I am getting closer. I rewrote the automation to include the use of a script. Here is what I have and it works as I want.

Automation:

alias: Dryer Done Monitor
description: Notify when the dryer is done
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_sensor_2
    to: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0
  - platform: homeassistant
    event: start
condition:
  - condition: state
    entity_id: binary_sensor.dryer_sensor_2
    state: "on"
action:
  - service: script.dryer_wait_till_off
    metadata: {}
    data: {}
mode: single

and this is the script part

alias: Dryer wait till OFF
sequence:
  - repeat:
      sequence:
        - wait_for_trigger:
            - platform: state
              entity_id:
                - binary_sensor.dryer_sensor_2
              to: "off"
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
        - condition: state
          entity_id: binary_sensor.dryer_sensor_2
          state: "off"
          for:
            hours: 0
            minutes: 0
            seconds: 0
        - service: notify.pushover_to_kurts_phone
          data:
            title: Alert
            message: Dryer Finished at {{ now().strftime('%H:%M %A, %B %d, %Y') }}
            data:
              sound: dryer_done
              priority: 0
          alias: Pushover to Kurt's Phone
      until:
        - condition: state
          entity_id: binary_sensor.dryer_sensor_2
          state: "off"
description: Keep checking to see if dryer is off

The script keeps checking to make sure the dryer is really off and not just a temporary off. When using the Test Confirm command the For never triggered and advanced when I entered a time, so I left it blank, hence the Wait (delay) before the Test Confirm.
With the Home Assistant Start trigger and the Condition of the dryer already running I think this will survive a restart enough for me.
Thank you all. Any more thoughts and/or ideas are always welcome.

I’m not sure how to reply to multiple people. This is why I am sending you this notice.

You might want to take another crack at that…

The until will close out the repeat, so the Wait for trigger won’t do anything.

Also, repeats don’t survive restart.

EDIT: See OP’s correct assertion below.

no worries :slight_smile:

as @Didgeridrew pointed out, there are still issues. and i think you’re making it significantly more complicated.

could you clarify for me… what don’t you like about this? (change the 15 mins to whatever timeout you want). your new code now waits only 30 seconds… easy.

this shouldn’t erroneously notify you if you stop and take clothes out and restart it (unless it takes you 15 minutes to take clothes out)…

alias: Dryer Done Monitor
description: Notify when the dryer is done
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dryer_sensor_2
    to: "off"
    from: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - service: notify.pushover_to_phone
    data:
      title: Alert
      message: Dryer Finished at {{ now().strftime('%H:%M %A, %B %d, %Y') }}
      data:
        sound: dryer_done
        priority: 0
    alias: Pushover to Phone
mode: single

It seems to work during testing. Since I don’t speak yaml, everything was created using the Visual Editor. I read that the Repeat Until loop performs the actions first (so the actions run at least once before even looking at the condition) and then waits for the condition to be true before stopping. So if the Test Confirm says that the state is on then the script stops and repeats, waiting again for a dryer off trigger. At least that is my understanding.

You are correct about the until loop… :man_facepalming:

I think I was stuck in my way of thinking (logic). You provided a solution by coming at it from a different angle that I just was able to wrap my head around. So thank you for that. I tend to over think things. Now I have to look at all of my other automations to see how I might have over complicated things. I will try your automation.

Just FYI, similar to a wait, the state trigger with a duration will fail if Home Assistant restarts within the 15 minutes after the state changes to ‘off’.

A problem with your program that I see is that I will get notified if I open and close the door and I do not really want to wait 15 minutes after a cycle has finished before I get notified

Correct but the script will still fire after a restart due to the Home Assistant Restart trigger