Chromecast Radio with station and player selection

Thanks for try to help me :slight_smile:

now i have it but
Ttile : script
Play Radio on Chromecast Audio
Activate button that not make any think.

what wrong?

@Bob_NL: Impressive! I just tried this and it worked like a charm once I had figured out what address to use for live Swedish Radio. Thanks!

And for anyone looking for Swedish radio, use the playlists found here: Sveriges Radio and the workaround at the bottom of the page (renaming pls/m3u links to .mp3)

5 Likes

Thank you. I incorporated your changes. It worked great. Where do I find these links for streaming radio links? I found few of them (SHOUTCast) but they didn’t work via the browser.

Thanks OP, great script. Added it and works a treat.
Only issue is it only appears to like mp3, m3u don’t play. Any idea?

1 Like

I set this up yesterday too - excellent idea, thanks for this!

I had a few problems getting it to work with BBC Radio stations, as they seem to be .m3u8 links which I think I’ve determined means that they’re in HTTP Live Streaming format.

After a bit of searching and faffing around, i worked out that you need to change the media_content_type from audio/mp4 to application/x-mpegurl and it then works fine. I’m only using BBC radio in my setup, so I just used the script as is and changed the media_content_type at the bottom. If you were using a mix of MP3 and HLS streams, you’d probably need to add another if block to set the parameter individually per station…

My station list looks like this so far :

               media_content_id: >
            {% if is_state("input_select.radio_station", "BBC Radio 1") %} http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_one.m3u8
            {% elif is_state("input_select.radio_station", "BBC Radio 4") %} http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_fourfm.m3u8
            {% elif is_state("input_select.radio_station", "BBC 6 Music") %} http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_6music.m3u8
            {% endif %}
           media_content_type: 'application/x-mpegurl'
3 Likes

Just try out different sources, shoutcast, tunein etc. I’ve had good luck saving the file and then opening into notepad ++ to see the url.

I got the right URL’s but they are failing to run due to incorrect media_content_type.

Is there any way we could have different media_content_type based on radio_station?

Ex:

 media_content_id: >
            {% if is_state("input_select.radio_station", "BBC Radio 1") %} 
                  http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_one.m3u8
                 media_content_type: 'application/x-mpegurl'
            {% elif is_state("input_select.radio_station", "Radio 538") %} 
                 http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
                 media_content_type: 'audio/mp3'
            {% endif %}
           media_content_type: 'audio/mpeg'

Thanks for this. My version I’ve been using for months was just a dedicated script for each station!

Was nice to do something that actually worked to finish off the day - the 12 hours of trying to install Debian, Debian Server, Ubuntu, Ubuntu Server and get HomeAssistant running on something heftier than my Pi 3 was a failure.

If like me you have your audio devices plugged into an AVR or such there is an excellent piece of Automation you might like to add to run alongside this courtesy of @ih8gates - I don’t know where the original is but here is my automation for a ChromeCast Audio that auto switches ON or OFF the AVR and selects source. My CCA is media_player.khonsu and the AVR is media_player.kitchen_avr - the source input for CCA is an optical port AUDIO1

[details=Automation:]…

# kitchen_AVR_khonsu_off:
- alias: Khonsu stops playing
  trigger:
      - platform: state
        entity_id: media_player.khonsu
        to: 'off'
  action:
    service: homeassistant.turn_off
    entity_id: media_player.kitchen_avr

# kitchen_AVR_khonsu_on:
- alias: khonsu begins playing
  trigger:
      - platform: state
        entity_id: media_player.khonsu
        to: 'playing'
        from: 'idle'
      - platform: state
        entity_id: media_player.khonsu
        to: 'playing'
        from: 'off'

  action:
    - service: media_player.turn_on
      entity_id: media_player.kitchen_avr
    - service: media_player.select_source
      data:
        entity_id: media_player.kitchen_avr
        source: AUDIO1[/details]

…[/details]

1 Like

@lolouk44 I see @bonterra has a solution for your problem :slight_smile: :

Thanks @Bob_NL but that doesn’t seem to work for me.
The link is http://media-ice.musicradio.com/ChillMP3.m3u,
Replacing m3u with mp3 as per the suggestion returns “The file you requested could not be found”
I’ve tried both http://media-ice.musicradio.com/ChillMP3.mp3 and http://media-ice.musicradio.com/Chill.mp3

@lolouk44 try this:

http://media-the.musicradio.com/ChillMP3

Note: I retreived this link by simply opening the m3u file with notepad. A m3u file is nothing more than a redirect for music players. Keep that in mind for if you want to add more streams.

Thanks @Bob_NL for this wicked implementation!

Do you have any hints of finding radio streams? All the ones you have in your config example work, but I do not know the first thing about adding my local radio stations. I added a couple of entries that I thought were right after inspecting the page source into the script, and the input_select script put they never stream. Would you have any pointers for me please?

Oh, and forgot to mention that the same config works great for anyone with a mopidy instance as well, not just chromecast.

input_select.yaml

  radio_station:
  name: 'Select Radio Station:'
  options:
    - Radio 538
    - Q-Music
    - 3FM
    - 100% NL
    - Veronica
    - Sky Radio
    - Arrow Classic Rock
    - Classic FM
    - BNR Nieuwsradio
    - SLAM! Hardstyle
    - Sleep Radio
    - Ambient Sleeping Pill
    - Radio Art - Sleep
    - Ambi Nature Radio
    - Calm Radio - Sleep
    - Dinamo.FM Sleep
    - CKBW Bridgewater
    - 89.9 The Wave
 home_radio:
  name: 'Select Speakers:'
  options:
    - ManCave
    - LivingRoom
    - MasterBedroom
    - Bathroom
  initial: ManCave
  icon: mdi:speaker-wireless

