Through some effort, and help on reddit, I found that you can send a youtube URL (sorta) to your google home using the following automation.
- service: media_player.play_media
data:
entity_id: media_player.google_home
media_content_id: https://r2---sn-5uaezn6s.googlevideo.com/videoplayback?nh=IgpwcjAyLmF0bDIyKgkxMjcuMC4wLjE&signature=8EE28CECD309F9772452B19BE0ECB7C3FDBF92EF.09F228C2A978D0CF41BF168363BCBEAE2A5B82D9&source=youtube&upn=1hX_AQQxUlo&requiressl=yes&mime=video%2Fmp4&ratebypass=yes&aol=yes&lmt=1471075243852831&ip=2602%3A306%3Ac4ea%3A4e20%3A6374%3A15f%3Add2%3Ac344&expire=1484819790&mm=31&ipbits=0&mn=sn-5uaezn6s&pl=52&mt=1484798144&dur=36001.657&mv=m&initcwndbps=5000000&ms=au&itag=22&sparams=aol%2Cdur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cnh%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&id=o-AGaeR8fidCRavdtmBFTIqi41yoRZdZGMbnKtfuBfHt-H&ei=7jiAWOzCNoGKqwWhlonwBg&key=yt6
media_content_type: audio/mp4
However, you can’t currently cast a normal youtube url. In order to find the direct link that the google home (and maybe all cast devices?) require, you need to use something like youtube-dl. GitHub - ytdl-org/youtube-dl: Command-line program to download videos from YouTube.com and other video sites
To get the url from youtube-dl, you can
sudo pip install --upgrade youtube_dl
youtube-dl -g --skip-download https://www.youtube.com/watch?v=RzACrNBYKFE&index=1&t=19s&list=PLq5sdyyflMdaurq02V-p1wr5tjKKmuOMX
Once you get the URL from that command, you use it in your configuration. BUT the url expires and you have to pull it at least once per day, which defeats the purpose of the automation.
I propose skipping the manual step, and allowing a configuration like this.
- service: media_player.play_media
data:
entity_id: media_player.google_home
media_content_id: https://www.youtube.com/watch?v=RzACrNBYKFE&index=1&t=19s&list=PLq5sdyyflMdaurq02V-p1wr5tjKKmuOMX
media_content_type: audio/youtube
When the automation runs, it would recognize the youtube content type, run the python youtube-dl lib to get the real url, and send that to the cast device. Preferably with some caching.
Let me know if I missed a better way to do this with current config, I have been working on automatically casting sleep music to google home for a while now and I’m almost there.
Thanks!