Chromecast Radio with station and player selection

Hi,

How would you tweak this one;
I went with the original code and everything seem to work perfectly, with my Google Home and my Chromecast. But one problem I came across, was when trying to stream audio to my chromecast that is connected to my AVR. When I select “media_player.denon_chromecast_audio” then it will try to stream to that device and probably also does. Unfortunately my AVR doesn’t turn on, nor the Zone where I want to “Living Room”.

If I add the media_player.turn_on in the script below, then it will just always turn it on, no matter what media player I select.

Does anyone have a good approach (sorry if I have missed a post where this already have been addressed).

script:

  afspil_radio:
    alias: Play Radio Audio Unit
    sequence:
      -  service: media_player.volume_set
         data:
           entity_id: media_player.home_assistant_stue
           volume_level: '0.20'
      -  service: media_player.play_media
         data_template:
           entity_id: >
            {% if is_state("input_select.chromecast_radio", "Living Room") %}  media_player.home_assistant_stue
            {% elif is_state("input_select.chromecast_radio", "Bathroomn") %} media_player.denon_chromecast_audio
            {% elif is_state("input_select.chromecast_radio", "All") %} media_player.all_rooms
            {% 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
            {% endif %}
           media_content_type: 'audio/mp4'

EDIT:

I solved it by putting in the below code just after the media_player.play_media

      - service: media_player.turn_on
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio", "Stue") %} media_player.stue_kokken
            {% elif is_state("input_select.chromecast_radio", "Bade") %} media_player.badevaerelser
            {% elif is_state("input_select.chromecast_radio", "Alle Rum") %} media_player.stue_kokken, media_player.badevaerelser
            {% endif %}
1 Like

Cool, thanks for sharing. I’ve modified this to work with Node-RED :slight_smile: writeup coming.

Hey @Bob_NL what speakers are involved in this setup?

Currently all Google Home speakers (5 x Mini, 1 Regular and 1 Hub) but this should work with any
media_player device that supports playing streams.

hi guys,

After the last update to 0.105 i got an error in the selection of the radio stations:

Unknown type encountered: entities.

entity: input_select.radio_station type: entities

any solution ?

thanks

I’ve not upgraded to 0.105 but will defo keep an eye on it and report back when I upgrade this weekend

Hi, I’v got the same problem as you. In my.

I ended up with using a custom card: Group card from Hacs

          - type: custom:group-card
            card:
              type: entities
              title: Radio
              show_header_toggle: false
            group: group.radio

Hope this can healp you

radio
First off…Thanks for taking the time and packaging this up! I sincerely appreciate the simplicity of a package for something like this…So I got this setup and working…sorta. I modified a couple things to get it to play with my Sonos setup.

I have one question for anyone?? I was under the impression that when I would change any inputs (ie Radio Station, Speakers, Volume) that it would dynamically adjust accordingly. Is it normal to have to press “Play” after making a change to volume, Speakers, or Station to get the script to update?

Perhaps I set it up wrong. Any input would be appreciated! thanks again!

I’m not sure which version you have (there have been several iterations), but most likely yes you would have to press play for the change to take effect.
If you want the change to take effect straight away, you need to add an automation that triggers on input_select and calls the script

- alias: Change Radio Station
  initial_state: true
  trigger:
    - platform: state
      entity: input_select.radio_station
  action:
    - service: script.turn_on
      data:
        entity_id: script.radio538
1 Like

Has anyone figured out a way to display “media_title:” and “media_artist:” as a part of the player?

Yes, but since you’re looking at radio streams you first need to retrieve that data (if it’s even available) using scrape sensors
Have a look here

Can someone help me with this. I am New to Hassio an would like to get this to work. I have everything in my config files but dont know how to get this to show up in lovelace. Can someone please guide me on that part

Thanks

Hi,
Assuming you got all the entities right.
Try adding a entities card.

Works for me :slight_smile:

I have the input selects and script and all working fine. I just want to know if there is an easy way to find the URL’s for the radio streams? I am struggling trying to find them to add to this.

Thanks in advance

Heyho,
i think there is no native way with the cast component. But i adopted the Node-Red version from @coen17st in one of the upper posts and it works fine with me…

1 Like

There’s no easy way to retrieve this as each website can use a different way to stream.
Doing a google search is probably what will give you the most results based on a specific station that you’re looking for.
I normally use Winamp to then play a stream to confirm the stream URL actually works

In Chrome hit F12 to open the dev panel and look (Ctrl + F) for ‘audio’ in the html section. Often you will find the stream url

Thanks for all the replies to this.
@sparkydave : that is the solution I thought would be needed but is a littel hit and miss. I’ll just keep searching until I find them all.
No one likes to advertise their direct media links.

How do I get the URL for Netflix and Pandora? Would be nice to press a HA button and have Pandora play on my patio chrome cast.

there is no such thing as “the” url for pandora/netflix. You’d need the URL of a stream, and it needs to be in mp3 format, not video.
and since you need to be logged in to access these services, I’m pretty sure you can’t access the stream URL directly from HA…