Chromecast Radio with station and player selection

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

Not sure about VLC, but I know MPD (Mopidy) works fine with the same commands.

Is there a way to replace the Activate text button with an icon instead?

I don’t think so. Would be a nice feature though to be able to change the text or replace with an icon.

Hi folks!

Big props to Bob to kicking this off… brilliant!

I’ve incorporated it into my system - I have a few local Australian stations and some 80’s throwbacks. It’s great! I have it streaming to 4 chromecasts and a Google Home - and also as a group for whole house vacuuming background music.

I was wondering if I could set the entity_picture to an image that represents the station being piped?

I was thinking that I could just these last three lines:

alias: Play Radio on Chromecast Audio
sequence:
  -  service: media_player.play_media
     data_template:
       entity_id: >
        {% if is_state("input_select.chromecast_radio", "Kitchen") %} media_player.kitchen_chromecast
        {% elif is_state("input_select.chromecast_radio", "Google Home") %} media_player.kitchen_home
        {% elif is_state("input_select.chromecast_radio", "Theater") %} media_player.home_theater_chromecasta
        {% elif is_state("input_select.chromecast_radio", "Man cave") %} media_player.man_cave_chromecast_a
        {% elif is_state("input_select.chromecast_radio", "Whole house") %} media_player.whole_house
        {% endif %}
       media_content_id: >
        {% if is_state("input_select.radio_station", "TripleJ") %} http://radio1.internode.on.net:8000/117
        {% elif is_state("input_select.radio_station", "DoubleJ") %} http://radio1.internode.on.net:8000/132
        {% elif is_state("input_select.radio_station", "TripleJ Unearthed") %} http://radio1.internode.on.net:8000/183
        {% elif is_state("input_select.radio_station", "Best of the 80's") %} http://radio1.internode.on.net:8000/42
        {% elif is_state("input_select.radio_station", "Industrial") %} http://radio1.internode.on.net:8000/47
        {% elif is_state("input_select.radio_station", "TripleR") %} http://public-radio1.internode.on.net:8002/114
        {% elif is_state("input_select.radio_station", "Soma Underground 80's") %} http://radio1.internode.on.net:8000/20
        {% endif %}
       media_content_type: 'audio/mp3'
       entity_picture: >
        {% if is_state("input_select.radio_station", "TripleJ") %} http://assets.cdn.iinet.net.au//assets/freezone/radio/radio-triplej-icon.jpg
        {% endif %}

I’ll find a better image than that - but I got stuck. I got this error:

17-03-18 20:22:55 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.play_media: extra keys not allowed @ data['entity_picture']. Got 'http://assets.cdn.iinet.net.au//assets/freezone/radio/radio-triplej-icon.jpg'

Any pointers anyone?

1 Like

@brendanheyu glad you like it.

Great idea!

I think it’s not possible in the play_media part but I guess it can work as script entity picture. Will try right away :slight_smile:

^^^^^^
And that is why this community rocks!

1 Like

After rethinking this it’s a little more complicated than I thought. The script icon is configured in the customize section. I’m not sure if templating is possible there (which is neccessary, right?)