Chromecast Radio with station and player selection

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.

Thanks, this makes it simple for everyone! :slight_smile:

Really appriciate it!!

I’ll give it a try. Thanks for your replies and help, it’s really appreciated.

It works amazing on my Xiaomi MiBox (android Tv) with built in chromecast.
But how do i get this radio on the lovelace screen?:thinking:

Found the simple solution.
Run Lovelace Migration app!

Hi All, I have this all up and running (thank you so much @wills106 ). Just wondering if any one knows how I would call this as a service/ action in order to make it part of an automation. Any help greatly appreciated.

Just realised the script you already wrote works well as a call service. Cheers

1 Like

Hey all,
also from my side, thanks a lot for running my home radio for the last year :slight_smile:
I found myself doing a lot of errors while working with the configuration, so after iterations on the interface and a complete rewrite using Lovelace Custom UI, I would love to share my derivate of the famous chromecast player. I opened up a thread for it

I’d love to get some of your insights in how you’ve been using home-assistant to play your media.

1 Like