Yet another Sonos / playing an MP3 issue

I am trying to get Sonos to play an MP3 file when triggered by a sensor, a topic that has been aired a couple of times. Here is the relevant part of the script

      - service: media_player.play_media
        data_template:
          entity_id: "{{ sonos_entity|default('media_player.kitchen') }}"
          media_content_id: "{{ file|default('https://www.ha-******.duckdns.org:8123/local/dog.mp3') }}"
          media_content_type: music

No error is being raised on HA and the Sonos app on the PC receives the file request ,but responds with “Unable to play ‘dog-barking.mp3’ - the song is not encoded correctly.” A bit of research via the Sonos Forum suggests that this typically because of network problems.

Via the Developer tool I have called media_player.play_media with every possible form of file format I could come up with and also tried content type as music and audio/mp4 with each combination.

I am running HA version 101.3

I have an HA script to play TTS messages which is working fine

Sonos software is up to date

The mp3 file plays correctly on Sonos when selected via Sonos, so the format of the file is ok.

I suspect that the answer is blindingly obvious but I am not sure what to try next.

1 Like

Finally resolved.
And it was not obvious, at least not to me. a directory called WWW has to be created in Config and the media file held there. then the default path above works.

Does this directory still need to be created if I’m using Home Assistant supervised? I used Samba to add my mp3 to what I believe is the default media directory. Using this tip for locating the URL I get:

http://192.168.1.100:8123/media/local/airhorn.mp3

But no luck getting it to play on Sonos. I can see and play the mp3 in the Media Browser when I select Web Browser with the “Choose Player” option in the upper right hand corner.

If I try to go directly to that URL in my browser I get “401: Unauthorized” and when I open up my Sonos app I can see airhorn.mp3 listed as the thing most recently played but if I hit the play button I get “Unable to play ‘airhorn.mp3’ - access is denied.”