Google Cast - Play Media From App (BBC Radio)

I am from the UK and trying to trigger BBC Radio stations playing on a Chromecast Audio from Home Assistant.

BBC Sounds has integration with Chromecast so that when I say to my Google Home “play BBC Radio 1 on Kitchen” it plays it without any extra configuration from me. When I do that I get the following state attributes against the device that I hoped would allow me to recreate the same action in a script:

volume_level: 1
is_volume_muted: false
media_content_id: bbc_radio_one
media_content_type: music
media_position: 1.125607
media_position_updated_at: '2021-05-05T14:57:47.208614+00:00'
media_title: BBC Radio 1
app_id: 03977A48
app_name: BBC Sounds
entity_picture_local: >-
  /api/media_player_proxy/media_player.shower?token=06964956ff9fcfb81360950d777e49fb9d8adcc5ce1fded850e20ea903511a1f&cache=b6acebd86ef09253
friendly_name: Shower
entity_picture: 'https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one/colour_450.png'
supported_features: 152461

The documentation seems to suggest this should be possible following the format of script in the YouTube or Supla examples. I have tried the following but it doesn’t work:

service: media_player.play_media
target:
  entity_id:
    - media_player.kitchen
data:
  media_content_type: cast
  media_content_id: '
          {
            "app_name": "bbc sounds",
            "media_id": "bbc_radio_one"
          }'

Anyone any ideas?

1 Like

I didn’t think an error was being generated, but it looks like it is:

Logger: homeassistant.components.cast.media_player
Source: components/cast/media_player.py:515
Integration: Google Cast (documentation, issues)
First occurred: 9:08:59 (2 occurrences)
Last logged: 9:10:45

App bbc sounds not supported
App BBC Sounds not supported

Not sure if this means it just won’t work, I am doing something wrong, or whether a code change is possible?

There should probably be some cooling off time on posting.

Since finding that error I have looked at the cast code and found the pychromecast repo, which doesn’t have an integration and therefore won’t work.

I will see if I can find time to look into this further.

Great idea, was looking into this, let us know if you find solution please.

Between having a 5 week old and never having used python before this is taking longer than I expected, but I should have a PR in for Sounds and iPlayer fairly soon.

Sorry what do you mean please? I am “python is a dangerous animal” kind of person :smiley:

thanks

PR is a Pull Request.

It’s a request to add code (to expand the functionality we are discussing), at which point the owner will review it, suggest changes or merge it in.

I have also created new topic asking about these apps in general, as there could be more opportunities, like tunein. BBC is a priority though for me as well. Thank you

This has been merged, hopefully should be in next month’s release.

Casting to Sounds / iPlayer functionality has now been released (as of ver 2021.7.0)

2 Likes

This sounds great, can you offer some insight in how to use these feature?

Hi - I’m also keen to know how to use this - does someone have a sample script?

I can speak to Google to play a BBC radio station, and it appears in the HA media player - good. But I want to be able to do this via Home Assistant. I can’t get the code shown in Google Cast - Home Assistant to run.

