Chromecast Radio with station and player selection

Chromecast (web)radio player with selectors for Radio Station and Speakers.

Hardware used: Chromecast Audio and Chromecast “regular” (1st gen.)

Frontend:

View:

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

Selectors:

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
  chromecast_radio:
    name: 'Select Speakers:'
    options:
      - Livingroom
      - Bedroom
      - Bathroom
      - Hall
      - Everywhere
    initial: Everywhere
    icon: mdi:speaker-wireless

Script:

  radio538:
    alias: Play Radio on Chromecast Audio
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.ca_hall
          volume_level: '0.35'
      -  service: media_player.volume_set
         data:
           entity_id: media_player.ca_bathroom
           volume_level: '0.20'
      -  service: media_player.volume_set
         data:
           entity_id: media_player.ca_livingroom
           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' 

Customize script name:

  customize:
   script.radio538:
    friendly_name: Start Playing
    icon: mdi:play

Enjoy!

128 Likes

This is awesome; in fact we have similar tastes so I don’t even have to change the station lists!

Thanks for sharing this from your other thread @Bob_NL - really nice of you to make it so easy for us.

1 Like

The volume set actions are optional off course, these are the settings that work best in my current setup but that’s obviously different in every situation (placing of speakers, room dimensions, distance between speakers etc.)
I like a not to intrusive background noise so the volumes are lowered down quite a bit.

This is very cool! I wish I could have things like pandora/spotify playlists to select though. Unless that becomes possible (maybe it is?) I don’t see myself setting this up.

3 Likes

Hi Bob,

I’m working on a similar project. Do you know of any possible way of creating a separate database file for my radio stations? Here’s what i have so far:

When you post code, instead of a screen shot please copy and paste the code into the forum post editor and then select it. The press the pre-formatted text button as indicated in the image below:

This makes it easy to read the code and also preserves the formatting in a way that others can see to check it. This is especially important with stuff like YAML! Also, it keeps the storing of images on the AWS servers low, which is also a good thing.

Thanks!

Here it is. Sorry for that

# My Existing Automation 

automation:  
  - alias: Select Patio Music
    trigger:
      - platform: state
        entity_id: input_select.patio_music
    action:
      - service: media_player.play_media
        entity_id: media_player.patio_chromecast
        data:
          media_content_type: audio/mp3
        data_template:
          media_content_id: >
            {% if trigger.to_state.state == 'Party Station' %}
              http://xx.xx.xx.xxx/PARTY
            {% elif trigger.to_state.state == 'Classical Station' %}
              http://xx.xx.xx.xxx/CLASSICAL
            {% elif trigger.to_state.state == 'Relax Station' %}
              http://xx.xx.xx.xxx/RELAX
            {% endif %}

__________________________________________________________________________

# My Custom Internet Radio Station Database File

Party Station: http://xx.xx.xx.xxx/PARTY               #line 1
Classical Station: http://xx.xx.xx.xxx/CLASSICAL       #line 2
Relax Station: http://xx.xx.xx.xxx/RELAX               #line 3

__________________________________________________________________________

# New Automation 

