Automation to play radio station on Sonos One

hi.

As per the title i would like to have an automation to play a radio station at a certain time but this works on a google puck device but the radio part doesnt work on a sonos one:

- id: Bedroom 4 Wake Up Routine
  alias: Bedroom 4 Wake Up Routine
  trigger:
  - at: '20:40'
    platform: time
  condition: []
  action:
  - service: tts.google_say
    entity_id: media_player.bedroom_4_sonos
    data:
      message: 'Good Morning'
  - delay: '00:00:05'
  - service: media_player.play_media
    entity_id: media_player.bedroom_4_sonos
    data:
      media_content_id: https://radio.virginradio.co.uk/stream-tunein
      media_content_type: music

Any ideas? Or anyone have an Sonos automations which will play a radio station ?

This is the error I get when trying on a Sonos one:

Log Details (ERROR)

Wed Jul 03 2019 22:14:28 GMT+0100 (British Summer Time)
Error on play_media with UPnP Error 714 received: Illegal MIME-Type from 192.168.1.43

Thanks!

Mark

Update! - fixed it by using the URL:
x-rincon-mp3radio://radio.virginradio.co.uk/stream-tunein

1 Like

After setting up Mopidy and Icecast to stream to our Sonos Play:1, I faced the same issue.

Your hint solved the problem and we’re able to play Spotify using this setup on Sonos.

Hopefully this keeps working :blush:

Can you show me some examples about what you did to play spotify on sonos?

Sure. I am building a new local hass.io addon best on BestLibre’s Mopidy addon which adds Icecast during the installation along with a few extra Mopidy extensions like MQTT control.

When you start playing music on Mopidy, the output is sent to Icecast which outputs the audio to a local stream on your hass.io installation.

E.g. http://hassio.local:8000/mopidy

This local stream can be sent to Sonos using the media_player integration of your Sonos by adding it to the media_content_id parameter of the media_player.play_media service.

E.g.

entity_id: media_player.your_sonos
media_content_id: x-rincon-mp3radio://hassio.local:8000/mopidy
media_content_type: music

This is still a work in progress and I have to test it more thoroughly to see if the music keeps playing without to much pauses.

1 Like

Hmm… i have hassbian and not hass.io so i don’t think i’ll be enable to do this…

Perhaps you can migrate towards hass.io since hassbian has been discontinued

Yes, i know it, but for the moment i do prefer to stay with hassbian…

At least you now know what you can do if you’d change your setup one day :blush:

Oh yes, of course now… :slight_smile:

Hi Geoffrey,

I wonder if you can help?

I have successfully got a stream to play to icecast2 on a separate RPI on 192.168.1.239:8000/stream. I can hear everything well when I browse to it.

Looking at what you’ve done beyond that to get the media player to pick up this stream, I’m a little confused.

I have tried in configuration.yaml;

media_player:

  • platform: mpd
    host: 192.168.1.239
    port: 8000/stream

However, the media player states it’s unavailable.

Can you explain your last steps so I can get on Hass.io please?

Thanks in advance.

Please note that I have icecast running alongside Mopidy and not just icecast. Mopidy (which also has an mpd interface) outputs its audiostream to an icecast server.

The configured MPD media_player is used to change what music Mopidy is playing and streaming towards icecast and is not used to output the audio directly to a device like a Sonos.

Do you use Mopidy or mpd in your setup? If not, then I assume you do not need the separate media player configuration you mentioned.

What I then do is take the output URL from icecast, in your case http://192.168.1.239:8000/stream and send it to a second Sonos media player using the media_player.play_media service with the following values

entity_id: media_player.your_sonos
media_content_id: x-rincon-mp3radio://192.168.1.239:8000/stream
media_content_type: music

I hope that helps to clarify things for you.

Thanks Goeffrey,

Where are you setting up this data please (is it in lovelace or config.yaml?)

This is what you use to invoke the Home Assisant service. When testing things out, you can use this in the Developer tools

Afterwards you can use it in e.g. an automation as an action that calls the same service.

Thanks for coming back to me Geoffrey,

I’m still somewhat confused about how to get the sound to Lovelace ultimately.

Currently I have FFMPEG on a separate RPI which streams to icecast2. If I browse to it I can hear the microphone attached to the RPI.

If I go to the Mopidy web ui in Hassio and I go to Iris and I enable Icast with the same url I can also hear the microphone (even though the Mopidy server constantly states it is connecting and never does).

I know icecast is on port 8000 and I know MPD is 6600 and Mopidy is 6680.

If I set up an MPD player in configuration. yaml, and I state that this is localhost on 6600 or 192.168.1.239 on port 8000 it says it’s unavailable.

I am confused by;
x-rincon-mp3radio: ? Do I need this or just http:

I am confused by the service call and automation. Are they still required with my set up or is that more to do with music and Sonos?

Sorry to be a pain. When you can hear what you need via an add on, but you don’t knoe how to get it in the front end, it’s a little frustrating.

Thanks for your patience and help.

Glenn

Hi Glen

I’m not sure what your end goal is. Are you trying to play the icecast stream through Mopidy in your browser and if so in Lovelace and not in Iris? In our setup, it is the output from Mopidy that needs to be played on other media player devices like Sonos.

It is specifically for the output to Sonos that we use the x-rincon-mp3radio:// in the media_content_id.

The screenshot you share seems to mix things up. The host and port in the Iris settings in my case is the server where Mopidy is running, not the stream I’m playing. That’s probably why the system cannot connect to Mopidy.

In our setup Mopidy is configured to output its stream itself to icecast as described here:

https://docs.mopidy.com/en/latest/audio/#streaming-through-icecast

I’m not a 100% sure if the services shown by Iris in the settings are the configuration of Mopidy or from Iris itself. In my case it does indeed work when I choose to stream the content to the browser, but I also see the URL of the stream itself there what seems to be different in your case.

I know that Thomas Loven has a way to make your browser act as a media player, but I have no experience with that and am not sure if it helps in achieving what you try to achieve

Also you might be interested in what @vittoriom excellently wrote up on his blog a while ago in using a similar approach using Chromecasts: