Sonos Snapshot / Play / Restore

I am trying to play an mp3 when on boolean change trigger.
It works but I get with behaviour :

  • Sonos group is playing some spotify music
  • Input boolean to off
  • The automation starts
  • The random mp3 starts to play
  • After a second mp3 stops and the original original music is restarting.
    media_player.sala is the coordinator and the music and the mp3 should playing an all the sonos.

What is wrong with this?



       #### SNAPSHOT

    - service: sonos.snapshot
        entity_id: media_player.sala
        with_group: true

        ##### SETTIAMO IL VOLUME A 40

    - service: media_player.volume_set
        volume_level: 0.40

          - media_player.bagno
          - media_player.camera_da_letto
          - media_player.cucina
          - media_player.sala

    - service: media_player.play_media
        entity_id: media_player.sala
        media_content_id: "{{range(1,2) | random}}.mp3"
        media_content_type: "music"

    - service: sonos.restore
        entity_id: media_player.sala
        with_group: true

I assume you have to insert a delay before restoring.
Something like:
- delay: '00:03:00'
Then restore will be executed not immediately, but after respective delay-time. (in example delay-time is 3 minutes)

Thanks but it couldn’t be the right solution: every mp3 has different lenght (even minutes: the mp3 are songs).
Maybe I can’t snapshot / restore in this way ?

Found this post about ‘wait_template’.
Maybe it helps. (Did not try it myselves!)

Have you seen this custom component? Does away with the need to snapshot/restore and all.

I didn’t look at this component up to now, as my tts-anouncements work fine.
As I understand music plays on and a short clip (with higher volume) is overlayed.
Don’t think this is usefull in your usecase, as this would mean two songs would play at the same time.

Right now, I’m using this solution: I do a snapshot on the input boolean ON trigger and the restore on input boolean OFF.
It’s not perfect but, in this case, it’s working for me.
(At the end of the mp3 I have to say “turn boolean off”, of course)