Chromecast Radio with station and player selection

I had the Chromecast Radio working wonderfully and then I updated to .87 and now it does not work.

Anyone experience this before?

I disabled the volume section of the code and it started working again. Which is fine cause that volume slider never worked

some italian stations:

    media_content_id: >
      {% if is_state("input_select.radio_station", "Rai Radio 1") %} http://icestreaming.rai.it/1.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 2") %} http://icestreaming.rai.it/2.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 3") %} http://icestreaming.rai.it/3.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 4 Light") %} http://icestreaming.rai.it/4.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 5 Classica") %} http://icestreaming.rai.it/5.mp3
      {% elif is_state("input_select.radio_station", "Rai Raido 6 Teca") %} http://icestreaming.rai.it:80/9.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 7 Live") %} http://icestreaming.rai.it:80/10.mp3
      {% elif is_state("input_select.radio_station", "Rai Radio 8 Opera") %} http://icestreaming.rai.it:80/11.mp3
      {% elif is_state("input_select.radio_station", "Rai IsoRadio") %} http://icestreaming.rai.it/6.mp3
      {% elif is_state("input_select.radio_station", "Rai GrParlamento") %} http://icestreaming.rai.it/7.mp3
      {% elif is_state("input_select.radio_station", "RTL") %} http://shoutcast.rtl.it:3010/
      {% elif is_state("input_select.radio_station", "RTL Best") %} http://shoutcast.rtl.it:3020
      {% elif is_state("input_select.radio_station", "RTL ItalianStyle") %} http://shoutcast.rtl.it:3030/
      {% elif is_state("input_select.radio_station", "RTL Groove") %} http://shoutcast.rtl.it:3040/
      {% elif is_state("input_select.radio_station", "RTL Lounge") %} http://shoutcast.rtl.it:3070/
      {% elif is_state("input_select.radio_station", "RTL Radiofreccia") %} http://shoutcast.rtl.it:3060/
      {% elif is_state("input_select.radio_station", "Radio Zeta L'Italiana") %} http://shoutcast.rtl.it:3030/stream/1/
      {% elif is_state("input_select.radio_station", "Radio Kiss Kiss") %} http://ice07.fluidstream.net:8080/KissKiss.mp3
      {% elif is_state("input_select.radio_station", "Radio Kiss Kiss Italia") %} http://wma07.fluidstream.net:3616/;stream.nsv
      {% elif is_state("input_select.radio_station", "Radio Kiss Kiss Napoli") %} http://ice08.fluidstream.net/KKNapoli.aac
      {% elif is_state("input_select.radio_station", "RDS 100% Grandi Successi") %} http://stream1.rds.it:8000/rds64k
      {% elif is_state("input_select.radio_station", "Radio Deejay") %} http://radiodeejay-lh.akamaihd.net/i/RadioDeejay_Live_1@189857/master.m3u8
      {% elif is_state("input_select.radio_station", "R101 Diretta") %} http://icecast.unitedradio.it/r101
      {% elif is_state("input_select.radio_station", "Virgin Radio") %} http://icecast.unitedradio.it/Virgin.mp3
      {% elif is_state("input_select.radio_station", "Radio Capital") %} http://radiocapital-lh.akamaihd.net/i/RadioCapital_Live_1@196312/master.m3u8
      {% elif is_state("input_select.radio_station", "Radio 105") %} http://icecast.105.net/105.mp3
      {% elif is_state("input_select.radio_station", "RMC Radio Monte Carlo") %} http://edge.radiomontecarlo.net/RMC.mp3
      {% elif is_state("input_select.radio_station", "RMC2 Radio Monte Carlo 2") %} http://edge.radiomontecarlo.net/MC2.mp3
      {% elif is_state("input_select.radio_station", "Radio m2o") %} http://radiom2o-lh.akamaihd.net/i/RadioM2o_Live_1@42518/master.m3u8
      {% elif is_state("input_select.radio_station", "Radio 24") %} http://shoutcast.radio24.it:8000/listen.pls
      {% elif is_state("input_select.radio_station", "Radio LatteMiele") %} http://onair18.xdevel.com:8014/
      {% elif is_state("input_select.radio_station", "Radio Marte") %} http://onair18.xdevel.com:8212/
      {% elif is_state("input_select.radio_station", "Radio Ibiza") %} http://wma02.fluidstream.net:5010/
      {% elif is_state("input_select.radio_station", "Discoradio") %} http://46.37.20.206:1935/live/1discoradio.stream/playlist.m3u8
      {% elif is_state("input_select.radio_station", "Radionorba") %} http://onair11.xdevel.com:9990/
      {% elif is_state("input_select.radio_station", "Radionorba Music & Sport") %} http://onair7.xdevel.com:8738/
      {% elif is_state("input_select.radio_station", "Radio Subasio") %} http://onair18.xdevel.com:8152
      {% elif is_state("input_select.radio_station", "Radio Subasio +") %} http://onair11.xdevel.com:8050
      {% elif is_state("input_select.radio_station", "Radio Subasio XL") %} http://onair11.xdevel.com:8052
      {% elif is_state("input_select.radio_station", "Radio Amore Campania") %} http://onair11.xdevel.com:8002
      {% elif is_state("input_select.radio_station", "Radio Cuore") %} http://nr9.newradio.it:9029
      {% elif is_state("input_select.radio_station", "RIN Radio Italia Network") %} http://sr9.inmystream.info:8006
      {% elif is_state("input_select.radio_station", "Radio RCS l’Onda Veronese") %} http://176.31.254.217:8030/
      {% elif is_state("input_select.radio_station", "Ram Power 102.7") %} http://46.37.20.206:1935/live/1ram.stream/playlist.m3u8
      {% elif is_state("input_select.radio_station", "Radio Playstudio") %} http://playstudio.serverroom.us:4140
      {% elif is_state("input_select.radio_station", "LifeGate Radio") %} http://onair11.xdevel.com:8024
      {% elif is_state("input_select.radio_station", "Radio Studio Delta") %} http://5.63.145.172:7203/
      {% elif is_state("input_select.radio_station", "Radio Sportiva") %} http://nr5.newradio.it:8545/stream.mp3
      {% elif is_state("input_select.radio_station", "Studioradio – The Vintage Station") %} http://91.121.38.216:8060/
      {% elif is_state("input_select.radio_station", "Radio Studio Più") %} http://ice.studiopiu.net/rete.aac
      {% elif is_state("input_select.radio_station", "RGS – Radio Grandi Successi") %} http://nrf1.newradio.it:9746/stream?type=http&nocache=8279
      {% elif is_state("input_select.radio_station", "Radio Margherita") %} http://onair20.xdevel.com:8011/
      {% elif is_state("input_select.radio_station", "Radio Margherita Giovane") %} http://onair20.xdevel.com:8018/
      {% elif is_state("input_select.radio_station", "R.L.B.") %} http://nr5.newradio.it:8767/stream.mp3
      {% endif %}
    media_content_type: 'music'
