Automation Help - Sonos Play sound, doorbell rings

Hey all,
i had this all working before but it stopped working a few versions ago, not sure which im afraid as i didnt really realise until a few days ago.

My goal is to play a doorbell sound on all sonos speakers, when the doorbell rings.

i recently added “base_url” to the TTS, but that didnt seem to help either.

Nothing shows up in the logs.

Config:

# Text to speech
tts:
  - platform: google_translate
    base_url: http://xxx:8123

Automaton

- id: play_doorbell_sound_all_sonos
  alias: Play Doorbell Sound on All Sonos Devices
  trigger:
  - entity_id: binary_sensor.front_door_ding
    from: 'off'
    platform: state
    to: 'on'
  action:
  - data:
      delay: '00:00:01'
      sonos_source: http://xxxx.local:8123/local/audio/doorbell.mp3
      volume: 0.4
    service: script.sonos_mp3_all_rooms

script:

sonos_mp3_all_rooms:
  alias: Sonos - MP3 - All Rooms
  sequence:
  - data_template:
      entity_id:
      - media_player.sonos_bedroom
      - media_player.sonos_ensuite
      - media_player.sonos_living_room
      - media_player.sonos_spectrum_studio
    service: sonos.snapshot
  - data_template:
      entity_id:
      - media_player.sonos_bedroom
      - media_player.sonos_ensuite
      - media_player.sonos_living_room
      - media_player.sonos_spectrum_studio
    service: sonos.unjoin
  - data:
      master: media_player.sonos_living_room
    entity_id: all
    service: sonos.join
  - data_template:
      entity_id:
      - media_player.sonos_bedroom
      - media_player.sonos_ensuite
      - media_player.sonos_living_room
      - media_player.sonos_spectrum_studio
      volume_level: '{{ volume }}'
    service: media_player.volume_set
  - data_template:
      entity_id: media_player.sonos_living_room
      media_content_id: '{{ sonos_source }}'
      media_content_type: music
    service: media_player.play_media
  - delay: '{{ delay }}'
  - data_template:
      entity_id:
      - media_player.sonos_bedroom
      - media_player.sonos_ensuite
      - media_player.sonos_living_room
      - media_player.sonos_spectrum_studio
    service: sonos.restore

origional post: SONOS doorbell sound trough local mp3 file. Script + automation done but still not working

3 Likes

I’m running a similar setup and I’m struggling with 5-10sec delays before the sound plays after pressing the door bell.
I’ve had to add wait templates in between the service calls because it would sometimes do things out of order…
Is the unjoining part of your automation necessary though? If you join all to the living room that shouldn’t matter, or does it?
As a test, can you try adding 5s delays between each step? You could find out if it’s a time based issue - i.e. the speakers are still taking a snapshot while they are receiving the command to play and then to restore immediately :thinking:

1 Like

Hey!
got it working, the issue was i was pointing it to “homeassisant” not the IP

ive now changed it to the IP and it all works fine (for the file to be player)

so:

  - data_template:
      entity_id: media_player.sonos_living_room
      # media_content_id: '{{ sonos_source }}'
      media_content_id: 'http://192.1xxxx:8123/local/audio/doorbell.mp3'
      media_content_type: music
    service: media_player.play_media
1 Like

Did someone tried using https instead of http in media_content_id?
I have two installations the prod environment uses https and non prod uses http, below doorbell code works (takes camera snpshot, posts notification, sends message to EchoDot) on both servers except playing mp3 doorbell ring on Sonos player which only works on non prod server using http. Any idea how to make mp3 file working with https on Sonos?


- id: Doorbell_Ring
  alias: 'Doorbell Ring'
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.doorbell
    to: 'on'
  action:
# take camera snapshot
  - service: camera.snapshot
    data_template:
      entity_id: camera.entryway_entryway
      filename: '/config/www/doorbell/doorsnap{{ states.counter.doorbell_ctr.state }}.jpg'
# take Sonos snapshot before playing mp3
  - service: sonos.snapshot
    data:
      entity_id: media_player.living_room
# announce on office Alexa EchoDot
  - service: notify.alexa_media
    data:
      data:
        type: announce
        method: all
      target: media_player.mukesh_s_echo_dot
      message: 'Attention, someone is at door'
# increment camera snapshot counter
  - service: counter.increment
    entity_id: counter.doorbell_ctr
# post HA notification
  - service: persistent_notification.create
    data:
      message: 'Doorbell Ring Received!'
      notification_id: '0151'
      title: Alert
# set Sonos volume & play mp3 file
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room
      volume_level: 0.4
  - service: media_player.play_media
    data:
      entity_id: media_player.living_room
      media_content_id: 'https://192.168.0.xxx:8123/local/doorbell.mp3'
      media_content_type: music
  - delay: '00:00:04'
# restore Sonos
  - service: sonos.restore
    data:
      entity_id: media_player.living_room
1 Like