Chromecast Radio with station and player selection

in what respect? from my config, ‘Lounge’ is a Chromecast Audio, ‘Bedroom’ is a Google Home and ‘House’ is a group in Google Assistant which includes both of those.

Hi

I just wanted to say thank you for this script, really helpful after playing around I got it to work for me.

The volume_slider change to volume_number stumped me for a bit though.

Thanks again

PS any Australian users some good channels here, http://freezone.internode.on.net/#/radio/

Ok that should be no issue then. Have you tried all your speaker options with a working streaming link?
You could try using it without a speaker selector for instance (and hardcode a speaker in the config) to rule out a fault there. If this works you could try hardcoding a radio station. That way you can debug peace by peace.
Also, activate the “start sound” in the Google Home app and see if you can hear it when activating the script. That way you know for sure if a command is send to your Cast devices at all.

@lerroy_b glad you like it!

1 Like

I have actually got one of the streams hard coded into a script and that works perfectly…

Great! Now you know you have a working setup. Work from there and extend your script bit by bit.

Are you entering URL into ‘Radio URL’ text box and on the fly you were streaming to Chromecast?

I have an idea where I would like to enter any Youtube URL then use media_extractor component (uses Youtube-DL) and stream audio from that URL to Chromecast.

Pretty much, I enter a URL, then select Custom Station from my drop down mebnu, then activate and it plays the MP3 file from that URL…

Why do you need to select custom station when you already entered URL to stream?

Could you share your code snippet?

I like that idea :slight_smile:

I missed that on your post, very nice addition.

1 Like

It worked great. Here is the code snippet.

media_extractor:

input_text:
  stream_url:
    name: Streaming URL
    initial: Enter URL

