Chromecast Radio with station and player selection

from where did you get stream links? i want to get some arabic channel.

I have actually made a spotify version of this - it works fine - the only problem is that the spotify component have a bad memory when it comes to sources, especially if you use multiple chromecasts - rendering it useless to me at the moment. However if anybody have better luck with spotify i’ll love to share.

UPDATE:
The spotify version can be found here: Spotify Playlist Player :slight_smile:

I’m assuming that all these multi speakers solutions requires to keep the speakers powered all the time. I mean, you are not using home assistant to turn on the speaker. Am I right?
I would like to make something similar, but the fact that it will drain power while not in use really annoys me… :yum:

You can, but it will depend on what your speaker setup. With my yamaha AVR I have auto on and off working with squeezebox, chromecasts, mibox and you can use it with any media player that reports its state to hass.

Have a look at the last part of the first post in this thread.

1 Like

Hi,

This is my first ever try with HA, i installed it manually on my RBP3, the aim of this is that I wanted to say hey google good morning, it would dim the lights (already done through smartthings) AND play music on chromecast (I have the 2nd gen chromecast not audio) <- this i got told can only be done with HA

So now i installed it and i used the following in my configurations.yaml:

 radio538:
alias: Play Radio on Chromecast Audio
sequence:
  - 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  }}' 
  -  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", "Smooth Jazz Tampa") %} http://us3.internet-radio.com:8007/listen.mp3           
        {% elif is_state("input_select.radio_station", "Classic Rock Florida") %} http://listen.shoutcast.com/Classic-RockFlorida
        {% elif is_state("input_select.radio_station", "Bob Sinclar Radio") %} http://listen.shoutcast.com/prysmradio09-mp3            
        {% elif is_state("input_select.radio_station", "Chill Out Zone") %} http://air.chillout.zone:8000/radio           
        {% elif is_state("input_select.radio_station", "SLAM! Hardstyle") %} http://stream.radiocorp.nl/web11_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'

I now get the activate but nothing happens…

I can see my Chromecast widget and my Google home widget as well, the logs shows this:

2017-09-24 18:42:12 INFO (MainThread) [homeassistant.helpers.script] Script Play Radio on Chromecast: Executing step call service
2017-09-24 18:42:12 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1972524368-57, domain=media_player, service_data=entity_id=, media_content_id=, media_content_type=audio/mp4, service=play_media>
2017-09-24 18:42:12 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.play_media: Entity ID is an invalid entity id for dictionary value @ data[‘entity_id’]. Got ‘’
2017-09-24 18:42:12 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1972524368-57>
2017-09-24 18:42:12 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1972524368-55>
2017-09-24 18:42:12 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=script.radio538, old_state=<state script.radio538=off; last_triggered=2017-09-24T20:36:52.562368+02:00, friendly_name=Play Radio on Chromecast @ 2017-09-24T20:34:24.628233+02:00>, new_state=<state script.radio538=off; last_triggered=2017-09-24T20:42:12.046148+02:00, friendly_name=Play Radio on Chromecast @ 2017-09-24T20:34:24.628233+02:00>>

Any help is appreciated

Some things to try:

  • collapse whitespace. use a - after the > and remove the space after the curly brace that closes the if/elif statement. indentation is significant. the extra space could cause trouble
  • test everything in the template dev tool, just to make sure that your if/elif returns what you expect it to return.
    entity_id: >-
        {% if is_state("input_select.chromecast_radio", "Livingroom") %}media_player.ca_livingroom
        ...

Very thankful for reaching this topic. I use to play on a speaker connected do the raspberry pi aux port. My custom implementation was:

Changed the script
From: media_content_type: ‘audio/mp4’
To: media_content_type: ‘audio/mp3’

I also created a intent script to start the radio by voice commands (api.ai / actions on google):

ListenToRadio:
speech:
text: >
{%- if OnOff == “on” -%}
You are listening to {{ RadioStation }}
{%- else -%}
Turning off the radio
{%- endif -%}
action:
- service: input_select.select_option
data_template:
entity_id: input_select.chromecast_radio
option: OrangePi
- service: input_select.select_option
data_template:
entity_id: input_select.radio_station
option: >
{%- if OnOff == “on” -%}
{{ RadioStation }}
{%- else -%}
Stop
{%- endif -%}
- service: script.radio_start

1 Like

Change the entity_id’s to your media player id’s, I see you are using my exact same names which would be very coincidental :slight_smile:

That’s correct. I’m using a couple of simple ball speakers which hardly use any power but you’re right it is a drain.

Ok so now I have this in my config:

