Skip to content

Instantly share code, notes, and snippets.

@TheGroundZero
Last active August 13, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheGroundZero/d01a94ed1d5fa6a752d0bb11510f4c7d to your computer and use it in GitHub Desktop.
Save TheGroundZero/d01a94ed1d5fa6a752d0bb11510f4c7d to your computer and use it in GitHub Desktop.
Webradio player for Home Assistant, with dropdown list and input field
# Requirements
# - Media extractor integration - https://www.home-assistant.io/integrations/media_extractor/
# - Mini media player (HACS) - https://github.com/kalkih/mini-media-player
# - A smart speaker, e.g. Xiaomi Mi Smart Speaker - https://s.click.aliexpress.com/e/_A0zLJq
# - Some URLs for web radio stations
# - (optional) Images/logos of the radio stations
# configuration.yaml
# ------------------
homeassistant:
packages: !include_dir_merge_named packages/
media_extractor:
# Lovelace dashboard
# -------------------
type: vertical-stack
cards:
- type: custom:mini-media-player
group: false
artwork: cover
source: full
sound_mode: full
info: short
name: Living Room
idle_view:
when_idle: true
entity: media_player.livingroom
- type: entities
entities:
- entity: input_select.radio_station
name: station
- entity: script.play_radio
tap_action:
action: call-service
service: script.turn_on
service_data:
entity_id: script.play_radio
- type: entities
entities:
- entity: input_text.url
name: URL
- entity: script.play_media_url
tap_action:
action: call-service
service: script.turn_on
service_data:
entity_id: script.play_media_url
icon: mdi:play
# Images
# --------
# If you want the logos of the webradio stations to be displayed in the mini media player card
# put them in a subfolder of the /config/www/ folder, which is referenced as /local/ in the URL.
# /config/packages/mediaplayers/webradio.yaml
# --------------------------------------------
---
# Play webradio on smart speaker(s)
#
# Based on https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732
#
# https://www.home-assistant.io/integrations/media_player
# https://www.home-assistant.io/integrations/input_select/
#
webradio:
script:
play_radio:
alias: Play radio
icon: mdi:play
description: Play web radio on Chromecast
mode: restart
sequence:
- service: media_player.volume_set
data:
entity_id: media_player.livingroom
volume_level: 0.10
- service: media_player.play_media
data:
entity_id: media_player.livingroom
media_content_type: music
media_content_id: >
{%- set station = states('input_select.radio_station') -%}
{% if station == "VRT Radio 1" %} http://icecast.vrtcdn.be/radio1-high.mp3
{% elif station == "VRT Radio 1 - Classics" %} http://icecast.vrtcdn.be/radio1_classics-high.mp3
{% elif station == "VRT Radio 1 - De LageLandenLijst" %} http://icecast.vrtcdn.be/radio1_lagelanden-high.mp3
{% elif station == "VRT Radio 2 Bene Bene" %} http://icecast.vrtcdn.be/radio2_benebene-high.mp3
{% elif station == "VRT Radio 2 West-Vlaanderen" %} http://icecast.vrtcdn.be/ra2wvl-high.mp3
{% elif station == "VRT Radio 2 Unwind" %} http://icecast.vrtcdn.be/radio2_unwind-high.mp3
{% elif station == "VRT Studio Brussel" %} http://icecast.vrtcdn.be/stubru-high.mp3
{% elif station == "VRT Studio Brussel - Bruut" %} http://icecast.vrtcdn.be/stubru_bruut-high.mp3
{% elif station == "VRT Studio Brussel - Hooray" %} http://icecast.vrtcdn.be/stubru_hiphophooray-high.mp3
{% elif station == "VRT Studio Brussel - De Tijdloze" %} http://icecast.vrtcdn.be/stubru_tijdloze-high.mp3
{% elif station == "VRT Studio Brussel - #ikluisterbelgisch" %} http://icecast.vrtcdn.be/stubru_tgs-high.mp3
{% elif station == "VRT Studio Brussel UNTZ" %} http://icecast.vrtcdn.be/stubru_untz-high.mp3
{% elif station == "VRT MNM" %} http://icecast.vrtcdn.be/mnm-high.mp3
{% elif station == "VRT MNM R&Beats" %} http://icecast.vrtcdn.be/mnm_urb-high.mp3
{% elif station == "VRT MNM Hits" %} http://icecast.vrtcdn.be/mnm_hits-high.mp3
{% elif station == "VRT MNM 90's & 00's" %} http://icecast.vrtcdn.be/mnm_90s00s-high.mp3
{% elif station == "VRT Ketnet Hits" %} http://icecast.vrtcdn.be/ketnetradio-high.mp3
{% elif station == "VRT NWS" %} http://progressive-audio.lwc.vrtcdn.be/content/fixed/11_11niws-snip_hi.mp3
{% elif station == "Topradio" %} https://str.topradio.be/topradio.mp3
{% elif station == "Qmusic" %} https://21293.live.streamtheworld.com/QMUSIC.mp3
{% elif station == "VBRO" %} https://radiohuis.com/VBRO
{% elif station == "Willy Radio" %} http://20723.live.streamtheworld.com/WILLY.mp3
{% endif %}
extra:
thumb: >
{%- set station = states('input_select.radio_station') -%}
{% if 'Studio Brussel' in station %} https://<my_homeassistant>/local/img/logo/logo_stubru.svg
{% elif 'MNM' in station %} https://<my_homeassistant>/local/img/logo/logo_mnm.svg
{% elif 'NWS' in station %} https://<my_homeassistant>/local/img/logo/logo_vrtnws.svg
{% elif station[:3] == "VRT" %} https://<my_homeassistant>/local/img/logo/logo_vrt.svg
{% elif station == "Topradio" %} https://<my_homeassistant>/local/img/logo/logo_topradio.svg
{% elif station == "Qmusic" %} https://<my_homeassistant>/local/img/logo/logo_qmusic.svg
{% elif station == "VBRO" %} https://<my_homeassistant>/local/img/logo/logo_vbro.png
{% elif station == "Willy Radio" %} https://<my_homeassistant>/local/img/logo/logo_willy.svg
{% endif %}
stream_type: LIVE
play_media_url:
alias: Play media from URL
mode: single
icon: mdi:music-box-multiple-outline
sequence:
- service: media_player.media_stop
target:
entity_id: media_player.livingroom
- service: media_player.volume_set
data:
entity_id: media_player.livingroom
volume_level: 0.10
- service: media_extractor.play_media
data:
media_content_type: MUSIC
media_content_id: "{{ states('input_text.url') }}"
target:
entity_id: media_player.livingroom
input_text:
url:
name: URL
min: 10
max: 255
icon: mdi:web
mode: text
input_select:
radio_station:
name: 'Kies radiostation'
icon: mdi:radio
initial: VRT Studio Brussel
options:
- VRT Radio 1
- VRT Radio 1 - Classics
- VRT Radio 1 - De LageLandenLijst
- VRT Radio 2 Bene Bene
- VRT Radio 2 West-Vlaanderen
- VRT Radio 2 Unwind
- VRT Studio Brussel
- VRT Studio Brussel - Bruut
- VRT Studio Brussel - Hooray
- VRT Studio Brussel - De Tijdloze
- "VRT Studio Brussel - #ikluisterbelgisch"
- VRT Studio Brussel UNTZ
- VRT MNM
- VRT MNM R&Beats
- VRT MNM Hits
- VRT MNM 90's & 00's
- VRT Ketnet Hits
- VRT NWS
- Topradio
- Qmusic
- Topradio
- VBRO
- Willy Radio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment