Instant vibes at home. Automatically turns on an Android TV, launches a YouTube video, and groups Sonos speakers.
- Home Assistant with a Sony Android TV added as a media player. (Any Android TV should work, but I haven't tested!)
- Home Assistant Cloud, set up with Google Home
- Sonos speakers (optional — for the speaker grouping feature)
- On the TV, go to Settings > Device Preferences > About > Build
- Click Build 7 times to enable Developer Options
- Go to Settings > Device Preferences > Developer Options
- Enable USB Debugging
- In Home Assistant, go to Settings > Devices & Services > Add Integration
- Search for Android TV Remote (or Android Debug Bridge) and install it
- Enter your TV's IP address when prompted
- Accept the pairing prompt that appears on the TV screen
- Go to Settings > Add-ons > Add-on Store
- Search for File Editor and install it
- Start it and enable Show in sidebar
- Open File Editor from the sidebar
- Create a folder called
python_scripts - Upload
get_random_youtube_video.pyintopython_scripts/
Open configuration.yaml in File Editor and append the file in this repo. This GitHub repo has 4 examples but you can add as many more as you want. Each sensor picks a random video ID from a YouTube channel or playlist feed. Replace the feed URLs with your own channels/playlists.
To get a feed URL:
- Channel:
https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID - Playlist:
https://www.youtube.com/feeds/videos.xml?playlist_id=PLAYLIST_ID - You can also pass individual video IDs as extra arguments (space-separated)
- Open
scripts.yamlin File Editor (create it if it doesn't exist) and append the file in this repo. - Update the entities for your TV and Sonos speakers.
- Add any new wrapper scripts, if you created additional sensors.
If you don't use scripts.yaml yet, make sure configuration.yaml includes it:
script: !include scripts.yamlFind your entity IDs in Settings > Devices & Services > Entities (use the search box).
| Variable | What to put |
|---|---|
tv |
Entity ID of your Sony TV, e.g. media_player.sony_tv |
active_speaker |
Entity ID of your main Sonos speaker |
group_speakers |
List of speaker entity IDs to group together |
For each wrapper script (e.g. "Background Video: Hiking"):
- Go to Settings > Automations & Scenes > Scripts
- Find the script > (...) on the right > Settings
- Voice Assistants > Turn on Expose
- Ensure Google Assistant is on
- Go back and save
This makes the script available to Google Home and other voice assistants.
- Go to Developer Tools > YAML and click Reload Scripts (and Reload Command Line to pick up the new sensors)
- Go to Settings > Scripts, find your wrapper script, and click Run
- Check Settings > System > Logs and filter for
[Background Video]to see what's happening
Head to Home Settings > Works with Google > Home Assistant Cloud > Check for New Devices so the scripts you exposed are loaded.
Then, for each kind of video:
- Go to Automations > + to create a new automation
- Tap (...) in the top right > Previous household editor
- Tap New in the top right > Household
- Tap Add starter > Define a voice command and enter your phrase (e.g. "play hiking videos")
- Tap Add action > Adjust home devices, scroll to the very bottom, tap Add scenes, and find the Background Video: ... script
Repeat for each channel.