Chromecast Radio with station and player selection

No problem :+1:

yeey it work thanks for the help :slight_smile:

maby something interesting… dutch radio streams
https://hendrikjansen.nl/henk/streaming.html#AS

4 Likes

Hi

Willing to share your code for this?
I love your conditional card-spotify picker and swipe card with the blurred background (browser mod)
The only thing i question left is, how do i integrate my sonos speakers with it (have sonos and google homes) . And can i browse spotify too?

Works really nice, is there a way to force the “title” of the radio station so that it shows what station is playing on the media player card?

Hi, the code is already posted here. It’s the same base code as the first post of this thread, but changed the script part to work with spotcast instead of radio stream: Chromecast Radio with station and player selection

And I added my own media player card design to the vertical stack: Fully loaded media player card (picture-elements project) Here is the part how to have conditional cards: Chromecast Radio with station and player selection If you wrap all cards inside a swiper card, you’re set with that part.

So you can re-create this by following the steps of the first step and use the codes I provided. I don’t use Sonos, so I can’t say what will or will not work.

sidenote: in this case I used stack-in-card instead of vertical-stack card. That one can disable margin etc, which gives the look that the separate cards are one.

Cool will try, the hard part is sonos, dont know how to do that

I tried…
Some questions though…
I’m not sure the script works…
I click the cast the radio (and/or cast spotify) and then somethings starts playing but i get the idea its not 100% what i ask to do…
Is there a way i can check whats playing?
I dont see a cover either, the google hub is showing : default media receiver
and not the radio channel cover or not the spotify playlist cover…

Radio doesn’t show artwork because it’s a simple mp3 stream that you cast to Chromecast. It can’t show artwork because it’s not there to begin with. There is no metadata with the stream url.

I use spotcast to cast Spotify playlists I predefined using the matching URI link, which does send metadata and show artwork and media info. Which is why it shows. If you don’t have artwork with Spotify and you use spotcast, then some of your code isn’t correct.

If it plays something else than you want, then most likely your script is not correct. If you switch URI codes then a different playlist wil play then you think.

This isn’t something I can really help you with, because all code is available and I have no idea what issues you’re having and what you expect it to do. If you explain that and post all your codes, maybe I can try and help, but that’s hard to say.

Many thanks for this approach. I have been using this for years, but it no longer works with HA versions after 0.115. Is anyone else having issues?
Problem Solved: Somehow my formatting of the script was jumbled up but still passed the configuration check. I cleaned up the formatting to how I remember I originally created it and the script is now working on 0.117.6.
See https://github.com/home-assistant/core/issues/40466

Your issue has to do with mdp if I read your ticket. So it has nothing to do with the script itself. I think your issue will be solved faster if you post your problems in threads about mdp player.

Ok heres the code.
Input select

radio_station:
  name: 'Kies Radio Station:'
  options:
    - Studio Brussel
    - Q-Music
    - MNM
    - Radio 2
    - Klara
    - Ketnet Radio
  icon: mdi:radio    
spotify_afspeellijst:
  name: 'Kies afspeellijst:'
  options:
    - Top 50 België
    - The Greatest Switch
  icon: mdi:spotify  
chromecast_speakers:
  name: 'Kies Luidspreker:'
  options:
    - Keuken
    - Slaapkamer Ouders
    - Slaapkamer X
    - Slaapkamer Y
    - Overal
  initial: Keuken
  icon: mdi:speaker-wireless   

Script

radio:
  alias: Activeer radio
  sequence:
    - service: media_player.volume_set
      data:
        entity_id: group.cast_player
        volume_level: '0.35'
    -  service: media_player.play_media
       data_template:
         entity_id: >
          {% if is_state("input_select.chromecast_speakers", "Keuken") %} media_player.keuken
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer Ouders") %} media_player.slaapkamer
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer X") %} media_player.slaapkamer_X
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer Y") %} media_player.slaapkamer_Y
          {% elif is_state("input_select.chromecast_speakers", "Overal") %} group.cast_player
          {% endif %}
         media_content_id: >
          {% if is_state("input_select.radio_station", "Studio Brussel") %} http://icecast.vrtcdn.be/stubru-high.mp3
          {% elif is_state("input_select.radio_station", "Q-Music") %} http://icecast-qmusic.cdp.triple-it.nl/Qmusic_be_live_64.aac
          {% elif is_state("input_select.radio_station", "MNM") %} http://icecast.vrtcdn.be/mnm_hits-high.mp3
          {% elif is_state("input_select.radio_station", "Radio 2") %} http://icecast.vrtcdn.be/ra2wvl-high.mp3
          {% elif is_state("input_select.radio_station", "Klara") %} http://icecast.vrtcdn.be/klara-high.mp3
          {% elif is_state("input_select.radio_station", "Ketnet Radio") %} http://icecast.vrtcdn.be/ketnetradio-high.mp3
          {% endif %}
         media_content_type: 'audio/mp4'
