Sonos door bell automation (play previous track)

I have setup the below code to play a door bell noise via the sonos speakers when the back gate gets opened.
Only issue is when listening to music the door bell will kick in, but I then have to put music back on. is there a way that I can go back to previously track after door bell has been played ?

  • alias: doorbell
    trigger:
    • platform: state
      entity_id: binary_sensor.aeotec_zw089_recessed_door_sensor_gen5_sensor_11_0
      to: ‘on’
      action:
    • service: media_player.volume_set
      data:
      entity_id: media_player.family_room
      volume_level: 0.75
    • service: media_player.play_media
      data:
      entity_id: media_player.dining_room
      media_content_id: http://XXX.XXX.XX.XX:8123/local/doorbell-1.mp3
      media_content_type: music

Maybe you can find some inspiration here SONOS TTS Script

Mind if I ask what folder you copied the mp3 to and what the bitrate, sampling frequency or any other specifics happen to be? I can’t seem to get any mp3s to play through.

put file into /home/homeassistant/.homeassistant/www/doorbell.mp3

restart Hass

test via http://ipaddress:8123/local/doorbell.mp3

don’t have bit rate to hand sorry

1 Like