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

This is AWESOME
thanks for creating and sharing this!

i had a quick question please…

what is this “master” section for?

data:
      master: media_player.living_room
    entity_id: all
    service: sonos.join

and why is living room (or whatever the master one is) called out specfically on its own again here?

  - data_template:
      entity_id: media_player.living_room
      media_content_id: '{{ sonos_source }}'
      media_content_type: music
    service: media_player.play_media

finally… rather then call out indiviaully entities, could you have a group?
then every time you add a new Sonos speaker, you can add it to the group and it will flow into this?

You set it in the script so you’re sure that in the following steps you’re talking to the master and not to a slave spreaker. That’s also the reason they are first unjoined and then joined again.

media_player.living_room is a group containing 2 speakers. They are merged by Sonos because they are in the same room.

1 Like

ahhh thnaks
i dont have any linked speakers, only 1 sonos per room
so i assume it doesnt matter which one i pick to have there in the code?

No that doesn’t matter which you set as a master, as long as the rest of the script you send commands to that speaker

1 Like

thanks again, this is fantastic

Hey
this seems to have stopped working for me recently and im unsure why?
i checked all my entites and they are all the same

i got an error about the delay, so i wrapped that in single quotes ’ however it still doesnt seem to work

i think i also saw some errors about volume but they are not showing up now

automation:
- 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://homeassistantssd.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.bedroom
      - media_player.ensuite
      - media_player.living_room
      - media_player.spectrum_studio
    service: sonos.snapshot
  - data_template:
      entity_id:
      - media_player.bedroom
      - media_player.ensuite
      - media_player.living_room
      - media_player.spectrum_studio
    service: sonos.unjoin
  - data:
      master: media_player.living_room
    entity_id: all
    service: sonos.join
  - data_template:
      entity_id:
      - media_player.bedroom
      - media_player.ensuite
      - media_player.living_room
      - media_player.spectrum_studio
      volume_level: '{{ volume }}'
    service: media_player.volume_set
  - data_template:
      entity_id: media_player.living_room
      media_content_id: '{{ sonos_source }}'
      media_content_type: music
    service: media_player.play_media
  - delay: '{{ delay }}'
  - data_template:
      entity_id:
      - media_player.bedroom
      - media_player.ensuite
      - media_player.living_room
      - media_player.spectrum_studio
    service: sonos.restore

Could anyone hook me up with the mp3 you are using for the ring?

HomeBee, my use case was slightly different, but my dumbed down solution might help you, if you’re still looking.

I’m running both S1 and S2 Sonos systems in the house so considered adjusting this to serve the file to both an S1 group and an S2 group, but the S1 and S2 grouping speeds seem a bit different and variable depending on what combination of speakers are grouped at the time, so the sync wasn’t ever going to be perfect with the mix of the two systems.

Since that’s the case, I decided not to worry about the sound being sync’ed at all.

My script dumbed down the original and removes the joining of different rooms and just defines the speakers (a mix of S1 and S2) that I want the sound to play on as a comma separated list in the entity_id: each time it is referenced. e.g.

entity_id: media_player.kitchen_sonos_move, media_player.ms_study, media_player.loft

It works well and the sync is only a bit out. The main aim was to hear the door bell in key rooms throughout the house, so job done.

I haven’t had the inclination to test if this might be quicker than joining all the speakers into their S1 and S2 groups and then playing the sound through the two groups, but I wonder if this way each speaker starts playing the chime when it’s ready, rather than waiting for the slowest speaker to group up before playing. Dunno.

Noto

I am struggling. I used the scripts you provided but I cannot hear anything. Perhaps I set the volume too low.

This is your automation script.

This is my automation script.

  action:
  - data:
      delay: 00:00:03
      sonos_entity: media_player.sonos_1
      sonos_source: https://192.168.xxx.xxx:8123/local/zapsplat_emergency_alarm_2.mp3
      volume: 0.1
    service: script.sonos_mp3_one_room
  mode: single

This is the location of the MP3 file on the RPi on which I run HA.

]

This is the location of the MP3 file in Media Browser.

Any and all pointers gratefully accepted.

There seems to be an issue with using local media now through Sonos. There is another thread somewhere on it, I don’t have the link to hand sorry.

I got around this by using my NAS as a media server connected to Sonos, put my local files in there, and then added them to the Sonos app. Lastly created a playlist and then added just the file to that playlist. I then call the playlist instead of the file direct.

Small delay and a bit of a pain, but works.

