Chromecast Radio with station and player selection

Use stack-in-card instead of vertical-stack. That allows you create vertical and horizontal stacks where the button cards have no gaps and look like one single card. This is what I use for most of my UI to give it a more clean look.

For example:


These are all stack within stacks, but they appear as single cards.

Make sure you use 0.1.1, 0.2.0 has a bug with nested cards.

1 Like

Nice!

I’ll give a go

Thanks man! :slight_smile: :ok_hand:t3:

1 Like

Guys,

Streaming to Sonos will not work by me. Streaming to googlehome mini or Chromecast is no problem. What should be the problem?

Hello dear people…i have been reading the original post and scrolling till 2021. I am quite confuse to which is the working iteration now on the current HA version.

I got a google home mini and interested in streaming tunein or other radio to the mini. I don’t have a Spotify account. If anyone can point me to the right direction please?
Thanks

If you haven’t already, setup the package folder / file

Place this in the yaml file:

input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
      - Hit 92-9
      - Nova 93-7
      - Mix 94-5
      - 96FM
      - 80's 1
      - 80's 2
      - OldSkool Hits
      - Old Skool Anthems
      - Raw FM (dance)
      - 181FM Power (Todays Hits)
      - 181FM 90's Dance
      - 181FM Star 90's
      - 181FM The Breeze
      - Heat Radio (RnB)
      - Fresh 92-7
      - DI Chill & Tropical House
      - DI Disco House
      - DI Funky House
      - DI Liquid D&B
      - Aloha Joe's Relaxation Island
      - Spectrum Fit
      - Energy FM Australia
      - Jazz Relax
      - Australian Country
      - Rebel FM
    initial: Raw FM (dance)
    icon: mdi:radio

    

  chromecast_radio:
    name: 'Select Speakers:'
    options:
      - Lounge
      - Bedroom
      - Office
      - Lounge and Office
      - House
      - House except office
      - Everywhere
      - Everywhere except office
      - Back yard
    initial: House
    icon: mdi:speaker-wireless

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

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

  - alias: 'Set Chromecast 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", "Lounge") %} media_player.lounge_speakers
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.chromecastaudio3249
          {% elif is_state("input_select.chromecast_radio", "Lounge and Office") %} media_player.lounge_and_office
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house
          {% elif is_state("input_select.chromecast_radio", "House except office") %} media_player.house_except_office
          {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.everywhere
          {% elif is_state("input_select.chromecast_radio", "Everywhere except office") %} media_player.all_except_office
          {% elif is_state("input_select.chromecast_radio", "Back yard") %} media_player.back_yard
          {% endif %}
        volume_level: '{{  states.input_number.volume_radio.state  }}'

script:

  radio:
    alias: Play Radio on Chromecast Audio
    sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge_speakers
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.chromecastaudio3249
          {% elif is_state("input_select.chromecast_radio", "Lounge and Office") %} media_player.lounge_and_office
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house
          {% elif is_state("input_select.chromecast_radio", "House except office") %} media_player.house_except_office
          {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.everywhere
          {% elif is_state("input_select.chromecast_radio", "Everywhere except office") %} media_player.all_except_office
          {% elif is_state("input_select.chromecast_radio", "Back yard") %} media_player.back_yard
          {% 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", "Lounge") %} media_player.lounge_speakers
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.chromecastaudio3249
          {% elif is_state("input_select.chromecast_radio", "Lounge and Office") %} media_player.lounge_and_office
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house
          {% elif is_state("input_select.chromecast_radio", "House except office") %} media_player.house_except_office
          {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.everywhere
          {% elif is_state("input_select.chromecast_radio", "Everywhere except office") %} media_player.all_except_office
          {% elif is_state("input_select.chromecast_radio", "Back yard") %} media_player.back_yard
          {% endif %}
        media_content_id: >
          {% if is_state("input_select.radio_station", "Hit 92-9") %} http://ic6ti.scahw.com.au/6ppm_128
          {% elif is_state("input_select.radio_station", "Nova 93-7") %} http://streaming.novaentertainment.com.au/nova937
          {% elif is_state("input_select.radio_station", "Mix 94-5") %} http://sc01.scahw.com.au/6mix_32
          {% elif is_state("input_select.radio_station", "96FM") %} https://icy.ihrcast.arn.com.au/au_012_icy
          {% elif is_state("input_select.radio_station", "80's 1") %} http://ic2ti.scahw.com.au/2easy_128
          {% elif is_state("input_select.radio_station", "80's 2") %} http://18243.live.streamtheworld.com/T_RAD_80S_S01_SC?
          {% elif is_state("input_select.radio_station", "OldSkool Hits") %} http://sc01.scahw.com.au/loveland_32
          {% elif is_state("input_select.radio_station", "Old Skool Anthems") %} http://nebula.shoutca.st:8075/stream
          {% elif is_state("input_select.radio_station", "Raw FM (dance)") %} https://frontend.stream.rawfm.net.au/i/syd-stream-192k.mp3 
          {% elif is_state("input_select.radio_station", "181FM Power (Todays Hits)") %} http://listen.181fm.com/181-power_128k.mp3?
          {% elif is_state("input_select.radio_station", "181FM 90's Dance") %} http://listen.181fm.com/181-90sdance_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM Star 90's") %} http://listen.181fm.com/181-star90s_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM The Breeze") %} http://listen.181fm.com/181-breeze_128k.mp3
          {% elif is_state("input_select.radio_station", "Heat Radio (RnB)") %} http://174.37.159.206:8106/stream
          {% elif is_state("input_select.radio_station", "Fresh 92-7") %} http://live.fresh927.com.au:80/freshaac
          {% elif is_state("input_select.radio_station", "DI Chill & Tropical House") %} http://pub1.diforfree.org:8000/di_chillntropicalhouse_hi
          {% elif is_state("input_select.radio_station", "DI Disco House") %} http://pub1.diforfree.org:8000/di_discohouse_hi
          {% elif is_state("input_select.radio_station", "DI Funky House") %} http://pub1.diforfree.org:8000/di_funkyhouse_hi
          {% elif is_state("input_select.radio_station", "DI Liquid D&B") %} http://pub1.diforfree.org:8000/di_liquiddnb_hi
          {% elif is_state("input_select.radio_station", "Aloha Joe's Relaxation Island") %} http://s2.voscast.com:7932/
          {% elif is_state("input_select.radio_station", "Spectrum Fit") %} http://51.255.235.165:5292/
          {% elif is_state("input_select.radio_station", "Energy FM Australia") %} http://s3.viastreaming.net:8502/
          {% elif is_state("input_select.radio_station", "Jazz Relax") %} http://199.195.194.94:8036/stream
          {% elif is_state("input_select.radio_station", "Australian Country") %} https://streaming.radio.co/s5ea3fdd1c/listen
          {% elif is_state("input_select.radio_station", "Rebel FM") %} https://au1.fastcast4u.com/proxy/rblgc?mp=/stream
          {% endif %}
        media_content_type: 'audio/mp4'

Adjust the entity id’s for your media players accordingly, change the radio station URL’s to whatever you want etc.

In Lovelace add a card:

entities:
  - input_select.radio_station
  - input_select.chromecast_radio
  - script.radio
  - input_number.volume_radio
header:
  image: /local/images/internet_radio.jpg
  type: picture
show_header_toggle: false
type: entities

Save this file under: www\images\internet_radio.jpg

internet_radio

…and you should end up with this:
image

6 Likes

thanks a lot. It works :slight_smile:

Not sure if this is the right forum, but would it be possible to use the same setup for TV-stations? I want to see live TV on my chromecast with a list of tv stations, like SVT1, TV4 etc (Swedish).

Hello, I have added Sonos support for my script.

  1. In the device select, all sonos devices have to have “Sonos” in the name eg.:
chromecast_radio:
    name: 'Device:'
    options:
      - Citation AMP
      - TV
      - Sonos Keittiö
    initial: Citation AMP
    icon: mdi:speaker-wireless

And here is an example how the media_content_id needs to be set:
(PS. Did not check if people have set the extra.title, but here is an example for that aswell. it will show the title in non-audio chrome cast devices and so on…)
(PPS media_content_type is music, as documentation suggests. Don’t know why OP had string there)

media_content_id: >
          {% if is_state("input_select.radio_station", "City") %}{% set url = "https://stream.bauermedia.fi/radiocity/radiocity_64.aac" %}
          {% elif is_state("input_select.radio_station", "Nostalgia") %}{% set url = "https://stream.bauermedia.fi/nostalgia/nostalgia_64.aac" %}
          {% elif is_state("input_select.radio_station", "Radio Rock") %}{% set url = "https://supla.digitacdn.net/live/_definst_/supla/radiorock/playlist.m3u8" %}
          {% endif %}
          {% if "Sonos" in states("input_select.chromecast_radio") %}x-rincon-mp3radio://{{url.split("://")[1]}}
          {% else %}{{url}}
          {% endif %}
        media_content_type: music
        extra:
          title: "{{ states('input_select.radio_station') }}"

Sonos uses the scheme x-rincon-mp3radio instead of http/https. All my streams work with https and http, so I’m not sure if sonos actually plays https streams.

:beer: Cheers, Ville

Thanks for sharing your code with specific reference to how to tackle different URL for Sonos and chromecast which works perfectly fine. I’m using the script to serve multiple rooms. For that purpose I wish to store the currently selected station for each room such that once I return to the specific room selection menu, it defaults to the currently selected/played music station. In principle it’s the reverse of the selection procedure:

 - platform: template
  sensors:
    radio_select_sonos:
      value_template: >-
          {% if is_state_attr('media_player.office', 'media_content_id', "x-rincon-mp3radio://https://21223.live.streamtheworld.com:443/SKYRADIO.mp3") %} 
            Sky Radio
           ........
          {% endif %}

This all works fine for my google chromecast devices which return the stream URL as specified. For SONOS, the situation is different. The above station returns a URL which is totally different from what was entered and moreover not consistent in what it returns. In case of the above URL, SONOS returns on the command:

 {{state_attr('media_player.office', 'media_content_id')}} the following URL which differs every time:
x-rincon-mp3radio://https://21283.live.streamtheworld.com:443/SRGSTR01.mp3

As stated, this URL is not consistent and changes very time the station is selected such that it would be impossible to store the currently selected station for the specific room.
Have you ever come across this phenomena and know how to overcome.

For chromecasts the urls should look like https://example.com and for sonos x-rincon-mp3radio://example.com. I see you are checking the state for x-rincon-mp3radio://https://example.com.
That shouldn’t work for either of the devices. Maybe try to figure out what the media_content_id for the devices are in the developer tools. Select the entity there and see what the url is. For me the Sonos has what I have set it. Anyways, I think you should read the state to a variable first and then just check if it contains the some part that is after the scheme for example:

{% set mediaIdOffice = state_attr('media_player.office', 'media_content_id') %}
{% if "SKYRADIO.mp3" in mediaIdOffice %} 
  Sky Radio
  ........
{% endif %}

Thanks a lot for putting me on a progressive trail. My URL’s specific to chromecast and sonos respectively are consistent with what you quoted in your response. Your proposed solution based on identifying string with {% if "SKYRADIO.mp3" in mediaIdOffice %} based on ‘media_content_id’ works fine for SONOS.
For chromecast using the Beosound Core, the content of ‘media_content_id’ is not always consistent and sometimes results in { {url}} response instead of the stream URL. However, I figured out that consistently and in all cases, the selected station name is being stored in ‘media_content_id’ and subsequently used instead using your if “contains-string” concept. Thanks a lot.
What I noticed though is that once changing room selection, though it defaults properly to the selected (currently running) radio station, it’s not a bumpless transfer. In other words, it reloads the currently played radio station URL. This looks obvious since one trigger is ‘input_select.radio_station’. I have tried to implement a value_template condition which, once true, will only continue with the action which contains the media_content_id’s.
To avoid a reload of the stream URL, the condition checks whether the result of the ‘mediaIdOffice’ is un-equal to ‘input_select.radio_station’ in which case fire ‘action’, otherwise stop.
If the above makes sense and you have a suggestion, I would appreciate yr feedback.

Folks, I now have everything working, sort of ;

image

But I have several ways to initiate playback on my devices. And if I use any other method than this Lovelace card, I’d like to make an automation that automatically populates this card, so that it shows the chosen settings independently of how it was initiated.
I know that it is possible to set the input.select value in a script. My problem is that if I do, it automatically also triggers the automation behind the card - just as if I had made a manual selection. This in turn again triggers the script, and I’m in a never ending loop.

So, I’m looking for a clever way to populate the on-screen display, without actually triggering the automation.
Any ideas, anyone?

Turn the automaton off before you update the input select, update it, then turn the automation back on?

Oh, can one automation turn another off? How?

Just use a service call:

service: automation.turn_off
entity_id: automation.YOUR_AUTOMATION_YOU_WANT_OFF

Can you please help me to make a scraper for Radio10 (dutch radio station from Talpa)
https://www.radio10.nl/radio-luisteren or https://juke.nl/radiozenders/radio-10

I realy don’t know where to start so any help is welcome

https://www.mp3streams.nl/zender/radio-10/stream/9-mp3-128

Well yes and no.
No because it’s honestly quite time consuming to set up, and no because any update to the html/page layout will result in the scrape sensor no longer working.
The yes part would only be “valid” if you’re able to provide a link to a json page from the radio as this is less likely to break/fail.

Thank for the quick reply, I don’t know how to find the json thats just the point :wink:

Sorry can’t help you there. Not all radios post the info in json.
What you’re looking for is a URL that posts information like this example
Then you can fairly easily extract the data. What you don’t want is to scrape the HTML as it will require maintenance at some stage.