Play Youtube video on Chromecast with script/service

I want to auto play Youtube video/playlist on Chromecast but not found any way. I search about https://home-assistant.io/components/media_extractor/ but it say service not exist, media_player.play_media will not too: Googlecast/Chromecast Play Youtube TV App/Channel

1 Like

See here :

1 Like

It show error:

Unable to find service media_extractor/play_media

I use hassio 0.64.3

you will need the add below to config

# Example configuration.yaml entry
media_extractor:
1 Like

Thank you. My fault with quick reading.

1 Like

Thnx jivesinger, but it doesn’t work with https://youtu.be/tPE4wv7ob8Q. Do you know why?

Would media_extractor work with Youtube Music urls. I’m new to this and would like to trigger a relaxation music playlist upon tv turning off, I’m already hooked to a webos tv but need some clues as to how to cast the playlist.

– edited to include answer –

Thank you so much I got this to work with youtube music casting to Google home mini
{
“entity_id”: “media_player.master_bedroom_speaker”,
“media_content_id”: “https://music.youtube.com/watch?v=vCQTiI_ESl0&list=RDAMVMvCQTiI_ESl0”,
“media_content_type”: “audio/youtube”
}

I believe this might also work without advertising since I have a subscription too. Don’t know how it might apply to others.

@3dgr, will this play the entire playlist without pause?

@goprojojo Yes, I believe it would play the entire playlist. I need to redo my setup so I can’t confirm now.

Sounds promising. I also tried to play a YouTube video playlist (https://music.youtube.com/playlist?list=PLMC9KNkIncKtsacKpgMb0CVq43W80FKvo ) on my Chromecast TV but it plays only the first video. Don’t know if it’s possible what I want. Any suggestions?

@goprojojo Did you try https://music.youtube.com/watch?v=vCQTiI_ESl0&list=PLMC9KNkIncKtsacKpgMb0CVq43W80FKvo to see if it would start directly ?

It starts directly but the playlist stops after the first track. Below my automation.yaml.
Any suggestions?

- alias: 'TEST'
  trigger:
    platform: state
    entity_id: binary_sensor.test
    to: 'on'
  action:
    - service: media_extractor.play_media
      entity_id:
      - media_player.tv_bedroom
      data:
        media_content_id: https://music.youtube.com/watch?v=vCQTiI_ESl0&list=PLMC9KNkIncKtsacKpgMb0CVq43W80FKvo
        media_content_type: video/youtube

Just tried this as well. The reason why it is probably not working, that the media extractor does not support it. This is the warning:

Playlists are not supported, looking for the first video
1:35 PM components/media_extractor.py (WARNING)

So is there another way to play Youtube video playlist (with or without media_extractor)?

1 Like

Nah, I ended up using this mess of a workaround to play youtube vids in a sequence, waiting for each to finish playing on the media player.

scripts.yaml

happy_hunter:
  alias: Happy Hunter
  sequence:
  - condition: state
    entity_id: media_player.upstairs_display
    state: 'off'
  - data:
      entity_id: media_player.upstairs_display
      media_content_id: https://www.youtube.com/watch?v=xyz1
      media_content_type: video/youtube
    service: media_extractor.play_media
  - delay: 00:00:30
  - timeout: 00:06:00
    wait_template: '{{ is_state(''media_player.upstairs_display'', ''idle'') }}'
  - data:
      entity_id: media_player.upstairs_display
      media_content_id: https://www.youtube.com/watch?v=xyz2
      media_content_type: video/youtube
    service: media_extractor.play_media
1 Like

Is there a better way to play a youtube playlist in 2021?

4 Likes

Or could there be in 2023

Or maybe 2024?

Or just stay in 2017 :wink: GitHub - skorokithakis/catt: Cast All The Things allows you to send videos from many, many online sources to your Chromecast.
With this tools you can cast YouTube playlist url.