Repeat Until Script Crashing HA after Updates (worked perfectly for over a year)

I finally decided to update HA after about a year. After the updates, HA would lock up everyday. I added system monitors and found the Memory and CPU surges to 80%+ and then locks up. I traced the time to my automations that contain Repeat Until Scripts. The Script Syntax guide (Script Syntax - Home Assistant) has the same example that I am utilizing
: - repeat: until: "{{ is_state('device_tracker.iphone', 'home') }}"

In my automation, once the washer is complete, “Full”, I want to make sure or wait until P is home and that the Dryer is not Dryer, and then I send P an alert to move the clothes to the dryer. I don’t know the best way to redo the script without creating 4 separate Automations for each condition combination. Any guidance would be greatly appreciated.

My Automation:

- id: '1604798000883'
  alias: Samsung Washing - Complete - Alert Pato
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.washer_state
    to: Full
  condition:
  - condition: time
    after: 07:00:00
    before: '22:00:00'
  action:
  - repeat:
      until:
      - condition: and
        conditions:
        - condition: state
          entity_id: person.p
          state: home
        - condition: not
          conditions:
          - condition: state
            entity_id: input_select.dryer_state
            state: Drying

      sequence: []
  - condition: state
    entity_id: input_select.washer_state
    state: Full
  - service: notify.p_sms
    data:
      title: Samsung Washing Machine
      message: Washing complete. Move clothes to dryer.
  mode: restart

CPPU

Mem

Your repeat is empty. It performs no work but simply iterates as fast as your host machine allows it. That’s an inappropriate use of repeat.

What you want is a wait_template. It simply waits until the desired conditions are met (without the processing demands of an empty repeat).

Thanks! I replaced with repeat until loops with the wait_template. So far, so good.

Below is what I am currently incorporated:

alias: Samsung Washing - Complete - Alert Pato
description: ''
trigger:
  - platform: state
    entity_id: input_select.washer_state
    to: Full
condition:
  - condition: time
    after: '07:00:00'
    before: '22:00:00'
action:
  - wait_template: >-
      {{ is_state('person.p', 'home') and not
      is_state('input_select.dryer_state', 'Drying') and
      is_state('input_select.washer_state', 'Full') }}
    timeout: '24:00:00'
  - service: notify.p_sms
    data:
      title: Samsung Washing Machine
      message: Washing complete. Move clothes to dryer.
  - repeat:
      count: '3'
      sequence:
        - repeat:
            count: '60'
            sequence:
              - delay: '00:00:30'
              - condition: and
                conditions:
                  - condition: state
                    entity_id: person.p
                    state: home
                  - condition: state
                    entity_id: input_select.washer_state
                    state: Full
        - condition: and
          conditions:
            - condition: state
              entity_id: person.p
              state: home
            - condition: state
              entity_id: input_select.washer_state
              state: Full
        - service: notify.p_sms
          data:
            title: Samsung Washing Machine Reminder
            message: Reminder - Wet clothes in washing machine
mode: restart

If replacing the empty repeat with a wait_template has eliminated the original problem (high CPU/memory usage), please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

Thanks. The wait_template seems to be the solution to the original issue. I want to add a time check to the reminder portion of my automation so that it will not get the three reminders after 10pm, if I haven’t put my clothes in the dryer. Can I change the conditions to a wait_template with a time check included like shown below or is there better way? I’m concerned that it will continuously race the time changes and overload again like the repeat until loop was doing.

wait_template: {{ is_state('person.p', 'home') and and is_state('input_select.washer_state', 'Full') and now().strftime('%T') > '07:00:00' and now().strftime('%T') < '22:00:00' }}

If you add a time range to the wait_template, it will wait until the current time is within the range.

In other words, if the person is home and the washer is full but the time is not within the range, it will wait until the time is within the range. Your wait_template has a very long timeout value (24 hours) so if the current time is past 22:00, it will wait until the next day at 7:00.

You should be aware that whenever you execute Reload Automations (it happens automatically whenever you save an automation with the Automation Editor), or restart Home Assistant, any automation that is in-progress (like in a repeat, delay, wait_template, wait_for_trigger`, etc) is cancelled and reset.