automation:  
  - alias: Select Patio Music
    trigger:
      - platform: state
        entity_id: input_select.patio_music
    action:
      - service: media_player.play_media
        entity_id: media_player.patio_chromecast
        data:
          media_content_type: audio/mp3
        data_template:
          media_content_id: >
            {% if trigger.to_state.state == '{FIRST PART of 3rd line on "My Internet Radio Station Database File" (example > "Relax Station") %}'
              {SECOND PART of 3rd line on "My Internet Radio Station Database File" (example - http://xx.xx.xx.xxx/RELAX) %}
            {% endif %}
1 Like

I got some problem with this, I can’t see the play icon, the “Start Playing” and ACTIVATE.

Where is the code for that? :slight_smile:

Thanx in advanced

@krsandvik That would be the script:

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

I forget to mention that I customized the script name to “start playing” (I added it to the startpost now):

  customize:
   script.radio538:
    friendly_name: Start Playing
    icon: mdi:play

Did you add all the code’s in the startpost in your yaml?

I understand what your saying but i’m afraid I can’t help you with that, sorry.

I extended it with a volume slider:

:warning: Mod Edit (2020): Since this topic was originally created several years ago, you might see outdated references to input_slider throughout this thread. It was renamed to input_number in Home Assistant 0.55. So whenever you see posts mentioning input_slider, make sure to replace that with input_number in your code - otherwise you will have invalid config.

Input number:

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

View:

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

Automation:

- alias: 'Set Radio Volume'
  trigger:
    platform: state
    entity_id: input_number.volume_radio
  action:
    service: media_player.volume_set
    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 %}
      volume_level: '{{  states.input_number.volume_radio.state  }}' 

I used a separate automation for this instead adding it to the script because that way you won’t have to restart the stream everytime you adjust the volume. State change of the volume slider will change the volume of the selected speakers instantly this way.

8 Likes

thanx for your reply, sorry but I still can’t get the activate button in the group. I have customize the radio to a Norwegian radio station.

Here is my configuration.yaml

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 59.7967
  longitude: 10.8136
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 168
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: 
  time_zone: Europe/Oslo

  customize:
    # Add an entry for each entity that you want to overwrite.
    media_player.bathroom:
    friendly_name: CC Bathroom
    media_player.google_home:
      friendly_name: Google Home
    media_player.hele_leiligheten:
      friendly_name: CC Apartment
    media_player.kitchen:
      friendly_name: CC Kitchen
    switch.rullegardin_soverom_oppenede:
      friendly_name: Rullegardin 
    script.nrk_radio:
      friendly_name: Start Playing
      icon: mdi:play
 # Example configuration.yaml entry

group:
####VIEWS
  livingroom_view:
    view: yes
    name: Living Room
    entities:
     - group.livingroom
####Groups
  livingroom:
    name: Living Room
    entities:
      - media_player.google_home
      - media_player.nexus_player
      - media_player.stereo
      - sensor.broadlink_sensor_temperature
  bedroom:
    name: Bedroom
    entities:
      - switch.rullegardin_soverom_oppenede
  hytta:
    name: Hytta
    entities:
      - sensor.netatmo_hytta_inne_temperature
      - sensor.netatmo_hytta_ute_temperature
  environment:
    - sensor.yr_symbol
    - sun.sun
  nrkradio:
    name: NRK Radio
    entities:
      - input_select.radio_station
      - input_select.chromecast_radio
      - script.nrkradio
      - input_slider.volume_radio

     ####Selectors
input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
     - "NRK P1"
     - "NRK p3"
     - "NRK Klassisk"

  chromecast_radio:
    name: Select Speakers
    options:
     - Livingroom
     - Bathroom
     - Kitchen
     - Everywhere
    initial: Everywhere
    icon: mdi:speaker-wireless
input_slider: 
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05

# Enables the frontend
frontend:

http:
  # Uncomment this to add a password (recommended!)
  #api_password: 
  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: example.duckdns.org:8123

# Checks for available updates
updater:

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:

# Weather Prediction
sensor:
  platform: yr

# Text to speech
tts:
  platform: google

# IFTTT
ifttt:
  key: 
  #### Scripts
nrkradio:
    alias: Play Radio on Chromecast Audio
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.hele_leiligheten
          volume_level: '0.35'
      - service: media_player.volume_set
        data:
          entity_id: media_player.bathroom
          volume_level: '0.20'
      - service: media_player.volume_set
        data:
          entity_id: media_player.stereo
          volume_level: '0.30'
      - service: media_player.volume_set
        data:
          entity_id: media_player.kitchen
          volume_level: '0.30'
      - service: media_player.play_media
        data_template:
           entity_id:  >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.stereo
            {% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.bathroom
            {% elif is_state("input_select.chromecast_radio", "Kitchen") %} media_player.kitchen
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.hele_leiligheten
            {% endif %}
           media_content_id:  >
            {% if is_state("input_select.radio_station", "NRK P1") %} h__p://lyd.nrk._no/nrk_radio_p1_ostfold_mp3_h
            {% elif is_state("input_select.radio_station", "NRK P3") %} h__p://lyd.nrk._no/nrk_radio_p3_mp3_h
            {% elif is_state("input_select.radio_station", "NRK Klassisk") %} h__p://lyd._nrk.no/nrk_radio_klassisk_mp3_h 
            {% endif %}
           media_content_type: 'audio/mp4'
1 Like

Do you see the script under the Script tab in your frontend?

Your streaming links seem to miss the “http”:

h__p://lyd.nrk._no/nrk_radio_p3_mp3_h

If the links are wrong, it could be your script is failing to initialize and therefor not showing at all.

What does your home-assistant.log file look like?

Update: I see what’s the problem now:

    script.nrk_radio:  <--------
      friendly_name: Start Playing
      icon: mdi:play

No underscore in your group:

  nrkradio:
    name: NRK Radio
    entities:
      - input_select.radio_station
      - input_select.chromecast_radio
      - script.nrkradio
      - input_slider.volume_radio

No underscore in your script:

nrkradio:
    alias: Play Radio on Chromecast Audio
    sequence:
    .....

loose the underscore in your customize section and it will probably work :slight_smile:

Still no go after the removing the underscore.

The URL I changed because of forum restictions

This is what I found in the home-assistant.log

17-03-03 23:39:19 ERROR (MainThread) [homeassistant.loader] Unable to find component nrkradio

1 Like

It looks like you your script nrkradio isnt under a script header in your configuration file … HA thinks that your script name is a component hence the radio.
I use a separate file to load my scripts but you may be able to add th nrkradio script under a script: header config in the file.

1 Like

Thanks @Bob_NL - works a treat.

2 Likes

Wow, can’t believe I missed that. Nice find!

Oh, that was it. It is my first week with home assistant.

Thank you both very much!

2 Likes

this is fantastic.

1 Like