Is it Possible to stream youtube video play list to Google Chromecast Audio?

#-------------------------------------------
# Music from youtube playlist sent to Google Chromecast Audio
# 
#-------------------------------------------
homeassistant:
  customize:
    input_boolean.music:
      friendly_name: 'Music'
      icon: mdi:music      
      hidden: False
#-------------------------------------------
input_boolean:
  music:
    name:  Music
    initial: off

#-------------------------------------------

automation:
  - alias: 'Turn on Music'
    trigger:
      - platform: state
        entity_id: input_boolean.music
        to: 'on'

    action:
#     - service: media_player.turn_on
#       entity_id: media_player.chrome1
       
     - service: media_extractor.play_media
       data_template:
        entity_id: media_player.chrome1
 
        media_content_id: "https://play_List_URL"
        media_content_type: "video/mp4"

  - alias: 'Turn off Music'
    trigger:
      - platform: state
        entity_id:
          - input_boolean.music
        to: 'off'

    action:
      - service: media_extractor.media_stop
        entity_id: media_player.chrome1
        
      - service: media_player.turn_on
        entity_id: media_player.chrome1

I am not a programer , just learing from great examples here on this site .

If it is, I haven’t been able to figure it out either. I ended up implementing the radio station that someone posted as a shared project.

The ability to play a random song off a youtube playlist to a chrome cast would super simplify things.

Hi

Are you able to get the playlist URL? Below is an example with a single video sent to CCA but for playlists should work the same way.

test:
  sequence:
    - service: media_extractor.play_media
      entity_id: media_player.home
      data_template:
        media_content_id: "https://www.youtube.com/watch?v=wzjWIxXBs_s"
        media_content_type: "audio/youtube"
1 Like

Just in case anyone cares for Alexa, I use this one which works and I haven’t been charged anything.

https://github.com/Fenton-Fenton-Fenton/alexa-tube

this code plays only first video from the playlist. It does take good 5 min for media to start playing some how.

Unfortunately :frowning: it is a limitation of the Media Extractor platform.

As an alternative you could try sending Google Music playlists to HA (this one works :slight_smile: )

or finding really long Youtube videos with Media Extractor.

PS: the time it takes for the Youtube video to start depends on the internet connection.

Thanks but my idea was to go to youtube add some music videos to youtube playlist then play that list using HA automation . Like this

  • Hey Google , Play my music >>> IFTTT>> HOME ASSISTANT>>media_player.chrome>> all speakers in the house.
    One can only wish lol.

Not really.

I think that the link I mentioned already does it (you can start either a playlist already saved or a radio based on a playlist in Google Music) so it is only a mater of time someone with the appropriate skills manages to do it with Youtube (if not already done).

Thank you very much but your link is great for people who what to setup Google music . I am interested in youtube. I searched all over the net and could not find code for youtube. I do hope somebody with appropriate skills will make one for youtube.

It would be nice to play a livestream or playlist from Youtube. Any progress on this?

Also looking for this, have not found a solution!

I imagine the easiest way of doing this would be to automate the Chrome Browser somehow and output your audio to the chromecast

I am not a programmer to achieve that.

I am able to play videos this way. Any idea how can I share the link directly from my phone using some kid of sharing service?

I don’t understand why not playing directly from YT Music app on the phone to Chromecast Audio.

Cause I want to play in other devices. Like panel tablets. Moreover I do not own a chromecast device.

My guess initially was that you wanted to send the link to Youtube video from mobile device to HA, but it would have been easier to just use the mobile device to cast to Chromecast devices.

I think that browser mod might be what you are looking for in order to be able to play on the browser running HA on tablet/pc.

Yeah you are right. I am using it and it is working fine.

I would like now to speed up the link sharing between youtube on mobile (for example) to HA so i can easilly call the service which plays youtube audio on the browser mod

Hi.

Is it possible to play a youtube playlist?

Thanks
Mike

1 Like

I have this worknig with a script, that calls the media_player service like this:

alias: Play on chromecast
sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.tv_tv
    data:
      media_content_id: >-
        {% set msg
        ={'app_name':'youtube','media_id':'dQw4w9WgXcQ'}%}{{
        msg|to_json }}
      media_content_type: cast
mode: single
icon: mdi:youtube

changing the ‘media_id’ to ‘playlist_id’, as mentioned here, would let you play a playlist instead.
also adding:

,'enqueue':'true'

in there would let you enque a video, or a playlist.
i have a short explanation, with examples here.