I currently have buttons on my desk which call scripts to play different BBC Radio stations - but the streams I’m using are going to be switched off in 2023 (e.g. http://stream.live.vc.bbcmedia.co.uk/bbc_6music).

I just tried this locally, still works fine for me, but I am on 2022.7.7 and don’t have any time to update currently.

From the docs I just took the example:

alias: "Cast BBC Sounds to My Chromecast"
sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.CHANGED_THIS
    data:
      media_content_type: cast
      media_content_id: '
        {
          "app_name": "bbcsounds",
          "media_id": "bbc_radio_one",
          "is_live": true
        }'
      extra:
        metadata:
          metadataType: 0
          title: "Radio 1"
          images:
            - url: "https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one/background_1280x720.png"

Created a new script, 3 dots, edit as YAML and pasted it in. Worked.

If that works then you can change the “media_id” to “bbc_6music”, which worked for me too. Metadata image I think I got from casting the station by voice and then taking the URL from the properties of the entity playing it.

Let me know how you get on.

See my previous reply, or the post above that for a link to the docs which has an example for BBC iPlayer and BBC Sounds.

Many thanks for the help, but I’m getting “URL is relative, but does not start with a /”

…which, googling may well be a bug (have tried removing, changing to local path). My script is currently:


alias: TEST Cast BBC Sounds to My Chromecast
sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.mass_all_speakers_3
    data:
      media_content_type: cast
      media_content_id: " { \"app_name\": \"bbcsounds\", \"media_id\": \"bbc_radio_one\", \"is_live\": true }"
      extra:
        metadata:
          metadataType: 0
          title: Radio 1
          images:
            - url: >
                "https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one/background_1280x720.png"
mode: single

I finally updated to the latest version of HomeAssistant and this is all working correctly with metadata supplied.

@DLW try this:

alias: TEST Cast BBC Sounds to My Chromecast
sequence:
  - service: media_player.play_media
    data:
      media_content_type: cast
      media_content_id: >-
        { "app_name": "bbcsounds", "media_id": "bbc_radio_one", "is_live": true
        }
      extra:
        metadata:
          metadataType: 0
          title: Radio 1
          images:
            - url: >-
                https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one/background_1280x720.png
    target:
      entity_id: media_player.mass_all_speakers_3
mode: single

Some subtle differences when I did a comparison of mine to yours, I won’t pretend to know what they mean but I adapted the above from my working version.

Belated thanks for this. It does work, and I’ve tweaked for Radio 4 (see below if you wish). ‘media_id’ can be found by right-clicking on the player when playing in a browser.

alias: TEST Cast BBC Sounds to My Chromecast
sequence:
  - service: media_player.play_media
    data:
      media_content_type: cast
      media_content_id: >-

        { "app_name": "bbcsounds", "media_id": "bbc_radio_fourfm", "is_live":
        true

        }
      extra:
        metadata:
          metadataType: 0
          title: Radio 4
          images:

            - url: "https://ichef.bbci.co.uk/images/ic/1920x1080/p0cbjc9r.jpg"
    target:
      entity_id: media_player.all_speakers_3
mode: single

My scripts to play 6 Music, Radio 4 and Radio 1 stopped working recently. World Service is working ok, which is confusing, and I don’t see any particular differences between the sequences other than the media_id.

BBC World Service (working):

service: media_player.play_media
target:
  entity_id: media_player.kitchen_chromecast_audio
data:
  media_content_id: |-
    { "app_name": "bbcsounds",
      "media_id": "bbc_world_service",
      "is_live": true }
  media_content_type: cast
  extra:
    metadata:
      metadata_type: 0
      title: BBC World Service
      images:
        - url: >-
            https://sounds.files.bbci.co.uk/3.5.0/networks/bbc_world_service/background_1280x720.png
alias: Play World Service on Kitchen Chromecast Audio

6 Music (not working):

service: media_player.play_media
target:
  entity_id: media_player.kitchen_chromecast_audio
data:
  media_content_id: |-
    {  "app_name": "bbcsounds",
       "media_id": "bbc_6music",
       "is_live": true   }
  media_content_type: cast
  extra:
    metadata: null
    metadata_type: 0
    title: BBC 6 Music
    images:
      - url: >-
          https://sounds.files.bbci.co.uk/3.5.0/networks/bbc_6music/background_1280x720.png
alias: Play 6 Music on Kitchen Chromecast Audio

When I trigger the script it changes the Chromecast status to paused, and if I then press play it starts playing the World Service. For BBC 6 Music, the status changes to idle, and it won’t play.

bbc_6music still seems to be the media id if I right click on the player at Radio 6 Music - Listen Live - BBC Sounds

Is anyone else seeing this issue?

Yes, I’m having the same issue with BBC 6music, Radio 1, BBC Radio 2, Radio 4Extra. All seem to follow the same rules as you. The script will begin the cast, the logo / image will appear on the GH screen for around 20-30s and the state will turn from off to idle. But nothing plays and then the image and app seems to close about 30-60s after the script was started.

This started happening ~2-3 weeks back / 2023-09-21T23:00:00Z

The script is pretty much as listed on the Cast documentation page.

play_bbc_6music_new:
  alias: "Cast BBC Sounds to My Chromecast"
  sequence:
    - service: media_player.play_media
      target:
        entity_id: "{{ entity_id | default('media_player.kitchen_speaker') }}"
      data:
        media_content_type: cast
        media_content_id: '
          {
          "app_name": "bbcsounds",
          "media_id": "bbc_radio_one",
          "is_live": true
          }'
        extra:
          metadata:
            metadataType: 0
            title: "Radio 1"
            images:
              - url: "https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one/background_1280x720.png"

Ok - I’m not going crazy :slight_smile:

If I recall correctly this worked a month ago. I’m doing this with a chromecast audio, so I don’t get any feedback apart from the beep if the script powers it on.

I hope the BBC haven’t deliberately broken this.