script:
radio538:
alias: Play Radio on Chromecast Audio
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.chromecast
volume_level: ‘0.35’
- service: media_player.volume_set
data:
entity_id: media_player.chromecast
volume_level: ‘0.20’
- service: media_player.volume_set
data:
entity_id: media_player.chromecast
volume_level: ‘0.30’
- service: media_player.chromecast
data_template:
entity_id: >
{% if is_state(“input_select.chromecast_radio”, “Livingroom”) %} media_player.chromecast
{% elif is_state(“input_select.chromecast_radio”, “Hall”) %} media_player.chromecast
{% elif is_state(“input_select.chromecast_radio”, “Bedroom”) %} media_player.chromecast
{% elif is_state(“input_select.chromecast_radio”, “Bathroom”) %} media_player.chromecast
{% elif is_state(“input_select.chromecast_radio”, “Everywhere”) %} media_player.chromecast
{% 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’

and now i get this, not sure exactly what to change:

2017-09-25 20:28:33 WARNING (MainThread) [homeassistant.core] Unable to find service media_player/chromecast

Please use blockquotes or preformatted text when posting code so we can debug. This is unreadable. Thanks.

done, apologies

I Also never get past the Activate widget…i never seen a drop down menu to choose speakers or stations…
however, if i click activate, the volume slider appears on TV and thats the best it went…

Hmmm

I’ve been trying for 15 min. to paste my configurations.yaml in blockquoted or preformatted and it just won’t work!!!

Here it is:
indent preformatted text by 4 spaces

pi@raspberrypi:~ $ cat .homeassistant/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: 31.2156
longitude: 29.9553

Impacts weather/sunrise data (altitude above sea level in meters)

elevation: 0

metric for Metric, imperial for Imperial

unit_system: metric

Pick yours from here: List of tz database time zones - Wikipedia

time_zone: Africa/Cairo

Customization file

customize: !include customize.yaml

Show links to resources in log and frontend

introduction:

Enables the frontend

frontend:

Enables configuration UI

config:

http:

Uncomment this to add a password (recommended!)

api_password: PASSWORD

Uncomment this if you are using SSL/TLS, running in Docker container, etc.

base_url: example.duckdns.org:8123

Checks for available updates

Note: This component will send some information about your system to

the developers to assist with development of Home Assistant.

For more information, please see:

Explaining the Updater - Home Assistant

updater:

Optional, allows Home Assistant developers to focus on popular components.

include_used_components: true

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

group: !include groups.yaml
automation: !include automations.yaml

script: !include scripts.yaml

mqtt:
broker: 192.168.2.228
port: 9001
client_id: mqttc
discovery: true
discovery_prefix: smartthings

light:

  • platform: mqtt
    name: “Far Right Stand”
    brightness_command_topic: “smartthings/Far Right Stand/level/set”
    brightness_state_topic: “smartthings/Far Right Stand/level”
    command_topic: “smartthings/Far Right Stand/switch”
    optimistic: false
    payload_off: “off”
    payload_on: “on”
    qos: 0
    state_topic: “smartthings/Far Right Stand/switch”

  • platform: mqtt
    name: “Right Stand”
    brightness_command_topic: “smartthings/Right Stand/level/set”
    brightness_state_topic: “smartthings/Right Stand/level”
    command_topic: “smartthings/Right Stand/switch”
    optimistic: false
    payload_off: “off”
    payload_on: “on”
    qos: 0
    state_topic: “smartthings/Right Stand/switch”

script:
radio538:
alias: Play Radio on Chromecast Audio
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.chromecast
volume_level: ‘0.30’
- service: media_player.play_media
data:
entity_id: media_player.chromecast
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’

ios:

Thank you so much for posting your code. i was looking for something exactly like this!

For my setup, I have a Monoprice Six Zone controller/amp connected to HomeAssistant. The Monoprice unit has six inputs and six speaker zones. I have one Chromecast connected as an input, and I can output it to all any or all zones. The Monoprice unit doesn’t natively support groups, but I added group support via groups.yaml. It works a treat.

Thanks again!

1 Like

@Bob_NL been using your script for a while now, and I love it.
Quick question, are you aware of a way to display custom picture / album art on the ChromeCast entities?
If I play content from Google Music, I normally get the album art so would like to add some art to my radio stations. Thanks

@lolouk44 glad you like it!

I’m not sure if that’s possible. I was struggling myself with custom icons for every station and I made a feature request topic for this: Templating icons in customize section

Seems like there is not that much interest lol

Just voted for it. If we could have all other users of your script do the same it would help.
Guys?

1 Like

hi @Bob_NL,

trying to customize for my setup, which is only up for a few days…
in which yaml file to put the selectors snippets? Im trying to setup the configuration without editing the configuration file and expand it endlessly, so have the automation.yaml, scripts.yaml etc etc. No where to put the selectors yet though :slight_smile:

Thanks,
Marius