Automation: (Loops) How to repeat an action 4 times ..at 90 second intervals

Hi.
I have tried your solution. But what is repeated is only the first mp3. The second is only played once.
This is my config:

- id: gg_food_waste  
  alias: gg_food_waste
  trigger:
    platform: time
    at: '20:00:00'
  condition:
    condition: time
    weekday:
      - tue
      - thu
      - sat
  action:
    - repeat:
          count: 2
          sequence:
              - data:
                  entity_id: media_player.gm_mini
                  volume_level: '0.3'
                service: media_player.volume_set
              - data:
                  entity_id: media_player.gm_mini
                  media_content_id: '/media/local/annunciazione.mp3'
                  media_content_type: audio/mp3
                service: media_player.play_media 
              - wait_for_trigger:
                  - platform: state
                    entity_id: media_player.gm_mini
                    from: playing
                    to: idle
                timeout:
                  seconds: 10   
              - data:
                  entity_id: media_player.gmini
                  media_content_id: '/media/local/conf_umido.mp3'
                  media_content_type: audio/mp3
                service: media_player.play_media 
  mode: single  

Any idea? Thanks

the automation itself looks OK.

is there anything in the logs or in the automation trace to indicate why itā€™s failing?

You are using repeat - count with two iterations so hereā€™s what that looks like. Steps 1-4 are the first iteration and steps 5-8 are the second one.

  1. Set volume
  2. Play annunciazione
  3. Wait for it to finish
  4. Play conf_umido
  5. Set volume
  6. Play annunciazione
  7. Wait for it to finish
  8. Play conf_umido

Notice how it waits for annunciazione to finish before it proceeds to play conf_umido.

In the second iteration, does it wait for conf_umido to finish playing before it proceeds to set volume and play annunciazione? No.

I suggest you fix that.

1 Like

good catch. I missed the lack of delay on the second iteration to wait for the second audio to stop playing.

Hi for all.
This works:

- id: gg_food_waste  
  alias: gg_food_waste
  trigger:
    platform: time
    at: '12:37:00'
  condition:
    condition: time
    weekday:
      - sun
      - thu
      - sat
  action:
    - repeat:
          count: 2
          sequence:
              - data:
                  entity_id: media_player.gm_mini
                  volume_level: '0.3'
                service: media_player.volume_set
              - data:
                  entity_id: media_player.gm_mini
                  media_content_id: '/media/local/annunciazione.mp3'
                  media_content_type: audio/mp3
                service: media_player.play_media 
              - wait_for_trigger:
                  - platform: state
                    entity_id: media_player.gm_mini
                    from: playing
                    to: idle
                timeout:
                  seconds: 10 
              - data:
                  entity_id: media_player.gm_mini
                  volume_level: '0.3'
                service: media_player.volume_set                  
              - data:
                  entity_id: media_player.gm_mini
                  media_content_id: '/media/local/conf_umido.mp3'
                  media_content_type: audio/mp3
                service: media_player.play_media 
              - wait_for_trigger:
                  - platform: state
                    entity_id: media_player.gm_mini
                    from: playing
                    to: idle
                timeout:
                  seconds: 10                 
  mode: single 

Hereā€™s another way to do the same thing:

- id: gg_food_waste  
  alias: gg_food_waste
  trigger:
    - platform: time
      at: '12:37:00'
  condition:
    - condition: time
      weekday:
        - sun
        - thu
        - sat
  action:
    - variables:
        media: ['annunciazione','conf_umido']
    - repeat:
        count: 2
        sequence:
          - service: media_player.volume_set
            target:
              entity_id: media_player.gm_mini
            data:
              volume_level: '0.3'
          - service: media_player.play_media
            target:
              entity_id: media_player.gm_mini
            data:
              media_content_id: '/media/local/{{ media[repeat.index-1] }}.mp3'
              media_content_type: audio/mp3
          - wait_for_trigger:
              - platform: state
                entity_id: media_player.gm_mini
                from: playing
                to: idle
            timeout:
              seconds: 10 
  mode: single

Hi taras
This solution is very interesting.
The code is much more compact. When the files to be played are more than one, it is very useful.
Thanks

Just commenting on an old post, there is a much easier way to do it now if anyone doesnā€™t know it, reply and I will explain.

Trying to do something similar. Please explain.

When you are writing your automation in actions, select repeat, select number of times do your task in in the task include a step to wait 90 seconds.