Chromecast Radio with station and player selection

It should work fine

Thanks, since my chromecast is connected to my soundbar which is connected to my tv I think my tv will turn on also and I would like to avoid it. Do you use it with a tv chromecast to confirm or not?

If enabled, HDMI CEC default behavior is to turn on/off the tv when the Chromecast starts playing. You can disable HDMI CEC from tv or soundbar and play to the soundbar when the tv is off; but then you loose functionality as you need to manually turn on/off the soundbar whenever you are using the tv (neither the volume keys from the tv would pass to the soundbar).

In order to use a regular Chromecast like the discontinued Chromecast Audio you would need a HDMI audio converter. This one does RCA https://www.aliexpress.com/item/32966462546.html and you need to ensure your soundbar has such a connector for input. This one has also SPDIF and 3.5 mm jack connectors which are more common for soundbars https://www.aliexpress.com/item/1857358266.html

1 Like

I will have to choose the second one. So if I connect it to my soundbar I don’t have to disable the HDMI CEC which I need it?

Right, you only need to change source from the soundbar’s remote to the SPDIF/3.5 input. The tv should remain off if only audio is needed.

1 Like

Can anyone say how to install this on a new HASSIO versions? Please

Goodday everyone,

I am pritty new to home assistant, and i am trying to get this to work.
i have a chromecast (v2 i belive) i have chanch the playing device but it issnt working, what am i doing wrong?
entiteit of the cromecast is media_player.huiskamer

i have addit the yaml file

Group:
  Radio:
    name: ChromeCast Radio
    icon: mdi:radio
    entities:
    - input_select.chromecast_radio_station
    - input_text.custom_station
    - input_select.chromecast_radio_speakers
    - input_number.volume_radio
    - script.play_chromecast_radio
    - script.stop_chromecast_radio

input_select:

  chromecast_radio_station:
    name: 'Select Radio Station'
    options:
     - 'Kiss FM'
     - 'Europa FM'
     - 'Rock FM'
     - 'Digi FM'
     - 'Romantic FM'
     - 'Radio Clasic'
     - 'P1'
     - 'P2'
     - 'P3'
     - 'P4'
     - 'Ekot'
     - 'RIX FM'
     - 'Bandit Rock'
     - 'Lugna Favoriter'
     - 'STAR FM'
     - 'Power Hit Radio'
     - 'Bandit Ballads'
     - 'Bandit Classics'
     - 'Bandit Metal'
     - 'RIX FM FRESH'
     - 'Power Club'
     - 'Power Street'
     - 'Indie 101'
     - 'Svenska Favoriter'
     - 'Dansbandsfavoriter'
     - 'Country Classics'
     - 'Star 90s'
     - 'Star 80s'
     - 'Star 70s'
     - 'Star 60s'
     - 'Electro Lounge'
     - 'Soul Classics'
     - 'One Hit Wonders'
    icon: mdi:radio

  chromecast_radio_speakers:
    name: 'Select Speakers'
    options:
      - LivingRoom
    initial: LivingRoom
    icon: mdi:speaker-wireless

input_text:
  custom_station:
    name: Radio URL
    icon: mdi:link-variant

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

