Play local mp3 on Sonos error

Hmm only other thing I can suggest is put in mp3 instead of music.

Use

media_content_type: ‘audio/mp4’

Yw.

I also tried that without any change.

This is my script that 100% works on Sonos One / Sonos Connect

radio_cast:
  alias: Cast Selected Radio on Sonos Speakers
  sequence:
    -  service: media_player.play_media
       data_template:
         entity_id: >
          {% if is_state("input_select.speakers", "Kitchen") %} media_player.kitchen
          {% elif is_state("input_select.speakers", "Livingroom") %} media_player.livingroom
          {% elif is_state("input_select.speakers", "Bedroom") %} media_player.bedroom
          {% endif %}
         media_content_id: >
          {% if is_state("input_select.radio_station", "Jayan Radio") %} !secret radio_url
          {% endif %}
         media_content_type: 'audio/mp4'

Sonos might need the full Http/Https url.

Try for example http://ip.to.your.pi:port/local/filename.mp3

A quick search for the above came up with …

http://hass_ip:8123/local/your.mp3

and use music as the type.

1 Like

Entering the full path did the trick :slight_smile:
both ´music´ and ´audio/mp4´ Works.

Thanks :slight_smile:

1 Like

I can confirm, it works here as well. This is my yaml:

    - service: media_player.play_media
      data:
        entity_id: media_player.bad
        media_content_type: music
        media_content_id: 'http://10.0.1.85:8123/local/Test.mp3'

The mp3 is in the folder /config/www/

Be me this works now. Streaming URL radio is not working. Did you have success that?

Hi. No I have not tried with URL radio streaming.
I just use the name from the source list for each media player.

How can i play mp3 file such as from NAS?

Thanks for your post. It was a life saver.
I had been working on it for 3 days. None of the other links gave the location of the mp3 file. I was trying /config/media/ and that doesn’t work. It also doesn’t work without the 8123 port.

Hello,

Have just begun my journey to have announcements on my Sonos. Found your code, but after trying to include it in my configuration.yaml file I received a bunch of errors.

- service: media_player.play_media
      data:
        entity_id: media_player.bad
        media_content_type: music
        media_content_id: 'http://10.0.1.85:8123/local/Test.mp3'

Could you please give me some context, such as where the code is added, and I assume this could just be triggered by an automation? Also, in relation to the media_content I assume the mp3 files are in a directory under /config??

Thanks, Mark

Not sure I understand what you mean by “where the code is added” ?

The code forms part of a script that will play audio to a (sonos) speaker. If you search for “Sonos TTS”, there are a number of examples that show you how this works.

You can either create scripts manually (which is what most people tend to do once they know how), or use the scripting tool within HA.

Probably like a lot of others, we are looking for where to put the codes you post to do something. any yaml? (config/script/automat/etc.) and what part it is, or what precedes it? The question was to play music and we get utfg on TTS. If someone is interested in TTS, they will find it themselves, right? This whole community shares snippets of meaningless code, without continuity, it’s nice that you know, but no one else does.

I share your pain… unfortunately that has been my personal experience. Mind you I am appreciative of those people that share, just sometimes the gurus may forget those of us that are rookies, and it takes us time to ‘get it’ with the coding.

I’ve likened my experience to reading a crime novel… picking up clues as I go, hopefully solving the mystery at the end. Can be frustrating at times, and doesn’t help when guru’s run out of patience with those of us finding our way.

Not sure if it helps… but this community is literally the same as others, so try not to be discouraged.

I understand your frustration, but unfortunately where you put the code is down entirely to how you have configured and manage your Home Assistant installation.

In the case of the script snippet, at a basic level it goes in scripts.yaml. However, depending on how you configure your setup, this will need to be edited to work (ID’s, location, etc)

For example, in my case, I have split all my yaml code (see Splitting up the configuration - Home Assistant ) and if you read that section (and the examples) you will notice that everyone does it differently. Some will break their code down into very small sections and individual yaml files (as I do) whilst others will create larger files containing (for example) all their scripts.

Below is a screenshot from my Git account showing (at a high level) how I organise my code.

It is unique to me, although a number of other people will use similar structures.

This is why you will invariably see just code snippets posted, because everyone manages their code differently. The code I posted will work, you just need to understand where to post it within your own personal HA setup.

For me, this is a life saver.
I have currently 5 sonos devices that now serve the purpose of our doorbell.
They however don’t ring simultaneous which I believe is “normal”, or I should group them first (but I think that will slow everything down too much).
What I do find annoying is that the local mp3 stays in the playlist :slight_smile: so after the playlist is done, we hear the doorbell.m3a again.
Does anyone have a fix for that?

Yes you could join them together. That’s what I do, iIf they are not playing.

Are you setting announce to True? This prevents it from being added to the queue and plays it over whatever is currently playing.

1 Like

You already nailed it I think.
I now used Enqueued (and then offcourse it’s normal that it queue’s the file, stupid of me), I changed it to announced and set the toggle to on.
It’s too late to test now, kids are already sleeping, will try tomorrow.
Thanks!