How to play Youtube livestream on Chromecast with media_extractor?

I cannot seem to play a Youtube livestream (e.g. https://youtu.be/tPE4wv7ob8Q) on Chromecast using the media_extractor.play_media component.
When I replace the url with a regular Youtube video HA does play without any issues.

Is my media_content_type incorrect maybe? Any help appriciated.

My configuration.yaml:

media_extractor:

My automation.yaml:

  alias: Test
  trigger:
  - entity_id: binary_sensor.switch_158d00020f1bba
    platform: state
    to: 'on'
  action:
  - data:
      media_content_id: https://youtu.be/tPE4wv7ob8Q
      media_content_type: video/youtube
    entity_id:
    - media_player.tv_bedroom
    - media_player.tv_bathroom
    service: media_extractor.play_media
1 Like

Isnā€™t the service the first action that needs to call?

That doensā€™t matter I think. If thatā€™s the issue then a regular Youtube stream wouldnā€™t load. I guess the problem has to be live streaming video. Any other thoughts?

this indeed looks like a problem with the live videos, i assume due to some issue with the yt-dl that is being used by the media_extractor for ā€œvideo/youtubeā€ media_type.

probably media_extractor implementation in home-assistant should support also the ā€œis_liveā€ option - see this info:

"is_live (boolean): Whether this video is a live stream or a fixed-length video"

Hi @goprojojo - If i understand the normal youtube link is working but livestream isnā€™t. I used your config above and tried to play a video but it doesnā€™t seem to work. I have added a media_player configuration too. Is the above config correct? Should we add a media_extractor section in config?

The above config should still work and you need to include media_extractor too. Try to replace it with a non-livestream url, for example: https://youtu.be/cHHLHGNpCSA

Hmm used it but looks like its still not working. Hereā€™s my configuration. On executing this it gives me a ā€œNotImplementedErrorā€

media_player:

  • platform: braviatv
    host: 192.168.0.197
    name: living

media_extractor:
default_query: best

automation:
trigger:
- platform: time
at: ā€˜10:29:00ā€™
action:
- service: media_extractor.play_media
data:
media_content_id: ā€œhttps://youtu.be/cHHLHGNpCSAā€
media_content_type: video
entity_id:
- media_player.living

Try media_content_type: video/youtube

Nope. Unfortunately its the same error. Btw i am using a dockerized version of HA. So i dont know if its still supported.

Has anyone figured out live streaming? Non-live streams work fine.

Would be interested in casting a youtube live stream as well. Works fine with a regular video but as soon as I use a live stream URL it wonā€™t load.

Any ideas how to solve this issue?

Indeed, would be nice to program a morning scene where the TV powers on and starts playing live news on the chromecast.

Has there been any update on this? I was also wondering if you could get around this by just having home assistant display an internal HTML page to the chromecast with just a simple iframe to the live video embedded?

Just chiming in, hoping for any solution here. Iā€™d like to live stream the news when i get up.

I set up CATT in my HA container (non-persistent, but easy enough to restore when necessery)

Came across this thread today trying to live-stream lo-fi hip-hip girl and the local news. Turns out CATT does this out of the box :slight_smile: catt -d "My Room display" cast "https://www.youtube.com/watch?v=5qap5aO4i9A"

The only hassle is that Iā€™m integrating this with HA via shell_command, and havenā€™t worked out how to pass service data to the command successfully. At this stage. Iā€™m stuck using an individual command for each video, but thatā€™s a pretty simple workaround.

1 Like

Subscribed also interested in live streams

1 Like

Hey all. I found a workaround Iā€™m comfortable with at least, using the ā€œYouTube appā€:

service: media_player.play_media
target:
  entity_id: media_player.58pus8555_12_2
data:
  media_content_type: cast
  media_content_id: '
    {  
       "app_name": "youtube",
       "media_id": "Ek1-adoyE_0"
    }'

1 Like

What do you exactly mean with using the YouTube app? How would it look like in an automation within Home Assistant (using yaml)

I just tried the YAML I posted in the Developer Tools and it worked like a charm :slight_smile: I would expect the same YAML to work in an automation by just calling that service as an action?

Sorry for not being very clear; the ā€œappā€-part was just what I understood from the Home Assistant documentation where I found how to do this :slight_smile: It should not be important.

EDIT:

Hereā€™s the documentation:

1 Like

My problem was very similar, I wanted to make an alarm clock with a YouTube live show. My problem was that the id changed every day when I started the stream. For this Google has its YouTube api. I created a new sensor to get the live id and call it from the automation. I leave the code below:

sensor:
  - platform: rest
    resource: https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={YOUR_CHANNEL_ID}&eventType=live&type=video&key={KEY_API}
    method: GET
    value_template: '{{ (value_json["items"][0].id.videoId | string) }}'
    name: "youtube"
    scan_interval: 2100        
action:
  - service: media_player.play_media
    data:
      media_content_type: cast
      media_content_id: " { \"app_name\": \"youtube\", \"media_id\": \"{{states.sensor.youtube.state}}\" }"
    target:
      entity_id: media_player.chromecast7018

PerdĆ³n por la traducciĆ³n, cualquier cosa me escriben