script:
  play_chromecast_radio:
    alias: Cast Selected Radio on Chromecast Speakers
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_station", "LivingRoom") %} media_player.huiskamer
            {% 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_station", "LivingRoom") %} media_player.huiskamer
            {% endif %}
          media_content_id: >
            {% if is_state("input_select.radio_station", "Kiss FM") %} http://andromeda.shoutca.st:8396/;stream.mp3
            {% elif is_state("input_select.radio_station", "Europa FM") %} http://astreaming.europafm.ro:8000/europafm_aacp48k.m3u
            {% elif is_state("input_select.radio_station", "Rock FM") %} http://80.86.106.143:9128/rockfm.mp3
            {% elif is_state("input_select.radio_station", "Digi FM") %} http://edge76.rdsnet.ro:84/digifm/digifm.mp3
            {% elif is_state("input_select.radio_station", "Romantic FM") %} http://5.254.113.34:9123/romanticfm.aacp
            {% elif is_state("input_select.radio_station", "Radio Clasic") %} http://37.251.146.169:8000/stream
            {% elif is_state("input_select.radio_station", "P1") %} https://sverigesradio.se/topsy/direkt/132-hi-mp3
            {% elif is_state("input_select.radio_station", "P2") %} https://sverigesradio.se/topsy/direkt/2562-hi-mp3
            {% elif is_state("input_select.radio_station", "P3") %} https://sverigesradio.se/topsy/direkt/164-hi-mp3
            {% elif is_state("input_select.radio_station", "P4") %} https://sverigesradio.se/topsy/direkt/212-hi-mp3
            {% elif is_state("input_select.radio_station", "Ekot") %} https://sverigesradio.se/topsy/direkt/4540-hi-mp3
            {% elif is_state("input_select.radio_station", "RIX FM") %} http://fm01-icecast.mtg-r.net/fm01_aac
            {% elif is_state("input_select.radio_station", "Bandit Rock") %} http://fm02-icecast.mtg-r.net/fm02_aac
            {% elif is_state("input_select.radio_station", "Lugna Favoriter") %} http://fm03-icecast.mtg-r.net/fm03_aac
            {% elif is_state("input_select.radio_station", "STAR FM") %} http://fm05-icecast.mtg-r.net/fm05_aac
            {% elif is_state("input_select.radio_station", "Power Hit Radio") %} http://fm04-icecast.mtg-r.net/fm04_aac
            {% elif is_state("input_select.radio_station", "Bandit Ballads") %} http://wr21-ice.stream.mtgr.se/wr21_aac
            {% elif is_state("input_select.radio_station", "Bandit Classics") %} http://wr11-icecast.mtg-r.net/wr11_aac
            {% elif is_state("input_select.radio_station", "Bandit Metal") %} http://wr03-icecast.mtg-r.net/wr03_aac
            {% elif is_state("input_select.radio_station", "RIX FM FRESH") %} http://wr04-icecast.mtg-r.net/wr04_aac
            {% elif is_state("input_select.radio_station", "Power Club") %} http://wr06-icecast.mtg-r.net/wr06_aac
            {% elif is_state("input_select.radio_station", "Power Street") %} http://wr07-icecast.mtg-r.net/wr07_aac
            {% elif is_state("input_select.radio_station", "Indie 101") %} http://wr05-icecast.mtg-r.net/wr05_aac
            {% elif is_state("input_select.radio_station", "Svenska Favoriter") %} http://wr13-icecast.mtg-r.net/wr13_aac
            {% elif is_state("input_select.radio_station", "Dansbandsfavoriter") %} http://wr15-icecast.mtg-r.net/wr15_aac
            {% elif is_state("input_select.radio_station", "Country Classics") %} http://wr14-icecast.mtg-r.net/wr14_aac
            {% elif is_state("input_select.radio_station", "Star 90s") %} http://wr12-icecast.mtg-r.net/wr12_aac
            {% elif is_state("input_select.radio_station", "Star 80s") %} http://wr02-icecast.mtg-r.net/wr02_aac
            {% elif is_state("input_select.radio_station", "Star 70s") %} http://wr10-icecast.mtg-r.net/wr10_aac
            {% elif is_state("input_select.radio_station", "Star 60s") %} http://wr09-icecast.mtg-r.net/wr09_aac
            {% elif is_state("input_select.radio_station", "Electro Lounge") %} http://wr16-icecast.mtg-r.net/wr16_aac
            {% elif is_state("input_select.radio_station", "Soul Classics") %} http://wr08-icecast.mtg-r.net/wr08_aac
            {% elif is_state("input_select.radio_station", "One Hit Wonders") %} http://wr18-icecast.mtg-r.net/wr18_aac
            {% endif %}
          media_content_type: 'audio/mp4'
  
  stop_chromecast_radio:
    alias: Stop Playing Radio on ChromeCast 
    sequence:
      - service: media_player.turn_off
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_station", "LivingRoom") %} media_player.huiskamer
            {% endif %}

group: should not have an UPPERCASE G, neither should the R in radio:

When you say ‘it isn’t working’, what error are you getting? What exactly doesn’t work?

Hy thanks frontje responce

If i select A radio station en press the play button The State changes for a split second and goos back to the start. Like of the program diddnt run Sorry for mu english Hope it makes sense.

Any errors in the log?

Hi sorry for the late response my sd card crashed so have to start over:)
i just have copied the lines back to home assistant.

i onley have 1 chrome cast right now thats called : media_player.huiskamer

in my radio.yaml file i have to chance the chrome cast
i do that at
service: media_player.volume_set
service: media_player.play_media
service: media_player.turn_off

there i chanch this

        {% if is_state("input_select.chromecast_radio_speakers", "LivingRoom") %} media_player.living_room_speaker
        {% elif is_state("input_select.chromecast_radio_speakers", "Bedroom") %} media_player.bedroom_speaker
        {% elif is_state("input_select.chromecast_radio_speakers", "TV") %} media_player.chromecast0899
        {% elif is_state("input_select.chromecast_radio_speakers", "All") %} media_player.home_group
        {% endif %}

