How to configure a radio stations player

How to configure a radio stations player

Hi guys,

In this article I introduced how to use Home Assistant to listen to internet radio stations.

What described in that article was something super basic. Nothing was created, I had just simply used what Home Assistant provides by default.?

Today I want to go a little bit deeper.

Recetly I've created some things to be able to:

  • select the radio station from a pre-configured list
  • select the device on which playing the radio stations (in my case google speakers)
  • increase / decrease volume
  • start / pause / stop playing

Software configuration

  1. Home Assistant. I'm currently running version?2022.9.6.
  2. Google Cast integration?configured in Home Assistant. This integration allows you to control your google devices for video streaming as well as audio via Home Assistant.

Home Assistant code (yaml) / procedure

I've created the following objects described below:

  • A brand new view named Radio and the following entities card:

No alt text provided for this image







  • The entities card is composed by:

No alt text provided for this image

Dropdown list to select the Radio station you want to listen to







No alt text provided for this image

Another dropdown list to select the speaker on which playing the radio station





No alt text provided for this image

A button to start playing

No alt text provided for this image

A control area to pause / stop playing and set the volume on the selected device

Please refer to this video to get in touch with the feature:

Are you curious to see the code written to do this?

Well, this is the code - as Script - I've written to manage everything:

sequence:
? - service: media_player.volume_set
? ? data_template:
? ? ? entity_id: |
? ? ? ? {%- if is_state("input_select.google_speaker_radio", "Casa") -%}
? ? ? ? ? group.multimedia
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Cucina") -%}
? ? ? ? ? media_player.cucina
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Cameretta") -%}
? ? ? ? ? media_player.camera_matrimoniale
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Soggiorno") -%}
? ? ? ? ? media_player.soggiorno
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Studio") -%}
? ? ? ? ? media_player.studio
? ? ? ? {%- endif -%}
? ? ? volume_level: 0.15
? - delay: 0.5
? - service: media_player.play_media
? ? target:
? ? ? entity_id: |
? ? ? ? {%- if is_state("input_select.google_speaker_radio", "Casa") -%}
? ? ? ? ? group.multimedia
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Cucina") -%}
? ? ? ? ? media_player.cucina
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Cameretta") -%}
? ? ? ? ? media_player.camera_matrimoniale
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Soggiorno") -%}
? ? ? ? ? media_player.soggiorno
? ? ? ? {%- elif is_state("input_select.google_speaker_radio", "Studio") -%}
? ? ? ? ? media_player.studio
? ? ? ? {%- endif -%}
? ? data:
? ? ? media_content_id: >
? ? ? ? {%- if is_state("input_select.radio_stations_list", "One Dance") -%}
? ? ? ? ? media-source://radio_browser/7a67fe09-ab18-11e9-88f4-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 La Banda di
? ? ? ? R101") -%}
? ? ? ? ? media-source://radio_browser/b34742d3-7fad-11e8-a43d-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 Enjoy The
? ? ? ? Music") -%}
? ? ? ? ? media-source://radio_browser/96262cd1-0601-11e8-ae97-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '90") -%}
? ? ? ? ? media-source://radio_browser/9639f338-0601-11e8-ae97-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '00") -%}
? ? ? ? ? media-source://radio_browser/9624a5a0-0601-11e8-ae97-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio 105
? ? ? ? Network") -%}
? ? ? ? ? media-source://radio_browser/9619ea14-0601-11e8-ae97-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Kiss Kiss
? ? ? ? Italia")-%}
? ? ? ? ? media-source://radio_browser/961756e4-0601-11e8-ae97-52543be04c81
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Babboleo
? ? ? ? Suono")-%}
? ? ? ? ? media-source://radio_browser/af6fdb6a-a57b-4cc9-ab92-53c826041aef
? ? ? ? {%- endif -%}
? ? ? extra:
? ? ? ? thumb: >
? ? ? ? ? {%- if is_state("input_select.radio_stations_list", "One Dance") -%}
? ? ? ? ? ? ?https://onedance.fm/img/apple-touch-icon-114x114.png
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 La Banda
? ? ? ? ? di R101")-%}
? ? ? ? ? ? ?https://www.r101.it/favicon_7.ico?v=1561631502000
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 Enjoy The
? ? ? ? ? Music") -%}
? ? ? ? ? ? ?https://www.r101.it/favicon_7.ico?v=1561631502599
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '90") -%}
? ? ? ? ? ? ?https://www.r101.it/favicon_7.ico?v=1561631502000
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '00") -%}
? ? ? ? ? ? ?https://www.r101.it/favicon_7.ico?v=1561631502599
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio 105
? ? ? ? ? Network") -%}
? ? ? ? ? ? ?https://upload.wikimedia.org/wikipedia/it/0/01/105.png
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Kiss Kiss
? ? ? ? ? Italia") -%}
? ? ? ? ? ? ?https://kisskissitalia.it/wp-content/uploads/2021/07/cropped-favicon-kisskissitalia-180x180.png?
? ? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Babboleo
? ? ? ? ? Suono") -%}
? ? ? ? ? ? ?https://players.fluidstream.it/RadioBabboleo/images/babboleo_suono.png
? ? ? ? ? {%- endif -%}
? ? ? media_content_type: audio/aac
? ? metadata:
? ? ? title: >
? ? ? ? {%- if is_state("input_select.radio_stations_list", "One Dance") -%}
? ? ? ? ? One Dance
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 La Banda di
? ? ? ? R101") -%}
? ? ? ? ? R101 La Banda di R101
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 Enjoy The
? ? ? ? Music") -%}
? ? ? ? ? R101 Enjoy The Music
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '90") -%}
? ? ? ? ? R101 90
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "R101 '00") -%}
? ? ? ? ? R101 00
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio 105
? ? ? ? Network") -%}
? ? ? ? ? Radio 105 Network
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Kiss Kiss
? ? ? ? Italia") -%}
? ? ? ? ?Radio Kiss Kiss Italia
? ? ? ? {%- elif is_state("input_select.radio_stations_list", "Radio Babboleo
? ? ? ? Suono") -%}
? ? ? ? ?Radio Babboleo Suono
? ? ? ? {%- endif -%}
mode: single
icon: mdi:radio
alias: AscoltaRadio        

Some specifics about the code / steps above

  • The script above is executed everytime you click this button

No alt text provided for this image


  • I've set a default volume at 15%
  • The speaker device to be used and the radio station to listen to are dynamically selected according to the dropdown lists
  • Of course you can customize the radio station list with your favourite ones. Here you can find any radio station you want

Thank you for reading and watching. ?? I hope you have enjoyed this article and video too.

I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below.

Your feedbacks will be very appreciated!

Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read all previous episodes and still up to date on latest news.

Chen Hezkel

Expert team manager and hungry for more

1 年

Hey, Great tutorial! What entity using in the "attualmente in play" section? Can you share this code?

回复
Federico Crucitti

Electronics and Computer Control Expert at the Physics Department at University of Antwerp

1 年

This tutorial helped me a lot with building up a selection of radio stations which can be played through a google home mini. It worked for months. Since I installed the last update Home Assistant (2023.3.5), the buttons are disabled. The warning says (translated) that the entity for input_select and input_number are not available anymore. Did to your knowledge some partial way of coding get depreciated? Nothing changed on the system a part from the updates, so I'm assuming the cause must have to do with that.

  • 该图片无替代文字
回复
Bert Hennink

Retired Sr Hardware expert Engineer at Krohne New Technologies

1 年

Hi I found this script dor playing the radio in HA. I looks interesting and The script looks clear to me and easy enoug to patse as a script. Editting for the stations is the next thing when all is working. But hopd did you create the 'view'? Which card did you use? you write Dropdown list to select the Radio station you want to listen to And another dropdown list. I looked in my cards but do not see a dropdown list

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了