scipt.yaml

 radio_house:
   alias: Play Radio on Chromecast Audio
   sequence:
     - service: media_player.volume_set
       data:
         entity_id: media_player.nexus_player
         volume_level: '0.35'
     -  service: media_player.volume_set
        data:
          entity_id: media_player.master_bedroom
          volume_level: '0.20'
     -  service: media_player.volume_set
        data:
          entity_id: media_player.mpd
          volume_level: '0.30'
     -  service: media_player.volume_set
        data:
          entity_id: media_player.bathroom
          volume_level: '0.30'
     -  service: media_player.play_media
        data_template:
          entity_id: >
           {% if is_state("input_select.home_radio", "LivingRoom") %} media_player.nexus_player
           {% elif is_state("input_select.home_radio", "MasterBedroom") %} media_player.master_bedroom
           {% elif is_state("input_select.home_radio", "ManCave") %} media_player.mpd
           {% elif is_state("input_select.home_radio", "Bathroom") %} media_player.bathroom
           {% endif %}
          media_content_id: >
           {% if is_state("input_select.radio_station", "Radio 538") %} http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
           {% elif is_state("input_select.radio_station", "Q-Music") %} http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3
           {% elif is_state("input_select.radio_station", "3FM") %} http://icecast.omroep.nl/3fm-bb-mp3
           {% elif is_state("input_select.radio_station", "100% NL") %} http://stream.100p.nl/100pctnl.mp3
           {% elif is_state("input_select.radio_station", "Veronica") %} http://8543.live.streamtheworld.com/VERONICACMP3
           {% elif is_state("input_select.radio_station", "Sky Radio") %} http://8623.live.streamtheworld.com:80/SKYRADIOAAC_SC
           {% elif is_state("input_select.radio_station", "Arrow Classic Rock") %} http://91.221.151.155/listen.mp3
           {% elif is_state("input_select.radio_station", "Classic FM") %} http://19143.live.streamtheworld.com/CLASSICFM_SC
           {% elif is_state("input_select.radio_station", "BNR Nieuwsradio") %} http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03
           {% elif is_state("input_select.radio_station", "SLAM! Hardstyle") %} http://vip-icecast.538.lw.triple-it.nl/WEB17_MP3
           {% elif is_state("input_select.radio_station", "Sleep Radio") %} http://37.59.28.208:8722/stream
           {% elif is_state("input_select.radio_station", "Ambient Sleeping Pill") %} http://perseus.shoutca.st:8447/h
           {% elif is_state("input_select.radio_station", "Radio Art - Sleep") %} http://live.radioart.com/fSleep.mp3
           {% elif is_state("input_select.radio_station", "Ambi Nature Radio") %} http://94.23.252.14:8067/stream
           {% elif is_state("input_select.radio_station", "Calm Radio - Sleep") %} http://streams.calmradio.com/api/39/128/stream
           {% elif is_state("input_select.radio_station", "Dinamo.FM Sleep") %} http://channels.dinamo.fm/sleep-aac
           {% elif is_state("input_select.radio_station", "CKBW Bridgewater") %} http://player.listenlive.co/32161
           {% elif is_state("input_select.radio_station", "89.9 The Wave") %} http://chns.streamon.fm/
           {% endif %}
          media_content_type: 'audio/mp3'

Thanks,

1 Like

Only direct links work with this (so the url should instantly play in your browser). Try Googling for “direct radio links” for your country. Thanks to @benjimatt I was able to extract a lot of links from Tunein Radio as well (unfortunately not all of them). Follow his instructions from this post:
https://community.home-assistant.io/t/need-help-chromecast-audio-media-center-plex-kodi/12361/3?u=bob_nl

If you only have a m3u link you can simply save the file somewhere and open it with a text aditor to see the direct link.

Hope this helps.

1 Like

Thanks @Bob_NL. Much appreciated. And I’ll look into opening m3u files in notepad in the future. Thanks for the tip

1 Like

Thanks @Bob_NL, this is awesome.
Works like a charm! Thanks for sharing!

1 Like

Thanks @Bob_NL that worked for a couple of radio stations. Like it was mentioned by @benjimatt for tunein: You need to have the auto load URL’s from TuneIn for the method to work, but it did. I’ll keep seeing if I can find something for the other ones.

Also, just a quick question but how did you do the group setting so you can stream everywhere? Was it a group you set up or are you calling a Universal Media Player?

You have to define your group in the Google Home app for this. After you set it up in the app, it will show as entity in HASS (media_player.home_group in my case).

1 Like

Thanks, i’m guessing that option isn’t available with my config (Nexus Player, Chromecast Gen 1 and Chromecast Audio). Tried looking through the Google Home app and there is no option there for any of the three devices I have listed.

The multiroom audio functionality unfortunately is only available for Chromecast Audio (at the moment).
In my case, media_player.home_group consists of 3 speakers (Bathroom, Hall, Livingroom) connected to Chromecast Audio. I also have 2 other Chromecasts (1st Gen. + 2nd Gen.) which can’t be paired to my group.

1 Like

Is it possible to use VLC player for radio. I have vlc on my raspberry with speaker attached. I tried but its not working