Chromecast Radio with station and player selection

Not sure about VLC, but I know MPD (Mopidy) works fine with the same commands.

Is there a way to replace the Activate text button with an icon instead?

I don’t think so. Would be a nice feature though to be able to change the text or replace with an icon.

Hi folks!

Big props to Bob to kicking this off… brilliant!

I’ve incorporated it into my system - I have a few local Australian stations and some 80’s throwbacks. It’s great! I have it streaming to 4 chromecasts and a Google Home - and also as a group for whole house vacuuming background music.

I was wondering if I could set the entity_picture to an image that represents the station being piped?

I was thinking that I could just these last three lines:

alias: Play Radio on Chromecast Audio
sequence:
  -  service: media_player.play_media
     data_template:
       entity_id: >
        {% if is_state("input_select.chromecast_radio", "Kitchen") %} media_player.kitchen_chromecast
        {% elif is_state("input_select.chromecast_radio", "Google Home") %} media_player.kitchen_home
        {% elif is_state("input_select.chromecast_radio", "Theater") %} media_player.home_theater_chromecasta
        {% elif is_state("input_select.chromecast_radio", "Man cave") %} media_player.man_cave_chromecast_a
        {% elif is_state("input_select.chromecast_radio", "Whole house") %} media_player.whole_house
        {% endif %}
       media_content_id: >
        {% if is_state("input_select.radio_station", "TripleJ") %} http://radio1.internode.on.net:8000/117
        {% elif is_state("input_select.radio_station", "DoubleJ") %} http://radio1.internode.on.net:8000/132
        {% elif is_state("input_select.radio_station", "TripleJ Unearthed") %} http://radio1.internode.on.net:8000/183
        {% elif is_state("input_select.radio_station", "Best of the 80's") %} http://radio1.internode.on.net:8000/42
        {% elif is_state("input_select.radio_station", "Industrial") %} http://radio1.internode.on.net:8000/47
        {% elif is_state("input_select.radio_station", "TripleR") %} http://public-radio1.internode.on.net:8002/114
        {% elif is_state("input_select.radio_station", "Soma Underground 80's") %} http://radio1.internode.on.net:8000/20
        {% endif %}
       media_content_type: 'audio/mp3'
       entity_picture: >
        {% if is_state("input_select.radio_station", "TripleJ") %} http://assets.cdn.iinet.net.au//assets/freezone/radio/radio-triplej-icon.jpg
        {% endif %}

I’ll find a better image than that - but I got stuck. I got this error:

17-03-18 20:22:55 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.play_media: extra keys not allowed @ data['entity_picture']. Got 'http://assets.cdn.iinet.net.au//assets/freezone/radio/radio-triplej-icon.jpg'

Any pointers anyone?

1 Like

@brendanheyu glad you like it.

Great idea!

I think it’s not possible in the play_media part but I guess it can work as script entity picture. Will try right away :slight_smile:

^^^^^^
And that is why this community rocks!

1 Like

After rethinking this it’s a little more complicated than I thought. The script icon is configured in the customize section. I’m not sure if templating is possible there (which is neccessary, right?)

well, I was thinking you could somehow set the entity values…

My wife is playing Depeeche Mode in the kitchen via google music:

friendly_name: Kitchen Chromecast
volume_level: 0.8500000238418579
app_name: Google Play Music
media_content_type: music
media_artist: Depeche Mode
media_position: 0.43924600000002173
media_content_id: https://mclients.googleapis.com/music/mplay?mjck=Tfa2hobjzaoa6gzpleunkxo7ktu&pt=a&dv=1&slt=1489830526869&sig=O39tqQ9NPrQ-LiPSPGfU24E7QTk_
media_title: Blue Dress (Remastered)
media_position_updated_at: 2017-03-18T09:48:47.101252+00:00
is_volume_muted: false
app_id: 2872939A
supported_features: 21437
entity_picture: /api/media_player_proxy/media_player.kitchen_chromecast?token=c26f183b4abb458bdaff364ff4aa67f374cdca711b965bb33285dabb7378482c&cache=4ecb4
media_album_artist: Depeche Mode
media_duration: 338

I figured seeing we were already changing the media_content_id that we could somehow use the same trick?

1 Like

I tried this:

  customize:
   script.radio538:
    friendly_name: Start Playing
    icon_template: >
            {% if is_state("input_select.radio_station", "Radio 538") %} /local/radio538.png
            {% elif is_state("input_select.radio_station", "Q-Music") %} /local/qmusic.jpg
            {% else %} mdi:play
            {% endif %}

No luck unfortunately, also no errors in my log file. Will try some more.

EDIT: We are basicaly trying the same thing, except you’re trying to change the device picture and I’m trying to change the script icon. I think configuration should be similair (in the customize section).

@brendanheyu I’m not sure if it’s even possible and I could not find a related topic for this challenge so I created a new topic:
https://community.home-assistant.io/t/templating-icons-in-customize-section/13993?u=bob_nl

Thanks mate, fingers crossed…

Whats the easiest way to add a Stop button? I tried adapting the pauze script above and switched media_player.media_pauze for media_player.media_stop (and media_player.stop_media) but it won’t work?

radio539:
  alias: Stop radio
  sequence:
    -  service: media_player.stop_media
       data_template:
         entity_id: >
          {% if is_state("input_select.chromecast_radio", "Kitchen") %} media_player.kitchen
          {% elif is_state("input_select.chromecast_radio", "Livingroom") %} media_player.livingroom
          {% elif is_state("input_select.chromecast_radio", "Group") %} media_player.group
          {% endif %}