Automation :

  - alias: Stream URL Text Changed Event
    initial_state: true
    hide_entity: true
    trigger:
      - platform: state
        entity_id: input_text.stream_url
    action:
      - service: media_extractor.play_media
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.living_room_home
            {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom_home_mini
            {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.officeroomspeaker
            {% endif %}
          media_content_id: "{{states.input_text.stream_url.state}}"
          media_content_type: 'video/mp4'

image

I entered this URL

2 Likes

That’s because the URL will stay in the box. Means once I’m done listening to the custom url I can then change to another pre defined station. Also means that I’m not forced to select a speaker before entering the URL (in case you set an automation based on custom url field)
I’ll share the code once I’m home but pretty much based on @Bob_NL code

1 Like

That is really cool!!! Thanks for sharing! I’ve been planning on doing it for a while.

chromecast_radio

Used this script and adjusted to my needs:

  • Simple start and stop of radio
  • Support for channel changes
  • Support for volume changes
  • Support for speaker changes
  • Persistence for settings over restarts

Enjoy!

scripts:

radio_start:
  alias: Play Radio on Chromecast
  sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: >
         {% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
         {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
         {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
         {% endif %}
        volume_level: '{{ states.input_number.radio_volume.state | float }}'
    - service: media_player.play_media
      data_template:
        entity_id: >
         {% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
         {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
         {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
         {% endif %}
        media_content_id: >
         {% if is_state("input_select.radio_station", "Radio 538") %} http://18973.live.streamtheworld.com/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", "Radio 2") %} http://icecast.omroep.nl/radio2-bb-mp3
         {% elif is_state("input_select.radio_station", "3FM") %} http://icecast.omroep.nl/3fm-bb-mp3
         {% elif is_state("input_select.radio_station", "Radio 10") %} http://stream.radio10.nl/radio10
         {% elif is_state("input_select.radio_station", "100% NL") %} http://stream.100p.nl/100pctnl.mp3
         {% elif is_state("input_select.radio_station", "Veronica") %} http://19993.live.streamtheworld.com:80/VERONICA_SC
         {% elif is_state("input_select.radio_station", "Sky Radio") %} http://19993.live.streamtheworld.com/SKYRADIO_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", "BNR Nieuwsradio") %} http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03
         {% elif is_state("input_select.radio_station", "SLAM! Hardstyle") %} http://streaming.slam.nl/web11_mp3
         {% endif %}
        media_content_type: 'audio/mp4'

radio_stop:
  alias: Stop Radio on Chromecast
  sequence:
    - service: media_player.media_stop
      data_template:
        entity_id: >
         {% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
         {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
         {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
         {% endif %}

radio_change_speakers:
  alias: Change Radio Speakers
  sequence:
    - service: media_player.media_stop
      data_template:
        entity_id: >
         {% if previous_speakers == "Livingroom" %} media_player.livingroom_speaker
         {% elif previous_speakers == "Kitchen" %} media_player.kitchen_speaker
         {% elif previous_speakers == "Everywhere" %} media_player.home_speakers
         {% endif %}
    - service: input_boolean.turn_off
      entity_id: input_boolean.radio_play

Automations:

- action:
  - service: media_player.volume_set
    data_template:
      entity_id: '{% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
        {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
        {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
        {% endif %}'
      volume_level: '{{ states.input_number.radio_volume.state | float }}'
  alias: Radio Volume
  condition: []
  id: radio_volume
  trigger:
  - entity_id: input_number.radio_volume
    platform: state
- action:
  - service: script.radio_start
  alias: Radio On
  condition: []
  id: radio_on
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'on'
- action:
  - service: script.radio_stop
  alias: Radio Off
  condition: []
  id: radio_off
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'off'
- action:
  - service: script.radio_start
  alias: Radio Channel Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_channel_change
  trigger:
  - entity_id: input_select.radio_station
    platform: state
- action:
  - service: script.radio_change_speakers
    data_template:
      previous_speakers: '{{ trigger.from_state.state }}'
  alias: Radio Speaker Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_speaker_change
  trigger:
  - entity_id: input_select.radio_speakers
    platform: state

Input selects:

  radio_speakers:
    name: 'Select Speakers:'
    options:
      - Livingroom
      - Kitchen
      - Everywhere
    icon: mdi:speaker-wireless

  radio_station:
    name: 'Select Radio Station:'
    options:
      - Radio 538
      - Q-Music
      - 3FM
      - 100% NL
      - Veronica
      - Sky Radio
      - Radio 2
      - Radio 10
      - Arrow Classic Rock
      - BNR Nieuwsradio
      - SLAM! Hardstyle

Input numbers:

  radio_volume:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05
    mode: slider

Input booleans:

  radio_play:
    name: Play Radio
    icon: mdi:radio

Groups:

  radio:
    name: Radio 
    view: no
    icon: mdi:radio
    entities:
    - input_select.radio_station
    - input_select.radio_speakers
    - input_number.radio_volume
    - input_boolean.radio_play

Recorder:

recorder:
  purge_keep_days: 10
  exclude:
    domains:
      - weblink
      - updater
      - media_player
  include:
    domains:
      - automation
      - sensor
      - binary_sensor
      - switch
      - climate
    entities:
      - input_boolean.radio_play
      - input_number.radio_volume
      - input_select.radio_speakers
      - input_select.radio_station
      - input_number.spotify_volume
      - input_select.spotify_speakers
      - input_select.spotify_playlist
3 Likes

Sorry… i am going mad, but on my side it doesn’t work… No sound goes to every speakers…
What to do?? The config is valid…

Check your logging.

Is it only that grouped speakers do not work or also specific chromecast speakers?

@Gernimo2018 @Bob_NL

Thanks for your great ‘scripts’!!

Just started experimenting with HA and this ‘stuff’ helps to migrate to HA soon.

@Gernimo2018
I think the begin of the ‘Automations:’ part is missing some lines? I got a bunch of errors and noticed that other automations start with the ‘alias:’. Sorry for my noob-ness, if I miss the clue :wink:

Thanks in advance for a reply.

Best Regards

@NicoS The order over automations is slightly different but shouldn’t hurt.
I think it is complete though.
Could you elaborate about the errors you get?

Where may i find more Internet Radio Stations to work here? Do you share any links?

@Gernimo2018
Thanks for your quick reply.

I checked all configuration items once again and now, with some trial and error, it’s working! Thanks again for your effort!