Music Mode: Automatically play music videos while you stream music!

Hello everyone, I recently created an automation that displays music videos on my Android TV for the songs I’m streaming from my Chromecast Audio. It also lets me set my lights to the color of the album cover I’m listening to.

Prerequisites

  • An Android TV box for video
  • Another Google Cast device for audio
  • A YouTube API key

YouTube Search

Copy these lines into your Home Assistant configuration.

rest_command:
  youtube_search:
    url: "https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&videoCategoryId=10&fields=items(id/videoId)&q={{ query | urlencode }}"
    method: GET
    headers:
      x-goog-api-key: your_youtube_api_key

How It Works

  1. Personally, I want the automation to trigger only when my Android TV is on and my lights are on as well.
  2. Optional: Once triggered, the automation activates a special scene of your choice. For example: one that turns off the lights you don’t want on while you’re listening.
  3. Next, it changes the color of your lights to match the album being played (see the end of the post for more details on the system I used).
  4. Searches for and displays the corresponding YouTube video on your TV using the API (if there are no results, it simply displays the album cover)
  5. Synchronizes the video with the audio
  6. And there you go!

The Dominant Color Extraction System

During my initial tests, I realized that the official Home Assistant integration (ColorExtractor) wasn’t very effective for extracting colors from album covers. So I decided to create my own API, which I integrated with Home Assistant. You’ll find here all the information you need, including details on integrating it with Home Assistant.

Disclaimer

This automation is by no means perfect and is provided “as is”. I’d love to hear your feedback!

Link to download the automation

I created a small, standalone custom component for Home Assistant that monitors the album art of a selected media_player and exposes its dominant color as a standard `light.* entity (RGB)