Chromecast Radio with station and player selection

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