Wait for trigger always waits for timeout

Hi,

I already red in different post about my problem but I couldn’t find out what’s going on in my specific case.

What I want to do:

I have the duplicati integration installed and have two locations defined to make backups of my paperless folder. Now there are buttons for triggering a backup and I want to start the first backup and wait for it to finish without errors. After the first backup finished I want to start the second backup and do the same thing. There are two binary sensor for each backup instance ( operating state and backup state).

Now I created a script with a wait_for_trigger. I press the first button and then check for the operating state to change from “operating” to “idle” (aka on to off). I also added a timeout of 15 minutes.

Normally a backup will take a couple of minutes. However if I trigger this multiple times in a row, there is no change to be done by duplicati and the operating state will change from off to on and from on to off in a couple of seconds (but it always changes).

Now what I can see in the traces is that there is never a “trigger” and each wait_for_trigger block stuck in the “timeout” block. I dont understand why the trigger is not fired. Can anyone help? Sorry I set by Home Assistant to German language.

alias: Paperless-Sicherung
sequence:
  - action: button.press
    metadata: {}
    data: {}
    target:
      entity_id: button.paperless_backup_backup_erstellen
  - wait_for_trigger:
      - entity_id:
          - binary_sensor.paperless_backup_betriebszustand
        to:
          - "off"
        trigger: state
        from:
          - "on"
    timeout:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
    continue_on_timeout: true
  - if:
      - condition: state
        entity_id: binary_sensor.paperless_backup_status
        state: "off"
    then:
      - action: button.press
        metadata: {}
        target:
          entity_id: button.paperless_extern_backup_backup_erstellen
        data: {}
      - wait_for_trigger:
          - entity_id: binary_sensor.paperless_extern_backup_betriebszustand
            to: "off"
            trigger: state
        timeout:
          hours: 0
          minutes: 10
          seconds: 0
          milliseconds: 0
        continue_on_timeout: true
      - if:
          - condition: state
            entity_id: binary_sensor.paperless_extern_backup_status
            state: "off"
        then:
          - action: notify.mobile_app_blackbird
            metadata: {}
            data:
              message: Sicherung erfolgreich abgeschlossen!
              title: Paperless
        else:
          - action: notify.mobile_app_blackbird
            metadata: {}
            data:
              message: "Fehler bei Sicherung an Hetzner Cloud. Bitte prüfen! "
              title: Paperless
    else:
      - action: notify.mobile_app_blackbird
        metadata: {}
        data:
          message: Fehler bei lokaler Sicherung auf Mac Mini. Bitte prüfen!
          title: Paperless
mode: restart

You have the mode of the automation set to “restart”, so every time you “trigger” the script it cancels the previous run and starts a new one.

Check the timing of the state change, if the state changes before the automation reaches the Wait step then there is no trigger event… you’ll need to use a Wait for Template instead.

Thanks! I wasn’t quit sure about the correct mode yet since this will be workflow for scanning my documents and then shred them afterwards.

Without having a deeper look into the logs I also think that this is somehow a timing problem. But will this timing problem not be the same on the wait_for_template?

And do you could give me some kind of example in my case? From my understanding I am looking explicit for a “mode change”. What I found for wait_for_template looks like “a specific mode occurred” instead of “a mode changed”.

In a Wait for Template the template is evaluated when the action starts and is reevaluated based on the contents of the template… when the states of entities used within the template update or at specific time intervals. So if the state changed to “off” before the Wait action starts, the wait will be completed immediately.

In a Wait for Trigger the trigger listener is set when the action starts. If the state is “off” when that listener is set, the state needs to change from “off” to “on”, then back to “off”.

What you are describing is a State trigger, so you were using the generally correct tool… it just may not work for this specific case.

I think it might be helpful if you give us a bit more detail about how you are firing this script and what the different parts do. Also, are there any other sensors from Paperless or Duplicati that you might be able to leverage to help determine when the backup is complete? (I don’t personally use either of these integrations, so you’ll need to let us know what’s available) For example, based on the integration repo it looks like there may be sensors for “execution time” and “duration” that I would assume update after a backup is completed…

Hi,

thanks again for your reply and sorry for my late answer. I tried a little bit more. I found the entity (date) in duplicate that will be set with a timestamp after a backup is complete.

I then adapted the script to save both entities at the beginning and then used a wait_for_template to check once the timestamp has changed. So far this is working. Although I it still quit hard for me to understand this timing problem, but I will accept it and do it like this in the future.

Thank you :slight_smile: