Since everybody where I am is working from home and the schools are closed, my kid’s teachers have sent out some class materials to keep them learning. Some of this material is in the form of online videos. I’ve learned the hard way that because of COPPA, you can no longer add kids’ content to a YouTube playlist. Also, some of the videos are on other sites, like Vimeo.
This presents me with a problem. How can I get these videos to play sequentially without having to play them manually every time? I figure home assistant can help in some way.
So here’s my question: Given that I have a list of video URLs (mostly YouTube, but some Vimeo and other sites), how can I configure Home Assistant to play them in sequence on my Chromecast, one after the other?
The google cast integration is ‘local polling’, so it’s going to be delayed, possibly 30 seconds, until the next video would play if you try to trigger on the state of the chromecast.
In any case, I would create a script to handle this. Mainly so you don’t have to restart HA completely to update the list (can just reload scripts from the config page)
You will have to create an input_number though to keep track of what video you’re on. Add it to lovelace too so you can set it to a number to start from a specific video.
script:
school_playlist:
sequence:
service: script.play_next
data_template:
# Create a custom string to pass to our script. Doing this so we
# only have to define the playlist once in a single place.
# We could create an input_text and define it there, but you would have to
# more work and maintenance to maintain it....
playlist_info: >
{% set playlist =
[
['http://url1','youtube'],
['http://url2','vimeo'],
['http://url3','netflix'],
]
%}
{% set index = states('input_number.current_video_index') | int %}
{% if index >= (playlist | count) %}
{% set index = 0 %}
{% endif %}
{{ playlist[index][0] ~ "," ~ playlist[index][1] ~ "," ~ playlist | count }}
play_next:
sequence:
# playlist_info is a comma separated string. 'url, source, playlist size'
# also, increment the current_video_index after playing.
- service: media_player.play_media
data_template:
entity_id: media_player.chromecast
media_content_id: "{{ playlist_info.split(",")[0] }}"
media_content_type: "video/{{ playlist_info.split(",")[1] }}"
- service: input_number.set_value
# Increment the number. If we go > playlist, wrap back to 0.
data_template:
value: "{{ ((states('input_number.current_video_index') | int) + 1) % (playlist_info[3] | int) }}"
Now just find some way to auto call school_playlist script. Alexa voice command (“Alexa, play next school video”), automation trigger when video is done (you’ll have to figure this out based on your media player attributes), etc.