Casting YouTube in Home Assistant

Casting YouTube in Home Assistant

My aim was to cast a Youtube video on Google devices with the help of Home Assistant, but it seems to be impossible, and I’ll explain why. Actually, it might be possible on a significantly faster host than RaspberryPi 3 and its weak SD card, but practically it’s not possible on them, right now.

During my experimentation, recommendations kept coming back for integrations like RESTful, Scrape, and the most important one: Media Extractor.

There is also a youtube integration under custom-components/youtube that gives information about the latest video on a channel, but it doesn’t bring me anything new that I don’t already have.

What I Want to Cast

There are several “entities” that I would like to cast, including the following:

  1. First and foremost, I would like to cast a regular video, for example:
    Youtube URL:

  2. Casting a Channel by ID, for example:
    Youtube Channel URL:

  3. Casting a Channel by @username, like:
    Youtube Channel URL by name:

  4. Casting a Playlist by ID, like:
    Youtube Playlist URL:

  5. Casting the Latest Video by hashtag, like:
    Youtube Hashtag URL:
    or a combination of Channel ID and search:

Note that in the case of a “hashtag” search, I eventually found a playlist with a regular ID, which is fortunate as I couldn’t find a way to cast a playlist that included a search.

Uncover the Real Channel ID

Casting “@user” is essentially the same as casting by Channel ID, we just need to manually uncover the Channel ID that hides behind the @user nickname. Since there is no perfect way to do this, the closest approximate short solution is to load any video from that user and type into the JS console:


This line should reveal the true Channel ID as it is located somewhere within the HTML element that has “itemprop” with a value of “channelId”, as described here.

Now the problem of casting is reduced to: video-by-id, channel-by-id, playlist-by-id, hashtag.

RSS Feeds If Needed

Although I haven’t found a specific use for them, since my problem isn’t in uncovering the URL but rather in actually streaming it, I will nonetheless list possible RSS feeds:

  • The Channel ID RSS feed is:<id>
  • The Playlist ID RSS is located at:<id>

Media Extractor

Integrating the media_extractor is the only option available for YouTube, relying on ytdl-org/youtube-dl as the engine. Unfortunately, this seems to result in the video being downloaded before it is played, which is a significant drawback on my less powerful RPi3. Thus, there’s no way to directly stream videos from YouTube to the Cast device.

Seeking Minimal Bandwidth

It turns out that I can successfully play some videos, but only if they are of a minimum size. The “worst” format can be specified with the hope that the video file in that format is not actually large.

For example, the following video doesn’t have a “small” format that contains both video and audio, as the smallest is even 200M:

youtube-dl "" --list-formats

And such a video is simply impossible to play on my devices.

Since the backend is actually youtube-dl, it’s best to first check with the following command if there’s a typically smaller resolution, and if not, I think further effort is futile:

youtube-dl "" --format=worst

For some videos there are smaller formats, like for example: video-yes, but for some there aren’t video-no.

Normally, playback of all types of media goes through the Home Assistant service call:

service: media_extractor.play_media
  entity_id: media_player.nest_hub
  media_content_id: ""
  media_content_type: video/youtube

The media_content_type can be “music”, “tvshow”, “video”, “episode”, “channel” or “playlist music”, whatever that means.

Opting for Smaller Files

You should add the following lines to the global configuration, which instructs our media player (Nest Hub) to utilize youtube-dl and download the worst and therefore, the smallest format, since the screen size is also small and therefore, there won’t be much difference:

      video: worst
No Dice

Regardless of the efforts I’ve made, everything was too slow. Perhaps, if I had replaced the SD card with an SSD disk or if the RPi3 was an RPi4, things would have been different. But as things stand, there’s no way I can play most podcasts from Youtube.

I even tried downloading just audio or video, but that too was slow to be usable.

Casting URL to Nest Hub or Google TV?

An interesting way to cast a URL to one of the Google Chromecast devices. AlexxIT/DashCast: DashCast component for Home Assistant

Alternative is CATT? HomeAssistant and CATT (Cast All the Things!) Google Nest Hub as Dashboard with DashCast add-on - Share your Projects! - Home Assistant Community

Cast or share camera stream · AlexxIT/WebRTC Wiki

Playing Tune-In Radio Stations

Integration: music-assistant/hass-music-assistant

To find a radio URL on the Tune-In Radio page - it is explained here Basically, just search the page for “jp_audio” and you will find the stream URL.

date 09. Jul 2022 | modified 06. Feb 2023
filename: » Media » Video