The only way, I got this working, is adding a delay. This delay must be one second longer, than the first mp3.
The automation does not look, how long your mp3 is. It fire’s the action to play the first file, and right after it it fire’s the second, so the first is “overruled”.
This way the automation wait’s, until the first file finish and fire’s the second command after the delay.
Works fine here…
alias: gg_food_waste
trigger:
platform: time
at: '19:45:00'
condition:
condition: time
weekday:
- tue
- thu
- sat
action:
- data:
entity_id: group.google_mini
volume_level: '0.7'
service: media_player.volume_set
- data:
entity_id: group.google_mini
media_content_id: '/media/local/1.mp3'
media_content_type: audio/mp3
- delay: '00:04:32' #The lenght of the first mp3 plus one second
service: media_player.play_media
- data:
entity_id: group.google_mini
media_content_id: '/media/local/2.mp3'
media_content_type: audio/mp3
service: media_player.play_media
An alternative to using delay is a wait_template that waits for the media_player’s state to not be playing (in other words, it waits until the media_player has finished playing the first mp3 file). If you do this, don’t overlook to include a timeout value so (in case something goes wrong) it doesn’t wait forever.
For more information, see the example in the documentation for wait_template.
Before the wait template Tara’s talk about there must be at least two seconds delay to make sure the state of the media player changes to “playing”
Hellis81 is right; it takes a finite amount of time for the media_player to report it’s playing the first mp3 so the wait_template might act on the media_player’s initial non-playing state. The inclusion of a very short delay would ensure the media_player has time to report its latest state prior to executing the wait_template.
Another approach, that wouldn’t need any delay, would be to use a wait_for_trigger. It can employ a State Trigger that looks for a state-change like from: playing with an optional to: idle to indicate when the media_player has ceased playing.