Automation multiple audio outputs when doors/windows opened

Hi everyone,
Need assistance.
I’m a Newbie and currently struggling with an automation

I wanted to achieve the following:
When I pass a certain motion sensor, my Sonos Speaker should say which windows/doors are currently open.

I tried to do it, but it doesn’t work how I want it to. Here’s my config:

alias: Türen und Fenster - Bewegungsmelder Eingang
description: ""
triggers:
  - type: motion
    device_id: removed
    entity_id: removed
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 1
    target:
      entity_id: media_player.hobbyraum
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        data:
          media:
            media_content_id: media-source://media_source/local/Bastelzimmertüre_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Bastelzimmertüre_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
        target:
          entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Bürotüre_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Bürotüre_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: >-
              media-source://media_source/local/Elternschlafzimmerfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Elternschlafzimmerfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Küchenfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Küchenfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Küchentüre_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Küchentüre_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Schiebetürewohnzimmer_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Schiebetürewohnzimmer_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Hobbyraumfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Hobbyraumfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Kellerfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Kellerfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Waschküchenfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Waschküchenfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Kinderzimmerfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Kinderzimmerfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Spielzimmerfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Spielzimmerfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - if:
      - type: is_open
        condition: device
        device_id: removed
        entity_id: removed
        domain: binary_sensor
    then:
      - action: media_player.play_media
        metadata: {}
        target:
          entity_id: media_player.hobbyraum
        data:
          media:
            media_content_id: media-source://media_source/local/Spielzimmerfenster_offen.mp3
            media_content_type: audio/mpeg
            metadata:
              title: Spielzimmerfenster_offen.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
              browse_entity_id: media_player.hobbyraum
mode: single

I just did multiple if - then automation (script) in one animation and just created a delay between ever if - then because of voice overlapping. The problem with that is, that if the last window/door in the if-then automation (script) is oppened, A very long delay is created before the audio/mp3-file is played. How could I change that?

Thank you for your help!

Are these audio files special?

If not, then the common approach would be to use a template to “write” the message for a TTS notification.

If you specifically want to use these files instead of one of the available TTS options…

The first thing to try would be to put the delay inside the “thens” so the delays don’t stack.
Another option might be to use Wait for Template actions instead of static Delays. Something like:

alias: "Wait up to 3 seconds if the media player is playing"
wait_template: "{{ not is_state('media_player.hobbyraum', 'playing') }}"
timeout:
  seconds: 3
continue_on_timeout: true

Otherwise, you need a way to queue the files. There isn’t anything built-in to HA to do that, but it could be done with Music Assistant integrated into HA.

each door/window has it’s own audio file

Yes, I understand that… the question is “is that necessary for your desired outcome?”

Just out of interest, why do you want a separate audio file for each sensor?

Welcome to the forum!
If I understand correctly, your issue is the long delay to get to the last sensor/audio, you can try using ‘choose condition with delay’ instead of if-then + delay. If a choose condition is not met, it will skip all associated action including the delay and move to the next choose.