Sonos Cannot Play Local MP3 File

I uploaded ‘chime.mp3’ to my local media folder. If I go into the media player, I can get the file to play to the correct speaker, HOWEVER, a service call does nothing. Where is my error?


service: media_player.play_media
target:
  entity_id: media_player.sonos_office_wall_speaker_real
data:
  media_content_id: |
    media-source: "http://192.168.xxx.xxx:8123/media/chime.mp3"
  media_content_type: music
  announce: true
  extra:
    volume: 80

Sonos doesn’t like http links. Have the Sonos controller app open on a device and watch the speaker you are trying to play to. When you do the service call, you should see a message in the Sonos controller app say something about “could not connect”. I’ve only gotten my service calls to work with https links. Not sure why the media browser works though… Of course that means you have to have a valid ssl cert for Sonos to recognize and connect.

Also, I split out my commands when I play something on my Sonos. I set the volume, then I send the play call. announce isn’t needed for music, only tts and even then it’s implied and hardcoded in a tts command.

      - service: media_player.volume_set
        data:
          entity_id: media_player.kitchen
          volume_level: 0.25
      - service: media_player.play_media
        data:
          entity_id: media_player.kitchen
          media_content_id: "https://path:port/local/sounds/sound.mp3"
          media_content_type: music

This is not true, plain HTTP links work just fine. If you’re having issues using them, there is some other reason the Sonos devices are unable to connect to the host in your URL.

Your media_content_id is likely not quite correct. Easiest way to validate is to start creating a new automation (you won’t need to use/save it). Select “Play media” as the Action, choose a Sonos device, and them select the media you want to play. Switch to YAML and you’ll see the generated service call.

In my case, I have media_source configured like this:

homeassistant:
  media_dirs:
    sound_files: /config/www/sound_files

With the above automation step, the generated value looks like this:

media_content_id: media-source://media_source/sound_files/doorbell-front.mp3

i can’t save the automation, Sonos does play the local file, but I just can’t save the automation
i get this error

" Message malformed: expected dictionary @ data[‘sequence’][0]

this is my 2 service calls, i played the file then watched the id in the services and got the right entity id and it’s working , when i try to save the call service for an automation or script i get error mesage

here is my call service yaml
there’s a question mark at the end of the file name, it was in the entity id when i looked it up, i tired with and without it , i can’t save

  • service: media_player.volume_set
    data:
    entity_id: media_player.living_room_sonos
    volume_level: 0.2

  • service: media_player.play_media
    data:
    entity_id: media_player.living_room_sonos
    media_content_id: http://192.168.0.2:8123/media/sound_files/relaxed.mp3?
    media_content_type: music

i’m so mad, it took me a whole night to get it to work and i was happy when it start working, but unfortunately I wasn’t happy for a long time because I couldn’t save

For future reference, the error message complained about “Message malformed” but no one can determine if your service calls have proper YAML syntax because you didn’t post them in YAML format.

I suggest you review FAQ guideline 11 - Format it properly:

I was able to get Sonos local media to work, but mounting the media file messed up my frigate storage.
I used this in my config,yaml and it worked to call local mp3 but frigate stopped working,

  • homeassistant:
    media_dirs:
    sound_files: /config/www/sound_files.

my setup is supervisor HA , my main config/ install on a sata ssd, and i moved data disk to another nvme ssd.
So now all my media is stored on the 2nd ssd, but the configuration is on the first one.

how can I mount the media directory on the 2nd ssd, any help will be really appreciated.

You posted yet more unformatted YAML.

Same issue overhere cant play a local mp3 with my sonos media players. The doorbell automation always worked like a charm but recently it stopped.

Solved it by using the dlna services to play the mp3 from my Synology.

If anyone does know what to do to play the mp3 again from local then please!

I don’t know if you’ve figured this out or not, but I got local MP3s working by using WinSCP to put my files in /root/homeassistant/www/ then using the following to play on the Sonos:

  - service: media_player.play_media
    target:
      entity_id: media_player.sonos_office
    data:
      media_content_type: music
      media_content_id: /local/my_file.mp3

Can you share the rights on the file?

I did the same thing but it aint working…

rw-r–r-- (644) for both

I play sleep sounds on mine every night this is what I use. It randomly chooses between 3 different files to play

service: media_player.play_media
metadata: {}
data:
  media_content_type: music
  announce: false
  media_content_id: >-
    {{ ["/local/Audio/OceanSounds.mp3", "/local/Audio/RainSounds.mp3",          
    "/local/Audio/ThunderStormSounds.mp3"] | random }}
target:
  entity_id: media_player.master_bedroom
1 Like