I spent some time searching for a smooth solution to play a specific YouTube video on a Roku device. There are a couple ways to do it, but they are all pretty involved, so I made my own. My adjusting the app_id, it should be possible to adapt this to deep-link media in any Roku app.
This script will play the specified YouTube video on the given Roku device. It may present a “select a profile” screen; if so, the script will pick the default profile so it can start playing.
alias: "Provide Penguins: Roku"
description: >-
This script will cast a YouTube video (Monterey Bay Penguin Cam, by default)
to the chosen Roku device, turning it on and clicking through the
"choose a profile" screen if necessary.
variables:
entity_name: smaller_roku_tv
video_id: gOptyLanxq4
fields:
entity_name:
name: Roku Entity Base Name
description: >-
The last field of the entity id, after the '.' so if your full entity_id
is "media_player.my_roku", then the entity_name should be "my_roku"
example: my_roku
default: my_roku
selector:
text: null
video_id:
name: Video ID
description: The YouTube video ID
example: gOptyLanxq4
default: gOptyLanxq4
selector:
text: null
sequence:
- variables:
mp_entity: media_player.{{ entity_name }}
r_entity: remote.{{ entity_name }}
- if:
- condition: template
value_template: "{{ states(r_entity) == 'off' }}"
then:
- service: remote.turn_on
data:
entity_id: "{{ r_entity }}"
- service: media_player.play_media
data:
entity_id: "{{ mp_entity }}"
media_content_id: 837
media_content_type: app
extra:
content_id: "{{ video_id }}"
content_type: live
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- if:
- condition: not
conditions:
- condition: template
value_template: "{{states( mp_entity ) == 'playing'}}"
then:
- service: remote.send_command
data:
command:
- enter
entity_id: "{{ r_entity }}"
icon: mdi:penguin
mode: parallel