started with radio playing over my google home’s, thought Id add my 2 cents to this thread, and share my newly created package. Not a lot of radiostations selected yet, but added a few templating techniques I didn’t see yet here. cut some code
code:
##############################################################################################################
# Package for Radio
# 20190404 @mariusthvdb
# version 0.04 .....
# https://www.home-assistant.io/components/media_player
# https://www.home-assistant.io/components/tts.google/
# based on and inspired by: https://github.com/danielpalstra/home-assistant-config/blob/ef26e6c1a4d341a6a1e2e4a86072052807abc75c/packages/radio.yaml#L86
# and community: https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732/463
##############################################################################################################
homeassistant:
customize:
script.play_radio:
action_name: 'Play'
icon: mdi:play
script.stop_radio:
action_name: 'Stop'
icon: mdi:stop
input_number.radio_volume:
templates:
icon: >
if (state === '0.0') return 'mdi:volume-off';
if (state <= '0.3') return 'mdi:volume-low';
if (state <= '0.6') return 'mdi:volume-medium';
if (state <= '1.0') return 'mdi:volume-high';
icon_color: >
if (state === '0.0') return 'rgb(145,227,237)';
if (state <= '0.1') return 'rgb(105,212,231)';
if (state <= '0.2') return 'rgb(46,147,238)';
if (state <= '0.3') return 'rgb(0,220,16)';
if (state <= '0.4') return 'rgb(0,195,13)';
if (state <= '0.5') return 'rgb(250,255,0)';
if (state <= '0.6') return 'rgb(252,150,0)';
if (state <= '0.7') return 'rgb(218,53,0)';
if (state <= '0.8') return 'rgb(255,0,0)';
if (state <= '0.9') return 'rgb(154,0,0)';
if (state <= '1.0') return 'rgb(81,0,0)';
##############################################################################################################
# Groups
##############################################################################################################
group:
radio:
name: Radio
control: hidden
entities:
- input_select.radio_station
- input_select.media_player
- input_number.radio_volume
- script.play_radio
- input_boolean.stop_radio
- script.stop_radio
##############################################################################################################
# Inputs
##############################################################################################################
input_boolean:
stop_radio:
name: Stop radio
initial: off
icon: mdi:volume-off
input_select:
radio_station:
icon: mdi:radio
name: 'Select Radio Station:'
options:
- 'Radio 1'
- 'Radio 2'
- '3FM'
- 'Radio 4'
- 'SLAM!'
- 'Radio 538'
- 'Q-Music'
- 'Veronica'
- 'Sky Radio'
- 'Arrow Classic Rock'
- 'BNR Nieuwsradio'
- '538 Dance Department'
radio_station_wakeup:
icon: mdi:radio
name: 'Select Wakeup radio:'
options:
- 'Radio 1'
- 'Radio 2'
- '3FM'
- 'Radio 4'
- 'SLAM!'
- 'Radio 538'
- 'Q-Music'
- 'Veronica'
- 'Sky Radio'
- 'Arrow Classic Rock'
- 'BNR Nieuwsradio'
- '538 Dance Department'
radio_station_lullaby:
icon: mdi:radio
name: 'Select Lullaby radio:'
options:
- 'Radio 1'
- 'Radio 2'
- '3FM'
- 'Radio 4'
- 'SLAM!'
- 'Radio 538'
- 'Q-Music'
- 'Veronica'
- 'Sky Radio'
- 'Arrow Classic Rock'
- 'BNR Nieuwsradio'
- '538 Dance Department'
media_player:
name: 'Select Media player:'
icon: mdi:speaker-wireless
options:
- Woonkamer
- Hall
- Master bedroom
- Hobbykamer
- Gym
- Broadcast (all)
initial: Woonkamer
input_number:
radio_volume:
name: Volume
# icon: mdi:volume-high
#initial: 0
min: 0
max: 1
step: 0.05
unit_of_measurement: '%'
##############################################################################################################
# Sensor
##############################################################################################################
sensor:
- platform: template
sensors:
media_player:
friendly_name: Media player
value_template: >
{% set state = states('input_select.media_player') %}
{% if state in ['Woonkamer','Hobbykamer','Hall', 'Master bedroom'] %} media_player.googlehome_{{(state)|lower|replace(' ','_')}}
{% elif state == 'Gym' %} media_player.chromecastaudio_gym
{% else %} group.broadcast
{% endif %}
- platform: template
sensors:
radio_station:
friendly_name: Radio station
value_template: >
{% set mapper =
{ 'Radio 1':'http://icecast.omroep.nl/radio1-bb-mp3',
'Radio 2':'http://icecast.omroep.nl/radio2-bb-mp3',
'3FM':'http://icecast.omroep.nl/3fm-bb-mp3',
'Radio 4':'http://icecast.omroep.nl/radio4-bb-mp3',
'SLAM!':'http://stream.slam.nl/slam',
'Radio 538':'http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO538.mp3',
'Q-Music':'http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3',
'Veronica':'http://19993.live.streamtheworld.com/VERONICA_SC',
'Sky Radio':'http://19983.live.streamtheworld.com/SKYRADIO.mp3',
'Arrow Classic Rock':'https://stream.gal.io/arrow',
'BNR Nieuwsradio':'http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03',
'538 Dance Department':'http://playerservices.streamtheworld.com/api/livestream-redirect/TLPSTR01.mp3'} %}
{% set state = states('input_select.radio_station') %}
{{mapper[state]}}
radio_station_wake_up:
friendly_name: Wakeup station
value_template: >
{% set mapper =
{ 'Radio 1':'http://icecast.omroep.nl/radio1-bb-mp3',
'Radio 2':'http://icecast.omroep.nl/radio2-bb-mp3',
'3FM':'http://icecast.omroep.nl/3fm-bb-mp3',
'Radio 4':'http://icecast.omroep.nl/radio4-bb-mp3',
'SLAM!':'http://stream.slam.nl/slam',
'Radio 538':'http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO538.mp3',
'Q-Music':'http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3',
'Veronica':'http://19993.live.streamtheworld.com/VERONICA_SC',
'Sky Radio':'http://19983.live.streamtheworld.com/SKYRADIO.mp3',
'Arrow Classic Rock':'https://stream.gal.io/arrow',
'BNR Nieuwsradio':'http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03',
'538 Dance Department':'http://playerservices.streamtheworld.com/api/livestream-redirect/TLPSTR01.mp3'} %}
{% set state = states('input_select.radio_station_wakeup') %}
{{mapper[state]}}
radio_station_lullaby:
friendly_name: Lullaby station
value_template: >
{% set mapper =
{ 'Radio 1':'http://icecast.omroep.nl/radio1-bb-mp3',
'Radio 2':'http://icecast.omroep.nl/radio2-bb-mp3',
'3FM':'http://icecast.omroep.nl/3fm-bb-mp3',
'Radio 4':'http://icecast.omroep.nl/radio4-bb-mp3',
'SLAM!':'http://stream.slam.nl/slam',
'Radio 538':'http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO538.mp3',
'Q-Music':'http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3',
'Veronica':'http://19993.live.streamtheworld.com/VERONICA_SC',
'Sky Radio':'http://19983.live.streamtheworld.com/SKYRADIO.mp3',
'Arrow Classic Rock':'https://stream.gal.io/arrow',
'BNR Nieuwsradio':'http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03',
'538 Dance Department':'http://playerservices.streamtheworld.com/api/livestream-redirect/TLPSTR01.mp3'} %}
{% set state = states('input_select.radio_station_lullaby') %}
{{mapper[state]}}
##############################################################################################################
# Scripts
##############################################################################################################
script:
stop_radio:
alias: Stop radio
sequence:
service: media_player.turn_off
data_template:
entity_id: >
{{states('sensor.media_player')}}
# Radio station sources: https://www.hendrikjansen.nl/henk/streaming.html
play_radio:
alias: Play radio
sequence:
- service: media_player.play_media
data_template:
entity_id: >
{{states('sensor.media_player')}}
media_content_id: >
{{states('sensor.radio_station')}}
media_content_type: 'audio/mp4'
play_wakeup_radio:
alias: Play wakeup radio
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.googlehome.master_bedroom
media_content_id: >
{{states('sensor.radio_station_wake_up')}}
media_content_type: 'audio/mp4'
play_lullaby_radio:
alias: Play lullaby radio
sequence:
- service: media_player.play_media
data_template:
entity_id: >
{{states('sensor.media_player')}}
media_content_id: >
{{states('sensor.radio_station_lullaby')}}
media_content_type: 'audio/mp4'
lullaby_radio:
alias: Lullaby radio
sequence:
- alias: Set Volume
service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.4'
# - alias: Say Sleep Left
# service: tts.google_say
# entity_id: media_player.bed_room
# data_template:
# message: >
# Next alarm in {{ (states('sensor.nextalarm').split(" ")[0] | int *60 ) | timestamp_custom("%H") | int }}
# hours and {{ (states('sensor.nextalarm').split(" ")[0] | int *60 ) | timestamp_custom("%M") }}
# minutes . Good night.
# cache: false
- delay:
seconds: 15
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.35'
- condition: state
entity_id: input_boolean.lullaby
state: 'on'
- service: script.play_lullaby_radio
- delay:
minutes: 5
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.3'
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.25'
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.15'
- delay:
minutes: 5
- service: media_player.turn_off
data_template:
entity_id: media_player.googlehome_master_bedroom
wakeup_radio:
alias: wakeup radio
sequence:
- alias: Set Volume
service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.01'
- service: script.play_wakeup_radio
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.05'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.10'
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.15'
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.20'
- delay:
minutes: 2
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.25'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.30'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.35'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.40'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.45'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.50'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.55'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.60'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.65'
- delay:
minutes: 1
- service: media_player.volume_set
data:
entity_id: media_player.googlehome_master_bedroom
volume_level: '0.70'
##############################################################################################################
# Automations
##############################################################################################################
automation:
- alias: Play Radio
hide_entity: True
trigger:
platform: state
entity_id: input_select.radio_station
action:
service: script.play_radio
- alias: Stop radio
hide_entity: True
trigger:
- platform: state
entity_id: binary_sensor.family_home
to: 'off'
for:
minutes: 5
- platform: state
entity_id: input_boolean.stop_radio
to: 'on'
action:
service: script.stop_radio
- alias: 'Set Radio volume'
id: 'Set Radio volume'
trigger:
platform: state
entity_id: input_number.radio_volume
condition: []
action:
service: media_player.volume_set
data_template:
entity_id: >
{{states('sensor.media_player')}}
volume_level: >
{{ states('input_number.radio_volume')|float }}
up next is creating a tiles section for the radio station selection, and of course Lovelace…