Help with repeat while automation

Hi all,

I have an automation that notifies me when my dishwasher has finished. The automation checks whether the dishwasher door is open or closed before repeating the message every 10min and here’s the problem. In fact, it happens that it takes less than 10min to empty it and close the door so the message starts again even if there is no longer needed.

  - id: lavastoviglie_finita_hub
    alias: Lavastoviglie Finita
    initial_state: on
    trigger:
    - entity_id: input_boolean.lavastoviglie_switch
      platform: state
      to: 'off'
    condition:
      - condition: template
        value_template: >
          {%- if states.binary_sensor.lavastoviglie.last_changed -%}
            {{ (as_timestamp(now()) - as_timestamp(states.binary_sensor.lavastoviglie.last_changed)) > 60*10 }}
          {%- else -%}
            true
          {%- endif -%}
    action:
      repeat:
        while:
          - condition: state
            entity_id: binary_sensor.lavastoviglie
            state: 'off'
          - condition: template
            value_template: "{{ repeat.index <= 12 }}"
          - condition: state
            entity_id: group.dispositivi_tracciati
            state: home
          - condition: state
            entity_id: input_boolean.lavastoviglie_switch
            state: 'off'
        sequence:
          - service: script.my_notify
            data_template:
              call_no_annuncio: 1 
              title: "Lavastoviglie"
              google: true
              message_tts: "la lavastoviglie è terminata"
              message: >-
                {{ [
                "La lavastoviglie è terminata. E' ora di sistemare i piatti!",
                "La lavastoviglie ha finito.",
                "I piatti sono puliti. Adesso tocca sistemarli!"
                ] | random }}
          - delay:
              minutes: 10

Can anyone suggest me a smarter solution?

use the alert integration