1 Like

Hi lollo78,
Thanks for this list!
I am an Italo-Canadian and love listening to Italian music every once in awhile. When I worked in Italy, I used to listen to RIN because it was the only real station I knew. Unfortunately, it’s hard to keep “up to date” with new music coming out.
I was wondering if you could potentially let me know what the best Italian stations are for the following if possible (excuse my ignorance with some of my “terminology”):

  • Italian Classics (Renato Carosone, Adriano Celentano, Vaso Rossi, etc.)
  • Musica Commerciale (Current Techno/Dance/Electronic Music)
  • Italian Rap (Fabri Fibra, Clementino, Extra points for Napoletano rap)
  • Italian Pop (Current popular music in Italy. Like Francesco Gabbani - Occidentali’s Karma, etc.)
    Grazie Mille!

Guys I messed something up and I’m not sure what it is, I can start and stop the radio stations fine but the volume slider isn’t working anymore. When I change the value nothing happens unless I go to my automation and manually trigger it then it sets the volume as per the slider. Any ideas?

##################    
## Radio Volume ##
##################
- 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", "Loungeroom") %} media_player.loungeroom
        {% elif is_state("input_select.chromecast_radio", "Mancave") %} media_player.man_cave_home
        {% elif is_state("input_select.chromecast_radio", "Kitchen") %} media_player.googlehomehub7267
        {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom_mini
        {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.office_mini
        {% elif is_state("input_select.chromecast_radio", "Main Living Area") %} media_player.main_living_area
        {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.hole_house
        {% endif %}
  volume_level: '{{  states.input_number.volume_radio.state  }}'

I moved some speakers around so had to update the enitity names etc… but they all appear correct now as when I do hole_house they all come on and i’m also able to turn on the individual speakers.

@frankfurts

Looks like your indentations are messed up.
Try like this:

##################    
## Radio Volume ##
##################
- 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", "Loungeroom") %} media_player.loungeroom
        {% elif is_state("input_select.chromecast_radio", "Mancave") %} media_player.man_cave_home
        {% elif is_state("input_select.chromecast_radio", "Kitchen") %} media_player.googlehomehub7267
        {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom_mini
        {% elif is_state("input_select.chromecast_radio", "Office") %} media_player.office_mini
        {% elif is_state("input_select.chromecast_radio", "Main Living Area") %} media_player.main_living_area
        {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.hole_house
        {% endif %}
      volume_level: '{{  states.input_number.volume_radio.state  }}'

Thanks for getting back to me turns out I was editing on my phone and accicdentally deleted the last letter of an entity elsewhere and I crashed my system about 3 times before I found the issue. Once HA was up and running again I forgot that with an issue like that it switches all your automations off. Simply toggled them back on and all good now.

Thanks for this script by the way working a treat :slight_smile:

1 Like

@RevelRob

I was wondering if you could potentially let me know what the best Italian stations are for the following if possible (excuse my ignorance with some of my “terminology”):

http://www.radio-browser.info/gui/#!/bycountry/Italy

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 :wink:

15

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…

8 Likes

looks great! Might steal some code from you! :wink:
I’m only using a script without variables to start a radio on my Google Home. However both radios need between 5-20s to start. I can hear the notification sound for casting immediately, but it needs time to play the music.

Is it the same for you?

cool, that’s why I shared. btw, updated the package to incorporate some alarm clock and lullaby radios. also some miner tweaks. Need to develop the alarmclock scripts, because now they are verbose and silly…

No, whenever I click play, the radio immediately plays. Do notice some delays with tts though when the system is busy.
What bugs me for now is the radio stops playing when a tts is also engaged.

Save the media_player status before playing TTS then restore once TTS play is over…

that sound like a solution, and I would have to do that probably in my generic notification script:

  intercom_message:
    alias: 'Intercom message'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.announce_googlehome', 'on') }}
      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.language')|lower}}
          entity_id: >
            {{states('sensor.googlehome')}}
          message: >
            {{message}}
  intercom_message:
    alias: 'Intercom message'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.announce_googlehome', 'on') }}
      - service: [safe media_player state]
      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.language')|lower}}
          entity_id: >
            {{states('sensor.googlehome')}}
          message: >
            {{message}}
      - service: [restore media_player state]

but how can one save that?

create a few input_text entities and save the data there
Here is an example from a different post a few days ago:

- alias: 'Garage Stream with Motion'
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_motion
    to: 'on'
  condition:
  - condition: state
    entity_id: input_select.house_mode
    state: Home
  action:
# save current TV state
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_source
      value: "{{ state_attr('media_player.tv','source') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_id
      value: "{{ state_attr('media_player.tv','media_content_id') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_type
      value: "{{ state_attr('media_player.tv','media_content_type') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_position
      value: "{{ state_attr('media_player.tv','media_position') }}"
# add more of these as needed based on your setup / what you're watching
  - service: camera.play_stream
    data:
      entity_id: camera.garage_camera
      media_player: media_player.tv
# Wait for end of motion or 30 sec, whichever comes first
  - wait_template: "{{ is_state('binary_sensor.garage_motion', 'off') }}"
    timeout: '00:00:30'
    continue_on_timeout: 'true'
# Restore TV State
  - service: media_player.select_source
    data_template:
      entity_id: media_player.tv
      source: '{{states("input_text.tv_source")}}
  - service: media_player.play_media
    data_template:
      entity_id: media_player.tv
      media_content_id: '{{states("input_text.tv_media_content_id")}}
      media_content_type: '{{states("input_text.tv_media_content_type")}}'
  - service: media_player.media_seek
    data_template:
      entity_id: media_player.tv
      seek_position: '{{states("input_text.media_position")}}
1 Like

A yes, I see. Thanks, that’s really robust and big.

Let me try to see if that would be of use in my setup. would only need it if a had turned on the radio before =, using one of my scripts posted above. In which case I could simply check for that and rerun the script again…I think.

Anyone can give me a hand on using youtube links instead of radio links?
I gave it a try using media_extractor, but no result so far

@lolouk44
fwiw, had a bit of a struggle, since I use templates for my players, which only tell me which player is selected, and don’t pass on the attributes ‘playing’, but think I made it solar using this:

  intercom_message:
    alias: 'Intercom message'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.announce_intercom', 'on') }}
      - service: script.radio_paused_for_message #check see below
      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.language')|lower}}
          entity_id: >
            {{states('sensor.intercom')}}
          message: >
            {{message}}
       - condition: template
         value_template: >
           {{is_state('input_boolean.radio_paused','on')}}
# radio was paused, so return to playing
       - service: script.play_radio #contains stream, volume, player
# and return the boolean to Off again
       - service: input_boolean.turn_off
         entity_id: input_boolean.radio_paused

# when a message comes in check if the intercom is identical to the current radio player, and if that is on
  radio_paused_for_message:
    alias: 'Radio paused for message'
    sequence:
      - condition: template
        value_template: >
          {{states('sensor.intercom') == states('sensor.media_player')}}
      - condition: template
        value_template: >
          {% set player = states('sensor.media_player') %}
          {% if player == 'media_player.googlehome_woonkamer'%} {{is_state('media_player.googlehome_woonkamer','playing')}}
          {% elif player == 'media_player.googlehome_hobbykamer' %} {{is_state('media_player.googlehome_hobbykamer','playing')}}
          {% elif player == 'media_player.googlehome_hall' %} {{is_state('media_player.googlehome_hall','playing')}}
          {% elif player == 'media_player.googlehome_master_bedroom' %} {{is_state('media_player.googlehome_master_bedroom','playing')}}
          {% else %} {{is_state('media_player.chromecastaudio_gym','playing')}}
          {% endif %}
      - service: input_boolean.turn_on
        entity_id: input_boolean.radio_paused

works alright, need to think about a delay though since the radio starts playing already before the message has been intercommed…fear I need another of these large template as wait_template to check for intercom = ‘playing’ to be precise and not gamble.

      - wait_template: >
          {% set player = states('sensor.intercom') %}
          {% if player == 'media_player.googlehome_woonkamer'%} {{is_state('media_player.googlehome_woonkamer','off')}}
          {% elif player == 'media_player.googlehome_hobbykamer' %} {{is_state('media_player.googlehome_hobbykamer','off')}}
          {% elif player == 'media_player.googlehome_hall' %} {{is_state('media_player.googlehome_hall','off')}}
          {% elif player == 'media_player.googlehome_master_bedroom' %} {{is_state('media_player.googlehome_master_bedroom','off')}}
          {% else %} {{is_state('media_player.chromecastaudio_gym','off')}}
          {% endif %}

should be fairly straight forward, just add a wait_template:

- wait_template: "{{ states('media_player.googlehome_woonkamer') != 'playing' }}"
  timeout: '00:00:15'
  continue_on_timeout: 'true'

Only thing I’ve not tried yet if to see if you can use a sensor’s state to parse the media_player entity, like, but can’t see why it would not work:

- wait_template: "{{ states(sensor.media_player) != 'playing' }}"
  timeout: '00:00:15'
  continue_on_timeout: 'true'

No that was my first try, but the template only shows the entity_id of the media_player, and can’t read attributes:

I had already added the wait_template, but that needs to be as big as it is, because of the above:

  intercom_message:
    alias: 'Intercom message'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.announce_intercom', 'on') }}
      - service: script.radio_paused_for_message
      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.language')|lower}}
          entity_id: >
            {{states('sensor.intercom')}}
          message: >
            {{message}}
      - condition: template
        value_template: >
          {{is_state('input_boolean.radio_paused','on')}}
      - wait_template: >
          {% set intercom = states('sensor.intercom') %}
          {% if intercom == 'media_player.googlehome_woonkamer'%} {{is_state('media_player.googlehome_woonkamer','off')}}
          {% elif intercom == 'media_player.googlehome_hobbykamer' %} {{is_state('media_player.googlehome_hobbykamer','off')}}
          {% elif intercom == 'media_player.googlehome_hall' %} {{is_state('media_player.googlehome_hall','off')}}
          {% elif intercom == 'media_player.googlehome_master_bedroom' %} {{is_state('media_player.googlehome_master_bedroom','off')}}
          {% else %} {{is_state('media_player.chromecastaudio_gym','off')}}
          {% endif %}
      - service: script.play_radio
      - service: input_boolean.turn_off
        entity_id: input_boolean.radio_paused

thanks!

ave you tried {{ states(sensor.media_player) != 'playing' }} without quotes around sensor.media_player?
Or {{ states(states.sensor.media_player.state) != 'playing' }} assuming returns a value like media_player.player_name ?

EDIT
{{ states(states.sensor.media_player.state) != 'playing' }} should work.

Here are the results of my test:

EDIT2:
or this {{states(states("sensor.media_player"))}} which is better

yess! works! great. Never new that… encapsulated states… learn something every day!
thank you very much indeed.

much shorter…:wink:

  intercom_message:
    alias: 'Intercom message'
    sequence:
      - condition: template
        value_template: >
          {{ is_state('input_boolean.announce_intercom', 'on') }}
      - service: script.radio_paused_for_message
      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.language')|lower}}
          entity_id: >
            {{states('sensor.intercom')}}
          message: >
            {{message}}
      - condition: template
        value_template: >
          {{is_state('input_boolean.radio_paused','on')}}
      - wait_template: >
          {{states(states('sensor.intercom')) == 'idle'}}
      - service: script.play_radio
      - service: input_boolean.turn_off
        entity_id: input_boolean.radio_paused

  radio_paused_for_message:
    alias: 'Radio paused for message'
    sequence:
      - condition: template
        value_template: >
          {{states('sensor.intercom') == states('sensor.media_player')}}
      - condition: template
        value_template: >
          {{states(states('sensor.media_player')) == 'playing'}}
      - service: input_boolean.turn_on
        entity_id: input_boolean.radio_paused

needed a small edit:

 - wait_template: >
     {{states(states('sensor.intercom')) == 'idle'}}
1 Like