Chromecast Radio with station and player selection

ok cool. I just didnt want to break the function by not following suit

if it ain’t broke… :slight_smile:

I would to use this but get two errors :

  1. 2017-11-16 21:16:28 ERROR (MainThread) [homeassistant.loader] Unable to find component chromecast_radio
    2017-11-16 21:16:28 ERROR (MainThread) [homeassistant.setup] Setup failed for chromecast_radio: Component not found

and the message that I have an invalid config because “Input_select could not be set_up” although I copied the code from this thread.
At first in a seperate yaml, and when that did not work, I put it in the configuration_yaml

Do I have to add some components that are not mentioned at top of this thread ?

@curious did you put both of them in your config?:

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
      - Radio Rijnmond
      - Poez
      - SLAM! Hardstyle
      - Bob Sinclar Radio
      - Smooth Jazz Tampa
      - Classic Rock Florida
      - Netherlands Viral 50
      - Chill Out Zone
      - Sleep Radio
      - Ambient Sleeping Pill
      - Radio Art - Sleep
      - Ambi Nature Radio
      - Calm Radio - Sleep
      - Dinamo.FM Sleep
    initial: Radio 538
    icon: mdi:radio
  chromecast_radio:
    name: 'Select Speakers:'
    options:
      - Livingroom
      - Livingroom - Onkyo
      - Google Home
      - Bedroom
      - Bathroom
      - Hall
      - Everywhere
    initial: Everywhere
    icon: mdi:speaker-wireless

Check here if you’re interested:

I did indeed, furthermore under Mediaplayer I have platform: cast

Script is correct now, Still get the message : the following components and platforms could not could not bes etup :
. chromecast radio

Please check your config.

Platform error solved too :slight_smile: Script in wrong place :frowning: No sound however. Struggling on, but won’t give up now I get this far
and there is sound tooooo.
For a noob like me it would be a good addition to the instructions, that you have to modify a line in the script.
For example

{% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.bed_room

where it says “media_player.bed_room” you to modify it to your own media_player.xxxxx
the correct name can be found under developer tools->states

@Bob_NL . thanx

How to make this as an alarm ?

I get a lot of questions about my wakeup light setup. I’m allmost on my way to the airport now for a short holiday. I’ll post my complete setup (incl. integration with my Android alarm clock) in a seperate topic when I’m back.

2 Likes

Wow, great, that’s the ultimate alarm clock/radio for HASS

its time to go back to work for HASS :stuck_out_tongue:

1 Like

Hi, Just want to share my radio station list I use.

      media_content_id: ' {% if is_state("input_select.radio_station", "The Office") %} http://listen.181fm.com/181-office_128k.mp3
    {% elif is_state("input_select.radio_station", "The Mix") %} http://listen.181fm.com/181-themix_128k.mp3
    {% elif is_state("input_select.radio_station", "Party 181") %} http://listen.181fm.com/181-party_128k.mp3
    {% elif is_state("input_select.radio_station", "Energy 98") %} http://listen.181fm.com/181-energy98_128k.mp3
    {% elif is_state("input_select.radio_station", "90''s Dance") %} http://listen.181fm.com/181-90sdance_128k.mp3
    {% elif is_state("input_select.radio_station", "Chilled Out") %} http://listen.181fm.com/181-chilled_128k.mp3
    {% elif is_state("input_select.radio_station", "Kickin'' Country") %} http://listen.181fm.com/181-kickincountry_128k.mp3
    {% elif is_state("input_select.radio_station", "80''s Country") %} http://listen.181fm.com/181-80scountry_128k.mp3
    {% elif is_state("input_select.radio_station", "Awesome 80''s") %} http://listen.181fm.com/181-awesome80s_128k.mp3
    {% elif is_state("input_select.radio_station", "Classic Hits 181") %} http://listen.181fm.com/181-greatoldies_128k.mp3
    {% elif is_state("input_select.radio_station", "Good Time Oldies") %} http://listen.181fm.com/181-goodtime_128k.mp3
    {% elif is_state("input_select.radio_station", "Mellow Gold") %} http://listen.181fm.com/181-mellow_128k.mp3
    {% 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
service: media_player.play_media
2 Likes

Anyone that know how to get this station to work with this setup?

#https://tunein.com/radio/JULRADIOse-s236911/

This is the .pls file when i open it:

[playlist]

File1=http://relay1.julradio.se:80
Title1=Relay #1 (Port80 Jobb/Arbete) - JULRADIO.se
Length1=-1

File2=http://relay1.julradio.se:9000
Title2=Relay #2 - JULRADIO.se 
Length2=-1

File3=http://relay2.julradio.se:80
Title3=Relay #3 (Port80 Jobb/Arbete) - JULRADIO.se
Length3=-1

File4=http://relay2.julradio.se:9000
Title4=Relay #4 - JULRADIO.se
Length4=-1

File5=http://relay1.julradio.se:443
Title5=Relay #5 (Port443 Jobb/Arbete) - JULRADIO.se
Length5=-1

File6=http://relay2.julradio.se:443
Title6=Relay #6 (Port443 Jobb/Arbete) - JULRADIO.se
Length6=-1

Hi! Thanks for the awesome work with the radio setup! However, I’m having some issues. The playback fails waay too often for some reason. Here are some examples:

  • I can’t use the group with my two Chromecast audios (group everywhere), I can hear it connect (with the blip), but nothing starts
  • Once I have started music in one of the audios I can’t switch to another speaker.
  • It generally feels a bit unstable since I can’t restart with the “Activate” button - Only way to get it up and running is to restart home assistant.

image

Here is my code, hope someone can spot errors:

script:
  julradio:
    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.frellenvardagsrum
            {% elif is_state("input_select.chromecast_radio", "Library") %} media_player.frellenbibliotek
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.frellenhome
            {% 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", "Livingroom") %} media_player.frellenvardagsrum
            {% elif is_state("input_select.chromecast_radio", "Library") %} media_player.frellenbibliotek
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.frellenhome
            {% endif %}
           media_content_id: >
            {% if is_state("input_select.radio_station", "Christmas P4") %} http://sverigesradio.se/topsy/direkt/3034-hi-mp3.mp3
            {% elif is_state("input_select.radio_station", "Christmas P2") %} http://sverigesradio.se/topsy/direkt/3036-hi-mp3.mp3
            {% endif %}
           media_content_type: 'audio/mp4'
input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
      - Christmas P4
      - Christmas P2
      - Test
    initial: Christmas P4
  chromecast_radio:
    name: 'Select Speakers:'
    options:
      - Livingroom
      - Library
      - Everywhere
    initial: Everywhere
    icon: mdi:speaker-wireless
input_number:
volume_radio:
  name: Volume
  icon: mdi:volume-high
  initial: 0.3
  min: 0
  max: 1
  step: 0.05
group:
  julradio:
    name: Julradio
    entities:
      - input_select.radio_station
      - input_select.chromecast_radio
      - script.julradio
      - input_number.volume_radio

Any ideas on how to make it work better?

Than you probably are using faulty links, check them in your browser (should play instantly without having to press a play button).

You should be able to switch by selecting your speakers and pressing play again. If you add a media_player.media_stop command in the script than the music stops on the prvious players before starting it on the other speakers.

That’s weird, I don’t recognize this behaviour. Check your logfile for errors. Are u using a Raspberry? Are you using an adapter with sufficiant amperage?

I have been using this code for a while and it works great! Many thanks for the work. But now I wanted to add Volume+ and Volume- buttons instead of the slider.

I found the media_player.volume_up and this work very good. But the volume-steps are too big…

So I found this and want to use it as a script:

volume_up:
  alias: Volume +
  sequence:
- service: media_player.volume_set
  data_template:
    entity_id: >
     {% if is_state("input_select.chromecast_radio", "Huiskamer") %} media_player.speakers_huiskamer
     {% elif is_state("input_select.chromecast_radio", "Zolder") %} media_player.speakers_zolder
     {% elif is_state("input_select.chromecast_radio", "Overal") %} media_player.huis
     {% endif %}   
  data_template:
         volume_level: '{{ states.media_player.YourPlayer.attributes.volume_level + 5 }}'

But now I am stuck, since I don’t know how to use the correct current volume level (ie the current chromecast being used) at the last step? I am quite a beginner in programming, but I can’t figure it out… Any help/tips would be appreciated!

The volume increments in steps of .5 so you might want to change this. If you are ok with the volume being changed to the selected speakers in your input_select, you could try like this:

volume_up:
  alias: Volume +
  sequence:
- service: media_player.volume_set
  data_template:
    entity_id: >
     {% if is_state("input_select.chromecast_radio", "Huiskamer") %} media_player.speakers_huiskamer
     {% elif is_state("input_select.chromecast_radio", "Zolder") %} media_player.speakers_zolder
     {% elif is_state("input_select.chromecast_radio", "Overal") %} media_player.huis
     {% endif %}   
    volume_level: >
     {% if is_state("input_select.chromecast_radio", "Huiskamer") %} '{{ (states.media_player.speakers_huiskamer.attributes.volume_level | float) + 0.5 }}'
     {% elif is_state("input_select.chromecast_radio", "Zolder") %}  '{{ (states.media_player.speakers_zolder.attributes.volume_level | float) + 0.5 }}'
     {% elif is_state("input_select.chromecast_radio", "Overal") %}  '{{ (states.media_player.huis.attributes.volume_level | float) + 0.5 }}'
     {% endif %}   

Great sample @Bob_NL. I’ve put all config in a package and I am using an Automation that triggers the script when a station is selected.

group:
  radio:
    name: Radio
    entities:
    - input_select.radio_station
    - input_select.chromecast_radio

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
      - Everywhere
    initial: Livingroom
    icon: mdi:speaker-wireless

automation:
  alias: Listen Radio
  hide_entity: True
  trigger:
    - platform: state
      entity_id: input_select.radio_station
  action: 
    - service: script.radio

script:
  radio:
    alias: Play Radio on Chromecast Audio
    sequence:
      -  service: media_player.select_source
         entity_id: media_player.denon_avrx1300w
         data: 
           source: 'AUX'
      -  service: media_player.play_media
         data_template:
           entity_id: >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.huiskamer
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.huiskamer
            {% endif %}
           media_content_id: >
            {% if is_state("input_select.radio_station", "Radio 538") %} http://playerservices.streamtheworld.com/api/livestream-redirect/TLPSTR01.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'
2 Likes

You could trigger the whole radio from that same automation too if you want it to play directly after selecting a stream. Or would you still like to keep the play button?

I’m keeping the play button to turn on the radio if the station I want to listen to is already selected :wink:

1 Like

Thanks, getting a bit closer but getting the following error:

Invalid service data for media_player.volume_set: expected float for dictionary value @ data['volume_level']. Got "'5.100000001490116'"

Does this have to do rounding the number or something?