Restore to previous state after automation trigger

I want to have my doorbells on my Sonos speakers, which in itself works fine (Automation just triggers once). However after playing the doorbells the speakers should return to the previous state. So e.g.:

  1. Speakers are playing something from Spotify (works fine)
  2. Doorbell get’s triggered (works fine)
  3. Speakers should stop Spotify and play the doorbell sound (works fine)
  4. After the doorbell the Speakers should resume the Spotify playback just where they stopped

Since I’m new to Home Assistant I honestly have no clue how to save the old state and restore it. Right now they are just quiet after playing the doorbell sound.

Sonos Snapshot: Sonos - Home Assistant

Keep this in mind when using sonos.restore.

Thanks to both of you. It’s working perfectly fine for local music now. However as @123 already indicated it doesn’t work at all with Spotify. Is there any workaround to get it somehow working?

The current approach:

alias: Türklingel in Büro
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fenster_1
condition: []
action:
  - service: sonos.snapshot
    data:
      entity_id: media_player.buro
  - service: media_player.play_media
    target:
      entity_id: media_player.buro
    data:
      media_content_id: media-source://media_source/local/doorbell.mp3
      media_content_type: audio/mpeg
    metadata:
      title: doorbell.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - service: sonos.restore
    data:
      entity_id: media_player.buro
mode: single

A workaround would be to store all of the information about what’s currently playing on Spotify (including the time elapsed in the song), stopping it, playing the doorbell sound, then using the stored information to specify what Spotify should play. Even this won’t work if you can’t tell Spotify to play a song starting at a specific time within the song.

I’ve take a look at the documentation and a quick one at the source code of the Sonos integration and it doesn’t seem like there would be a way to do that. On top of that it’s impossible to use the Spotify integration or take a look at the official Spotify API since Sonos devices are not supported by the official API: Spotify - Home Assistant
Seems like there would be no solution to the problem :frowning: