Chromecast Radio with station and player selection

Hello,

This is something where i was looking for!
Is this also do able with an Android tv box with chromecast?
I don 't use the box for anything else.

Tnx

Yes, in fact it should be suitable for every media_player platform.

Oke, i tried to get it working.
I’m quite new to HA…
Probably i’m just doing thing wrong haha.
Trying to play it with the kodi mediaplayer?
What i did:

Added to groups.yaml:

Residence Radio:
name: Residentie Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.radio538

Added to my configuration.yaml:

input_select:
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

Also added to configuration.yaml:

chromecast_radio:
name: ‘Select Speakers:’
options:
- Livingroom
- Bedroom
- Bathroom
- Hall
- Everywhere
initial: Everywhere
icon: mdi:speaker-wireless

Added to scripts.yaml
Copied all you tekst under Script: in your first post to scripts.yaml
Changed all mediaplayers to my own mediaplayers.

Added to customize.yaml:
script.radio538:
friendly_name: Start Playing
icon: mdi:play

When i check my configuration i get:
Ongeldige configuratieCONTROLEER CONFIGURATIE

extra keys not allowed @ data[‘customize’][‘customize’] Component not found: chromecast_radio

This is what’s on my page now:
radio

Thanks!!

can you please edit your post and put the code in using the </> icon as per the blue banner at the top of the page?

Sorry, changed it!

its still not right :wink: but it looks like you have indentation errors

I selected the code and then pressed “blockquote”, when i press “preformatted text” nothing happens,
Lol, forgive me my noobness haha.

The code and stuff is oke in my configuration.yaml.
This is the stuff i used to put in my scripts.yaml:

radio538:
    alias: Play Radio on Chromecast Audio
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.kodi_libreeleclocal
          volume_level: '0.35'
      -  service: media_player.volume_set
         data:
           entity_id: media_player.kodi_libreeleclocal
           volume_level: '0.20'
      -  service: media_player.volume_set
         data:
           entity_id: media_player.kodi_libreeleclocal
           volume_level: '0.30'
      -  service: media_player.play_media
         data_template:
           entity_id: >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.ca_livingroom
            {% elif is_state("input_select.chromecast_radio", "Hall") %} media_player.ca_hall
            {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bed_room
            {% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.ca_bathroom
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
            {% 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'

This is the right way to paste code on this forum isn’t it?

Yep, correctly posted. You have indentation issues with everything under the radio538 heading being too many spaces across. I’m only on my phone so a bit ok thanks hard to help out. In the morning (it’s currently 10pm here) I’ll post my code. I also suggest putting it all in a ‘package’. Much easier to keep under control

Going to try to put in in a package and going to try your code.
So mutch to learn and so less time :slight_smile: .

This looks amazing.
I’ve been looking all over for something like this. Is there a step by step install guide that I can follow? I’m a total noob, but not completely dull. I just need help to start the installation and what code goes in to what folders for example.

Did You manage to get everything working?
Could you help me?

No, to less experience with home assistant. Going to try again when i can spend a few evenings…

I copy pasted everything in my config but no sigar.

First I want to thank @Bob_NL for the initial code and concept and I also want to thank @lolouk44 as I used his github repository to piece it all together into a package. I prefer to use packages now as all of the code is in one place and you don’t need to remember where all of the bits are.

If you have not used packages before make sure you add the following to your configuration.yaml file:

configuration.yaml

  customize: !include customize.yaml

  packages: !include_dir_named packages

Then create a folder called “packages” in your main config folder.
Then create a file called “radio.yaml” or what ever you want to call it.
Then copy in the following and edit your radio stations and media players.

radio.yaml

#Initial code and concept Bob_NL https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732/1
#Converted into a package by wills106 https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732/419
group:
  Radio:
    name: ChromeCast Radio
    icon: mdi:radio
    entities:
    - input_select.chromecast_radio_station
    - input_text.custom_station
    - input_select.chromecast_radio_speakers
    - input_number.volume_radio
    - script.play_chromecast_radio
    - script.stop_chromecast_radio

input_select:

  chromecast_radio_station:
    name: 'Select Radio Station'
    options:
      - Absolute Radio Classic Rock
      - RealXS Manchester
      - Custom Station
    icon: mdi:radio

  chromecast_radio_speakers:
    name: 'Select Speakers'
    options:
      - LivingRoom
      - Bedroom
      - TV
      - All
    initial: LivingRoom
    icon: mdi:speaker-wireless

input_text:
  custom_station:
    name: Radio URL
    icon: mdi:link-variant

input_number:
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    initial: 0.3
    min: 0
    max: 1
    step: 0.05

script:
  play_chromecast_radio:
    alias: Cast Selected Radio on Chromecast Speakers
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "LivingRoom") %} media_player.living_room_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "Bedroom") %} media_player.bedroom_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "TV") %} media_player.chromecast0899
            {% elif is_state("input_select.chromecast_radio_speakers", "All") %} media_player.home_group
            {% endif %}
          volume_level: '{{  states.input_number.volume_radio.state  }}' 
      - service: media_player.play_media
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "LivingRoom") %} media_player.living_room_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "Bedroom") %} media_player.bedroom_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "TV") %} media_player.chromecast0899
            {% elif is_state("input_select.chromecast_radio_speakers", "All") %} media_player.home_group
            {% endif %}
          media_content_id: >
            {% if is_state("input_select.chromecast_radio_station", "Absolute Radio Classic Rock") %} http://icy-e-bab-04-cr.sharp-stream.com/absoluteclassicrock.mp3
            {% elif is_state("input_select.chromecast_radio_station", "RealXS Manchester") %} http://media-ice.musicradio.com:80/RealXSManchesterMP3
            {% elif is_state("input_select.chromecast_radio_station", "Custom Station") %} {{states.input_text.custom_station.state}}
            {% endif %}
          media_content_type: 'audio/mp4'
  
  stop_chromecast_radio:
    alias: Stop Playing Radio on ChromeCast 
    sequence:
      - service: media_player.turn_off
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "LivingRoom") %} media_player.living_room_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "Bedroom") %} media_player.bedroom_speaker
            {% elif is_state("input_select.chromecast_radio_speakers", "TV") %} media_player.chromecast0899
            {% elif is_state("input_select.chromecast_radio_speakers", "All") %} media_player.home_group
            {% endif %}