@bonterra

media_player.media_stop 

should work.

You can allways turn off your player, this definitely works:

media_player.turn_off

Finally got time to implement this and it works great. Right now I am just using the stations you provided but I hope to get some more of my own in there.

For anyone looking, this is a great source: https://www.internet-radio.com/

Thanks, @Bob_NL for a wonderful addition! I need to go out now and get a few more CC audios!

2 Likes

I’ve tried adding a couple of stations from internet-radio.com but can’t get any of them to play. My guess is that they may be of a different media_content_type.

So I have two questions:

  1. How do you determine the media content type from the URL? The stations don’t seem to indicate the type:

    http://us1.internet-radio.com:8105/
    http://us3.internet-radio.com:8007/

    http://192.240.102.198:14373/listen.pls?sid=1

  2. If you have different media content types, do you have to create separate scripts for them or can you mix different types by simply blocking the types together in the script? How would you do this?

EDIT: OK, I have found out what types these are at least from just putting the URL in a browser:

http://us1.internet-radio.com:8105/ - audio/mpeg
http://us3.internet-radio.com:8007/ - appears to be MP3

http://192.240.102.198:14373/listen.pls?sid=1 - playlist

@rpitera This works:

http://us3.internet-radio.com:8007/listen.mp3

And here is your Classic Rock Florida link: :slight_smile:

http://listen.shoutcast.com/Classic-RockFlorida

Nice stations btw, I added them to my radio (Y)

1 Like

Small update: volume slider settings now also effect the start of the stream instead of pre-defined volume settings.
Also I added some streams.

script:

  radio538:
    alias: Play Radio on Chromecast Audio
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.ca_livingroom
            {% elif is_state("input_select.chromecast_radio", "Hall") %} media_player.ca_hall
            {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bed_room
            {% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.ca_bathroom
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
            {% endif %}
          volume_level: '{{  states.input_slider.volume_radio.state  }}' 
      -  service: media_player.play_media
         data_template:
           entity_id: >
            {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.ca_livingroom
            {% elif is_state("input_select.chromecast_radio", "Hall") %} media_player.ca_hall
            {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bed_room
            {% elif is_state("input_select.chromecast_radio", "Bathroom") %} media_player.ca_bathroom
            {% elif is_state("input_select.chromecast_radio", "Everywhere") %} media_player.home_group
            {% endif %}
           media_content_id: >
            {% if is_state("input_select.radio_station", "Radio 538") %} http://vip-icecast.538.lw.triple-it.nl:80/RADIO538_MP3
            {% elif is_state("input_select.radio_station", "Q-Music") %} http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3
            {% elif is_state("input_select.radio_station", "3FM") %} http://icecast.omroep.nl/3fm-bb-mp3
            {% elif is_state("input_select.radio_station", "100% NL") %} http://stream.100p.nl/100pctnl.mp3
            {% elif is_state("input_select.radio_station", "Veronica") %} http://8543.live.streamtheworld.com/VERONICACMP3
            {% elif is_state("input_select.radio_station", "Sky Radio") %} http://8623.live.streamtheworld.com:80/SKYRADIOAAC_SC
            {% elif is_state("input_select.radio_station", "Arrow Classic Rock") %} http://91.221.151.155/listen.mp3
            {% elif is_state("input_select.radio_station", "Classic FM") %} http://19143.live.streamtheworld.com/CLASSICFM_SC
            {% elif is_state("input_select.radio_station", "BNR Nieuwsradio") %} http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_96_03
            {% elif is_state("input_select.radio_station", "Smooth Jazz Tampa") %} http://us3.internet-radio.com:8007/listen.mp3           
            {% elif is_state("input_select.radio_station", "Classic Rock Florida") %} http://listen.shoutcast.com/Classic-RockFlorida
            {% elif is_state("input_select.radio_station", "Bob Sinclar Radio") %} http://listen.shoutcast.com/prysmradio09-mp3            
            {% elif is_state("input_select.radio_station", "Chill Out Zone") %} http://air.chillout.zone:8000/radio           
            {% elif is_state("input_select.radio_station", "SLAM! Hardstyle") %} http://stream.radiocorp.nl/web11_mp3
            {% elif is_state("input_select.radio_station", "Sleep Radio") %} http://37.59.28.208:8722/stream
            {% elif is_state("input_select.radio_station", "Ambient Sleeping Pill") %} http://perseus.shoutca.st:8447/h
            {% elif is_state("input_select.radio_station", "Radio Art - Sleep") %} http://live.radioart.com/fSleep.mp3
            {% elif is_state("input_select.radio_station", "Ambi Nature Radio") %} http://94.23.252.14:8067/stream
            {% elif is_state("input_select.radio_station", "Calm Radio - Sleep") %} http://streams.calmradio.com/api/39/128/stream
            {% elif is_state("input_select.radio_station", "Dinamo.FM Sleep") %} http://channels.dinamo.fm/sleep-aac
            {% endif %}
           media_content_type: 'audio/mp4'    

Jep, scripname is still “radio538” because I started this project with only one radio station :wink:
P.S. All the sleepy stations are part of my “Wakeup alarm with radio and Lullaby on bedtime” project.

5 Likes

How do you create a Group with a Chromecast (not audio)?

You can’t add the old Chromecasts to a group. You can select multiple speakers as players like this:

entity_id: media_player.home_group, media_player.bed_room

Chances are they will be out of sync though.

So you use all chromecast audio for your Everywhere?