spotify:
  alias: Activeer Spotify
  sequence:
    -  service: spotcast.start
       data_template:
         entity_id: >
          {% if is_state("input_select.chromecast_speakers", "Keuken") %} media_player.keuken
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer Ouders") %} media_player.slaapkamer
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer X") %} media_player.slaapkamer_X
          {% elif is_state("input_select.chromecast_speakers", "Slaapkamer Y") %} media_player.slaapkamer_Y
          {% elif is_state("input_select.chromecast_speakers", "Overal") %} group.cast_player
          {% endif %}
         uri: >
          {% if is_state("input_select.spotify_playlist", "Top 50 België") %} spotify:playlist:37i9dQZEVXbJNSeeHswcKB
          {% elif is_state("input_select.spotify_playlist", "The Greatest Switch") %} spotify:playlist:3dMgR1GWfuSLJeUUvUTZXV
          {% endif %}
         random_song: 'true'     
         shuffle: 'true'         

Group

cast_player:
  name: Chromecast_player
  entities:
    - media_player.keuken
    - media_player.slaapkamer
    - media_player.slaapkamer_Y
    - media_player.slaapkamer_X

Then the UI

type: custom:vertical-stack-in-card
    title: Luidprekers
    cards:
      - type: entities
        entities:
          - input_select.radio_station
          - input_select.spotify_afspeellijst
          - input_select.chromecast_speakers
      - type: horizontal-stack
        cards:
          - type: custom:button-card
            show_icon: false
            show_label: true
            tap_action:
              action: call-service
              service: script.radio
          - type: custom:button-card
            show_icon: false
            show_label: true
            tap_action:
              action: call-service
              service: script.spotify
      - type: custom:swipe-card
        parameters:
          spaceBetween: 1
        cards:
          - type: conditional
            conditions:
              - entity: media_player.keuken
                state_not: on
            card:
              type: custom:mini-media-player
              entity: media_player.keuken
              artwork: cover
          - type: conditional
            conditions:
              - entity: media_player.slaapkamer
                state_not: on
            card:
              type: custom:mini-media-player
              entity: media_player.slaapkamer
              artwork: cover

You say with radio its normal i dont get art, is it a possibility to use tunein then for radio instead of urls?

1 Like

Regarding radio: there is no TuneIn integration in Home Assistant. And there is no way to cast TuneIn to Chromecast, unless someone creates that component (just like spotcast).

Regarding Spotify:

I still don’t know what your issue is… like I explained, I want to help and you can post code but you still haven’t explained that the issue is. You said:

I click the cast the radio (and/or cast spotify) and then somethings starts playing but i get the idea its not 100% what i ask to do…

I have no idea what it is you ask it to do (or you think you’re doing) and what is does then. So what is the issue?

See my code up

The problem is:

  • radio gets no cover but you explained so thats “ok”
    It takes long too to start playing the mp3 , is that normal?
  • spotify problem: he doenst play my playlist, yesterday i started a playlist… and stopped it, i just tried to start playing the top 50 but the hub shows the playlist from yesterday and doesnt play anything so it doesnt start correct playlist…
  • It takes long too to start playing the mp3 , is that normal?

This depeneds on the stream. Some work instantly, other might take longer to buffer. This is handled by the core Chromecast integration in the end. So if you think it’s a bug, you can create a ticket at HA github → Issues · home-assistant/core · GitHub

  • spotify problem: he doenst play my playlist, yesterday i started a playlist… and stopped it, i just tried to start playing the top 50 but the hub shows the playlist from yesterday and doesnt play anything so it doesnt start correct playlist…

Then your code is not right in the script and/or input_select. All the script does is execute the spotcast service and use the speaker and playlist combination you wrote under input_select and the script.

One thing I do notice, is that you also have group.cast_player as one of he speaker options. I don’t know if that’s supported by spotcast. I created Chromecast group speakers within Google Home app, and then used that as a media_player entity, not group. For example, I have media_player.sony_cast, media_player.badkamer_cast and media_player.multispeakers_cast. The Multispeaker mediaplayer consists of Sony and Badkamer, but that’s handled by Google Home. I don’t group them using Home Assistant.

I can’t really help you with this myself. I just edited the code that this thread provided and used my own Spotify playlist URI’s. And created the UI card and mixed stuff to create something for myself.

If you’re having issues with the spotcast service call, I advise you to ask in that thread - > Spotcast - custom component to start playback on an idle chromecast device

So if you’re issue is: it plays, but not the playlist I asked it to play. Then you need to check your Spotify URI’s and make sure the input_select is correct. I advise to first test the playlist URI codes and make sure it’s the correct one. Use developer tools for that to execture service calls. If it fails you can pinpoint what the issue is, by trying a different Chromecast media player and URI playlist. If still fails, mention it over at the spotcast thread if it’s related to spotcast.

hey ok good tips
thx for the help mate

1 Like

Can you tell me how to check the spotify url using the developer tools to excute the service call?
Thx

Just paste the code inside the service tab. This is located -> https://ur-of-your-ha:8123/developer-tools/service. There just use the service_data (or paste below code in there) and press the button to call the service.

entity_id: media_player.keuken
uri: spotify:playlist:37i9dQZEVXbJNSeeHswcKB

Change the entity_id and uri based on the one you want to test and use different Spotify uri’s to see if it’s the correct one. If you have any errors or if the issue is with spotcast, make sure to visit that thread I linked above so people can help you.

i keep trying but it says : cannot call service, extra keys not allowed

service: media_player.play_media
entity: media_player.keuken
uri: spotify:playlist:37i9dQZEVXbJNSeeHswcKB

That’s because you’re not using the correct service. It’s not play_media service call, but spotcast.start.

You do have spotcast installed right? Please read spotcast documents so you understand how it works.