sonos_doorbell:
  alias: "Sonos doorbell script"
  sequence:
   - service: sonos.snapshot
     data:
       entity_id: media_player.lounge_room_sonos
   - service: sonos.unjoin
     data:
       entity_id: media_player.lounge_room_sonos
   - service: media_player.volume_set
     data:
       entity_id: media_player.lounge_room_sonos
       volume_level: 0.5
   - service: media_player.play_media
     data:
       entity_id: media_player.lounge_room_sonos
       media_content_id: Doorbell
       media_content_type: playlist
   - delay: 00:00:08
   - service: sonos.restore
     data:
       entity_id: media_player.lounge_room_sonos

Much appreciated

Never mind, my mistake was that I did not added a delay after the chime play… Problem solved.

I think I’m having a similar problem with Sonos not being able to play an mp3 from my HomeAssistant media library. Did you find a solution?

No, just got back to it today.

Seems that most people suggest setting up the sounds you want to play in a SONOS playlist through SONOS app and then playing then from HA. There must be a better way.

To be honest I have even lost the basic sounds, such as a door opening, that I had playing on Google Home speakers.

I can see the files in Media Browser and I can even play them from there on the Googel speakers, not the SONOS.

I’ve commented out the Configuration setting to allow then to default.

image

I’ve create a test script, but I can’t hear anything when I play the script.

media_test:
  alias: Media Test
  sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.office
    data:
      media_content_type: wav
      media_content_id: media/Ping_2.wav
  mode: single

I’ve tried lots of different value for media_content_id, but none make a sound, even though I don’t get an error.

Any suggestions? I presume the issue is the media_content_id, but I really cannot work out what value to use. Once I have this working I will go back to SONOS.

Made a little bit of progress using the Sonos app for OSX. I was able to create a Sonos media library and upload my mp3 file to the Sonos media library. I can now see the Sonos Media library when I select a Sonos speaker from the Home Assistant media library by clicking “Choose Player” in the upper right hand corner. Still can’t figure out how to select that file as a source when trying to build an automation though.

1 Like

This is how I solved my Doorbell Issue and it works fine.

alias: Klingel
description: ''
trigger:
  - device_id: 7f20e9523ce98b27ea733c0dbffe2b86
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition: []
action:
  - service: media_player.volume_set
    target:
      entity_id:
        - media_player.airplay_58d3491a6b85
        - media_player.airplay_f434f021772f
        - media_player.airplay_f434f03017e5
        - media_player.airplay_f434f0662f81
        - media_player.hauptschlafzimmer
        - media_player.wohnzimmer
    data:
      volume_level: 0.55
  - service: media_player.play_media
    target:
      entity_id:
        - media_player.airplay_58d3491a6b85
        - media_player.airplay_f434f021772f
        - media_player.airplay_f434f03017e5
        - media_player.airplay_f434f0662f81
        - media_player.hauptschlafzimmer
        - media_player.wohnzimmer
    data:
      media_content_type: music
      media_content_id: http://homeassistant.fritz.box:8123/local/doorbell.mp3
  - service: notify.apple_devices
    data:
      message: Es hat an der Tür geklingelt!
mode: single

The Sound file is in my /www Folder. The Mediaplayers Hauptschlafzimmer/Wohnzimmer are the Sonos Players. The other Media Players are HomePod minis.

I am pretty sure it would also be possible to put the mp3 file in the media folder but never tried this due to no reason.

@magicbenny how are you uploading your files. If I attempt to use either the Media Management or the File Editor the uploads fail because the files are too large. Is there some place to increase the upload file size.

@magicbenny actually I have discovered a few issues to work through with uploading and using files with the Media Management. When using the Nginx SSL Proxy add-on there is a file size issue not present when using the standard HTTP access and port. I need to track down or open up an issue for the add-on in this regard.

Hi Guys,

Before I get into this and give it a try, I’m running the latest version of HA on a Rpi4b with 120gb HD.

In this version of HA, there is already a media folder.

Do I use this folder for my door sounds or do I still have to create a ‘www’ folder?

Darren.

@Dizzwold I am successfully using the Local Media folder. The only problem I’ve run into with it is uploading files when using the Nginx HA SSL Proxy. If I connect to my HA without going through the SSL proxy I can upload the sound files no problem to the Local Media folder. I haven’t had a chance to dig in farther with the Nginx Proxy to find a solution. Here is an example of what I have in my alarm script.

service: media_player.play_media
data:
  media_content_id: /media/local/mixkit-facility-alarm-sound-999.wav
  media_content_type: audio/wav
  enqueue: play
target:
  device_id: xxxxxxxx