Chromecast Radio with station and player selection


#1

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!


Spotify Playlist Player
How to send play tunein radio to google home
Combined music player
Streams controlled by Alexa
Motion sensor thermostat
Dynamically building input_select - Logitech Media Servier
Create Alarm clock
Should I go there? Whole house audio and then some
Radio streaming with Album Art, Artist and Track Name
Assigning a picture to music send to a ChromeCast
Multi Zone Chromecast Web Radio
Creating a alarm clock
Using Google Home for setting up a radio alarm
Synology Audio Station Media Player
How to prevent automation looping/repeating?
Smart Audio system for home
Lovelace: Mini Media Player
Add a standard interface for media player multi-room zone support
Input_select options with 'friendly name' and 'payload'
HA intercom advice
Streaming radio on Hassio
Volumio - How to play specified files or playlist or shuffle songs?
Yamaha AVR netradio
Chromecast audio group? Showing state off
Playing web radio stations on chromecasts
Get motion to trigger just once within a time period
Monoprice Whole Home Audio controller 10761 success
Templated Automation not working... but no error
Problems to cast radio
Adding a group for a popup?
Rotate to the left or right in Xiaomi Magic Cube?
Hass.io Play Radiostream
Play music to Google Homes
#2

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.


#3

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.


#4

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.


#5

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:


#6

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!


#7

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 %}

#8

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


#9

@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?


#10

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


#11

I extended it with a volume slider:

Input slider:

input_slider: 
  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_slider.volume_radio

Automation:

- alias: 'Set Radio Volume'
  trigger:
    platform: state
    entity_id: input_slider.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_slider.volume_radio.state  }}' 

I used a seperate 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.


#12

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'

#13

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?


#14

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:


#15

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


#16

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.


#17

Thanks @Bob_NL - works a treat.


#18

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


#19

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

Thank you both very much!


#20

this is fantastic.