Then to clean it up a bit I add the following to the customize.yaml file in the main config folder:

customize.yaml

script.play_chromecast_radio:
  friendly_name: Play
  icon: mdi:play
script.stop_chromecast_radio:
  friendly_name: Stop
  icon: mdi:stop

radio
You then should end up with something looking like this.

12 Likes

This is amazing, thank you for providing this. I have followed your guide and my HA frontend now has this radio player.
I hope you don’t mind if I ask you some questions?
I use Volumio on a separate raspberry pi with an amp hat. What part of your script do I need to edit to use my media player, if my media player entity_id is: [media_player.volumio]?

Any help you can provide would be greatly appreciated.

Glad it helped some one out.

I don’t know if you can stream to Volumio as I have not tested yet and I need to rebuild the SD Card on mine. I have uploaded a test version onto my GitHub page for you to try, I also don’t know if the volume settings work the same as Google Cast devices but give it a go…

My GitHub https://github.com/wills106/homeassistant-config if you rename your radio.yaml to radio.yaml.disabled and then copy the radio-test.yaml that’s in the “experimental” folder to your packages folder and give it ago.

If you open the file you will be able to see how I added an extra device.

1 Like

Thank you @wills106 for modifying that code for me.
The switch at the top of the player, is it supposed to “latch on” and stay latched?
Unfortunately it did not work for me.
I’ve attached a pic showing how it looks, which I assume is all correct? Next to the chromecast radio player, you can see both instances of volumio I have on my network.

It would be great to get this working!
I really want some buttons on my HADashboard with radio stations, so that I can just walk over to my touchscreen and tap my favourite radio station and it plays whilst I cook.

You mean the “ChromeCast Radio”?
That look’s like it’s always off on mine as well.

You do know with Volumio if you have Play Lists setup you can select them through Home Assistant?

Yes, but you cant add radio stations to playlists, and for some reason, my playlists dont work? They show up in HA but they wont play? volume, play and pause work, but not the loading of a playlist.

Hmm, it seems my playlists don’t actually work inside Volumio to !!??
That would be why they’re not working in HA.

I have just got my Volumio setup working again and it does not look like you can stream to it.
Might be worth having a look at one of the plugins to see if you can stream to it such as the Squeezelite one?

Playlist’s created on my Volumio can be selected in the Home Assistant interface ok though.