to

        {% if is_state("input_select.chromecast_radio_speakers", "LivingRoom") %} media_player.huiskamer

        {% endif %}

and here

chromecast_radio_speakers:
name: ‘Select Speakers’
options:
- LivingRoom
- Bedroom
- TV
- All

chance to this

chromecast_radio_speakers:
name: ‘Select Speakers’
options:
- LivingRoom

i may add some speakers later so wanna keep the pull out menu.

if i change it like this am i doing it right ?

kind regards Dennis Visser

Looks about right :+1:. Just remove that additional blank line before the ‘endif’ part

Hello, first of all: thanks @Bob_NL! Your code seems very nice but I think I am doing something wrong. As final result I get this: image. When I am sliding with the volume button, I hear my Google Nest Mini changing the volume, so that is working fine. But when I try to cast a radio channel to the Nest Mini, nothing seems to happen. I already tried simply casting with your little radio testscript and even that doesn’t work. No errors are shown. Can someone help me?
Thanks in advance!

First try a different url stream. Chances are the url you are using is down. Does the url work when visiting in your browser directly? Do you hear a stream playing? If not try a different url in your script. So look for a working url link of the radio station you’re trying to listen to.

If the url is not the issue, post the code of your script (please use the use the correct format, don’t just paste it like plain text). Nobody can help if you only post a picture of your card. It doesn’t really tell us much.

Thank you for the quick reply! The link I was using worked in my browser and I heared a stream playing.
Here are my files:
in scripts.yaml:

radio:
    alias: Play Radio on Chromecast Audio
    sequence:
      -  service: media_player.play_media
         data_template:
            entity_id: >
                {% if is_state("input_select.chromecast_radio", "Keuken") %} media_player.eetkamer
                {% elif is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
                {% elif is_state("input_select.chromecast_radio", "Ruben") %} media_player.nest_ruben
                {% elif is_state("input_select.chromecast_radio", "Overal") %} media_player.volledige_huis
                {% endif %}
            media_content_id: >
                {% if is_state("input_select.radio_station", "Radio 1") %} http://icecast.vrtcdn.be/radio1-mid.mp3
                {% elif is_state("input_select.radio_station", "MNM") %} http://icecast.vrtcdn.be/mnm-mid.mp3
                {% elif is_state("input_select.radio_station", "Nostalgie") %} http://nostalgiewhatafeeling.ice.infomaniak.ch/nostalgiewhatafeeling-128.mp3
                {% elif is_state("input_select.radio_station", "MNM hits") %} http://icecast.vrtcdn.be/mnm_hits-mid.mp3
                {% elif is_state("input_select.radio_station", "MNM 90's & 00's") %} http://icecast.vrtcdn.be/mnm_90s00s-mid.mp3
                {% endif %}
            media_content_type: 'audio/mp4'
            volume_level: '{{  states.input_number.volume_radio.state  }}'

in my configuration.yaml:

default_config:
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant: 
    customize: !include customize.yaml
input_select:
  radio_station:
    name: 'Selecteer radio station:'
    options:
      - Radio 1
      - MNM
      - Nostalgie
      - MNM hits
      - MNM 90's & 00's
  chromecast_radio:
    name: 'Selecteer Chromecast:'
    options:
      - Keuken
      - Lounge
      - Ruben
      - Overal
    initial: Overal
    icon: mdi:speaker-wireless
    
input_number: 
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05 

This is my automations.yaml but this part works.

  - 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", "Keuken") %} media_player.eetkamer
                {% elif is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
                {% elif is_state("input_select.chromecast_radio", "Ruben") %} media_player.nest_ruben
                {% elif is_state("input_select.chromecast_radio", "Overal") %} media_player.volledige_huis
                {% endif %}
            volume_level: '{{  states.input_number.volume_radio.state  }}'

I think these are the most important files to share.

1 Like

Remove this line of the script service: media_player.play_media. That’s not part of the service call so most likely that’s causing issues. It’s also not the original code like that, so you added that yourself there. You need to create it as a separate sequence inside that script. You have it now as a part of the play_media service sequence.

Delete the line and try again. If that starts playing, then create a sequence inside that script and follow the example code again.

3 Likes

It is working now. Thank you for the quick response!

No problem :+1:

yeey it work thanks for the help :slight_smile:

maby something interesting… dutch radio streams
https://hendrikjansen.nl/henk/streaming.html#AS

4 Likes