Last active
April 20, 2025 15:29
-
-
Save mediacutlet/fe3d20279e97b87c20631b109305683b to your computer and use it in GitHub Desktop.
Home Assistant Script to Enable LLM Voice Assistants to Shuffle Plex TV Shows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sequence: | |
- variables: | |
tv_show_query: " { other_tv_show_title } " | |
- if: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: media_player.living_room | |
state: "off" | |
- condition: state | |
entity_id: media_player.living_room | |
state: standby | |
then: | |
- action: media_player.turn_on | |
metadata: {} | |
data: {} | |
target: | |
entity_id: media_player.living_room | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 4 | |
milliseconds: 0 | |
alias: Check if Apple TV is turned on and available, if not, turn it on | |
- alias: Conditionally turn TV on, set media source to Plex on Apple TV | |
if: | |
- condition: not | |
conditions: | |
- condition: state | |
entity_id: media_player.sony_xbr_65a1e | |
state: "off" | |
- condition: state | |
entity_id: media_player.sony_xbr_65a1e | |
state: unavailable | |
- condition: state | |
entity_id: media_player.sony_xbr_65a1e | |
state: unknown | |
then: | |
- alias: >- | |
Check if the Sync Box source is set to HDMI 4 (Apple TV) – If not, set | |
it to Apple TV and change the media source to Plex | |
if: | |
- condition: not | |
conditions: | |
- condition: state | |
entity_id: select.sync_box_hdmi_input | |
state: Apple TV | |
then: | |
- action: select.select_option | |
metadata: {} | |
data: | |
option: Apple TV | |
target: | |
entity_id: select.sync_box_hdmi_input | |
alias: Select HDMI 4 on Sync Box (Apple TV) | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 3 | |
milliseconds: 0 | |
- action: media_player.select_source | |
metadata: {} | |
data: | |
source: Plex | |
target: | |
entity_id: media_player.living_room | |
alias: Change Apple TV media source to Plex | |
else: | |
- action: media_player.select_source | |
metadata: {} | |
data: | |
source: Plex | |
target: | |
entity_id: media_player.living_room | |
alias: Change Apple TV media source to Plex | |
else: | |
- alias: >- | |
If Sony TV is off, turn it on and change the source to Plex on Apple | |
TV | |
if: | |
- condition: state | |
entity_id: media_player.sony_xbr_65a1e | |
state: "off" | |
then: | |
- action: media_player.turn_on | |
metadata: {} | |
data: {} | |
target: | |
entity_id: media_player.sony_xbr_65a1e | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 5 | |
milliseconds: 0 | |
- action: select.select_option | |
metadata: {} | |
data: | |
option: Apple TV | |
target: | |
entity_id: select.sync_box_hdmi_input | |
alias: Select HDMI 4 (Apple TV) on Sync Box | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 2 | |
milliseconds: 0 | |
- action: media_player.select_source | |
metadata: {} | |
data: | |
source: Plex | |
target: | |
entity_id: media_player.living_room | |
alias: Select Plex as Apple TV media source | |
else: | |
- variables: | |
response: | |
tv_response: | | |
The Sony TV is unavailable. | |
- stop: "" | |
response_variable: response | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 4 | |
milliseconds: 0 | |
- action: plex.scan_for_clients | |
metadata: {} | |
data: {} | |
alias: Scan Plex for clients in case Living Room Apple TV client is dormant | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 2 | |
milliseconds: 0 | |
- alias: Choose a TV Show to shuffle | |
choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ action_to_take == 'Shuffle MASH' }}" | |
sequence: | |
- data: | |
media_content_type: EPISODE | |
media_content_id: >- | |
{ "library_name": "TV Shows", "show_name": "M*A*S*H", "shuffle": | |
"1" } | |
action: media_player.play_media | |
target: | |
entity_id: media_player.plex_plex_for_apple_tv_apple_tv | |
- action: media_player.volume_set | |
metadata: {} | |
data: | |
volume_level: 0.28 | |
target: | |
entity_id: media_player.sony_xbr_65a1e | |
alias: Shuffle MASH | |
- conditions: | |
- condition: template | |
value_template: "{{ action_to_take == 'Shuffle The Big Bang Theory' }}" | |
sequence: | |
- data: | |
media_content_type: EPISODE | |
media_content_id: >- | |
{ "library_name": "TV Shows", "show_name": "The Big Bang | |
Theory", "shuffle": "1" } | |
action: media_player.play_media | |
target: | |
entity_id: media_player.plex_plex_for_apple_tv_apple_tv | |
- action: media_player.volume_set | |
metadata: {} | |
data: | |
volume_level: 0.2 | |
target: | |
entity_id: media_player.sony_xbr_65a1e | |
alias: Shuffle The Big Bang Theory | |
- conditions: | |
- condition: template | |
value_template: "{{ action_to_take == 'Shuffle Will and Grace' }}" | |
sequence: | |
- data: | |
media_content_type: EPISODE | |
media_content_id: >- | |
{ "library_name": "TV Shows", "show_name": "Will & Grace", | |
"shuffle": "1" } | |
action: media_player.play_media | |
target: | |
entity_id: media_player.plex_plex_for_apple_tv_apple_tv | |
alias: Shuffle Will & Grace | |
- conditions: | |
- condition: template | |
value_template: "{{ action_to_take == 'Shuffle How I Met Your Mother' }}" | |
sequence: | |
- data: | |
media_content_type: EPISODE | |
media_content_id: >- | |
{ "library_name": "TV Shows", "show_name": "How I Met Your | |
Mother", "shuffle": "1" } | |
action: media_player.play_media | |
target: | |
entity_id: media_player.plex_plex_for_apple_tv_apple_tv | |
alias: Shuffle How I Met Your Mother | |
- conditions: | |
- condition: template | |
value_template: "{{ action_to_take == 'Shuffle Other TV Show' }}" | |
sequence: | |
- data: | |
media_content_type: EPISODE | |
media_content_id: >- | |
{ "library_name": "TV Shows", "show_name": "{{ | |
other_tv_show_title }}", "shuffle": "1" } | |
action: media_player.play_media | |
target: | |
entity_id: media_player.plex_plex_for_apple_tv_apple_tv | |
alias: Shuffle Other Show | |
- variables: | |
response: | |
tv_response: > | |
A random episode from the selected TV show should now be playing on | |
Plex. | |
alias: Set success or failure response variable | |
- stop: "" | |
response_variable: response | |
alias: Shuffle Specific TV Show on Plex on Apple TV (Living Room) | |
description: >- | |
Allows you to play a random episode and shuffle show episodes we watch often | |
like M*A*S*H, The Big Bang Theory, How I Met Your Moth, and Will and Grace. If | |
a show is requested to be shuffled which is not listed above, you can still | |
try and shuffle it using this tool. | |
fields: | |
action_to_take: | |
selector: | |
select: | |
options: | |
- Shuffle MASH | |
- Shuffle The Big Bang Theory | |
- Shuffle Will and Grace | |
- Shuffle How I Met Your Mother | |
- Shuffle Other TV Show | |
name: Action to Take | |
description: Decide which action to take based on the TV show requested. | |
required: true | |
default: Shuffle Other TV Show | |
other_tv_show_title: | |
selector: | |
text: null | |
name: other_tv_show_title | |
description: >- | |
If the show being requested to shuffle is not one of the predetermined | |
options, attempt to run a custom query for a specific other TV show. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment