Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ecto1a2003/2f435ea12aa2b7e00389419a1c2885a8 to your computer and use it in GitHub Desktop.

Select an option

Save ecto1a2003/2f435ea12aa2b7e00389419a1c2885a8 to your computer and use it in GitHub Desktop.
play_plex_media_using_assist.yaml
blueprint:
name: Play Plex media using Assist
description: >
Play any Plex media on a media player of your choice.
The media player has to support this action.
domain: automation
input:
button:
name: plex rescan button
description: Button that initiates rescan on target plex server
selector:
entity:
domain: button
media_player:
name: Media player
description: Media player on which to start Plex playback
selector:
entity:
domain: media_player
chromecast:
name: Is this a chromecast
description: Specify if this is a chromecast device
default: false
selector:
boolean:
media_player_friendly_name:
name: Media player friendly name.
description: The name of the media player you want the automation to trigger on. E.g. 'bedroom TV'
default: plex
media_player_power:
name: Media player that can be tested for power.
description: The media player that can be power controlled and set source to plex, not needed if chromecast
default:
selector:
entity:
domain: media_player
media_player_app:
name: exact name of plex app
description: Literal name of plex app from media player
default:
selector:
select:
options:
- Plex - Free Movies & TV
- Plex
media_player_remote:
name: Media player remote that can power control device
description: The remote that can power the media player if off - only if needed.
default:
selector:
entity:
domain: remote
movies_library_name:
name: Movies library name
description: The name of your Plex Movies library
default: "Movies"
tvshows_library_name:
name: TV Shows library name
description: The name of your Plex TV Shows library
default: "TV Shows"
music_library_name:
name: Music library name
description: The name of your Plex Music library
default: "Music"
variables:
target_is_chromcast: !input chromecast
target_friendly_name: !input media_player_friendly_name
target_media_player: !input media_player
target_power_player: !input media_player_power
target_movies_library: !input movies_library_name
target_tvshows_library: !input tvshows_library_name
target_music_library: !input music_library_name
target_media_player_app: !input media_player_app
target_media_player_remote: !input media_player_remote
target_button: !input button
# lists:
# verbal_number:
# values:
# - in: "first"
# out: 1
trigger:
- platform: conversation
id: movie
command:
- Play [the] (movie|film) {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: episode
command:
- Play [the] episode [number] {plex_episode_index} [of the] season [number] {plex_season_index} [of the show] {plex_media_name} on [the] {media_player_assist_name}
# - Play [the] "{verbal_number:plex_episode_index}" episode [of the] "{verbal_number:plex_season_index}" season [of the show] {plex_media_name} on [the] {media_player_assist_name}
# - Play [the] "{verbal_number:plex_episode_index}" episode [of] season [number] {plex_season_index} [of the show] {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: namedEpisode
command:
- Play [the] episode {plex_episode_title} on [the] {media_player_assist_name}
- Play [the] episode {plex_episode_title} of the show {plex_media_name} on [the] {media_player_assist_name}
#need to test if show can be null otherwise seperate trigger
- platform: conversation
id: newestEpisode
command:
- Play [the] (newest|latest) episode [of the show] {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: season
command:
- Play [the] season [number] {plex_season_index} [of the show] {plex_media_name} on [the] {media_player_assist_name}
#- Play the {plex_season_verbal} season [of the show] {plex_media_name} on [the] {media_player_assist_name}
#need second sentence here to map words like second or first to 2, 1
- platform: conversation
id: show
command:
- Play the show {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: playlist
command:
- Play the playlist {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: movieCollection
command:
- Play the plex movie Collection [the] {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: tvCollection
command:
- Play the plex (tv|show|tv show|episode) Collection [the] {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: randomMovie
command:
- (Play|pick) a random (movie|film) on [the] {media_player_assist_name}
- (Play|Pick) a movie on [the] {media_player_assist_name}
- platform: conversation
id: ratingMovie
command:
- (Play|pick) a {rating} rated (movie|film) on [the] {media_player_assist_name}
- platform: conversation
id: genreMovie
command:
- (Play|pick) a {genre} (movie|film) on [the] {media_player_assist_name}
- platform: conversation
id: randomEpisode
command:
- (Play|pick) a random episode of the show {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: randomShow
command:
- (Play|pick) a random show on [the] {media_player_assist_name}
- platform: conversation
id: performerMovie
command:
- (Play|pick) a (movie|film) that {actor} is in on [the] {media_player_assist_name}
- platform: conversation
id: directorMovie
command:
- (Play|pick) a (movie|film) that {director} directed on [the] {media_player_assist_name}
- platform: conversation
id: unwatchedMovie
command:
- (Play|pick) a unwatched (movie|film) on [the] {media_player_assist_name}
- (Play|pick) a (movie|film) [that] (i|we) havent seen on [the] {media_player_assist_name}
- platform: conversation
id: track
command:
- Play the (song|track) {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: album
command:
- Play the album {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: artist
command:
- Play the artist {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: musicGenre
command:
- Play the {plex_media_name} genre on [the] {media_player_assist_name}
- Play the music genre {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: mood
command:
- Play the {plex_media_name} mood on [the] {media_player_assist_name}
- Play the mood {plex_media_name} on [the] {media_player_assist_name}
- platform: conversation
id: style
command:
- Play the {plex_media_name} style on [the] {media_player_assist_name}
- Play the style {plex_media_name} on [the] {media_player_assist_name}
#triggers to add:
#make area aware?
#random episode of show
#newest|latest episode of show
#resume
#pickup where i|we left off on show
#resume movie/episode of show
#finish movie/episode
#music
# song from artist
# song from alblum
# album from artist\
#how many x are in you
#what was last episode i played of show
action:
- service: system_log.write
data:
level: error
message: "{{target_friendly_name}}"
- service: system_log.write
data:
level: error
message: "{{trigger.slots.media_player_assist_name}}"
- service: system_log.write
data:
level: error
message: "{{target_is_chromcast}}"
- alias: "Check if friendly media player name is used"
condition: template
value_template: "{{ (target_friendly_name) == (trigger.slots.media_player_assist_name)}}"
- if:
- condition: template
value_template: "{{ (target_is_chromcast) == False }}"
# value_template: "{{ states(target_power_player) != unknown}}"
then:
- if:
- condition: template
value_template: "{{ states(target_power_player) == off }}"
then:
- if:
- condition: template
value_template: "{{ states(target_media_player_remote) != unknown }}"
then:
# seperate power remote specified
- service: remote.turn_on
target:
entity_id: !input media_player_remote
else:
- service: media_player.turn_on
target:
entity_id: !input media_player_power
- wait_for_trigger:
- platform: template
value_template: "{{ states(target_power_player) == on }}"
for:
hours: 0
minutes: 0
seconds: 2
#- service: plex.scan_for_clients
# data: {}
- service: button.press
target:
entity_id: !input button
- wait_for_trigger:
- platform: state
entity_id: !input media_player
timeout:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- if:
- condition: state
entity_id: !input media_player
state: unavailable
then:
- service: media_player.select_source
data:
source: !input media_player_app
target:
entity_id: !input media_player_power
- repeat:
sequence:
- if:
- condition: template
value_template: "{{ ((repeat.index) % 5) == 0 }}"
then:
- service: media_player.select_source
data:
source: !input media_player_app
target:
entity_id: !input media_player_power
#- service: plex.scan_for_clients
# data: {}
- service: button.press
target:
entity_id: !input button
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
while:
- condition: state
entity_id: !input media_player
state: unavailable
- choose:
- conditions:
- condition: trigger
id:
- movie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "movie.title": "{{ trigger.slots.plex_media_name}}" }'
- conditions:
- condition: trigger
id:
- performerMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "actor": "{{ trigger.slots.actor}}","sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- directorMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "director": "{{ trigger.slots.actor}}","sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- randomMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
# media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "sort": "random", "maxresults": 1 }'
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "contentRating!": ["R","Unrated","X","NC-17","Not Rated","None"], "sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- genreMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
# media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "genre": "{{ trigger.slots.genre }}", "sort": "random", "maxresults": 1 }'
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "contentRating!": ["R","Unrated","X","NC-17","Not Rated","None"], "genre": "{{ trigger.slots.genre }}", "sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- ratingMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "contentRating": "{{ trigger.slots.rating }}", "sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- unwatchedMovie
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "contentRating!": ["R","Unrated","X","NC-17","Not Rated","None"],"unwatched": 1, "sort": "random", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- episode
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "season.index": "{{ trigger.slots.plex_season_index}}", "episode.index": "{{ trigger.slots.plex_episode_index}}" , "show.title": "{{ trigger.slots.plex_media_name}}" }'
- conditions:
- condition: trigger
id:
- namedEpisode
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "episode.title": "{{ trigger.slots.plex_episode_title}}" , "show.title": "{{ trigger.slots.plex_media_name}}" }'
#media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "episode.title": "{{ trigger.slots.plex_episode_title}}" }'
- conditions:
- condition: trigger
id:
- newestEpisode
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "show.title": "{{ trigger.slots.plex_media_name}}", "episode.unwatched": true, "sort": "addedAt:desc", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- randomEpisode
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "show.title": "{{ trigger.slots.plex_media_name}}", "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- season
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "season.index": "{{ trigger.slots.plex_season_index}}", "show.title": "{{ trigger.slots.plex_media_name}}" }'
- conditions:
- condition: trigger
id:
- show
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "show.title": "{{ trigger.slots.plex_media_name}}", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- randomShow
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: EPISODE
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}","contentRating!": ["R","Unrated","X","NC-17","Not Rated","None","TV-MA"], "sort": "random", "maxresults": 3 }'
- conditions:
- condition: trigger
id:
- playlist
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: PLAYLIST
media_content_id: 'plex://{"playlist_name": "{{trigger.slots.plex_media_name}}", "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- movieCollection
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_movies_library}}", "collection": "{{trigger.slots.plex_media_name}}", "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- tvCollection
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: movie
media_content_id: 'plex://{"library_name": "{{target_tvshows_library}}", "collection": "{{trigger.slots.plex_media_name}}", "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- track
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "track.title": "{{ trigger.slots.plex_media_name}}", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- album
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "album.title": "{{ trigger.slots.plex_media_name}}", "maxresults": 1 }'
- conditions:
- condition: trigger
id:
- artist
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "artist.title": "{{ trigger.slots.plex_media_name}}", "maxresults": 1, "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- musicGenre
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "genre": "{{ trigger.slots.plex_media_name}}", "shuffle": 1, "allow_multiple": 1 }'
- conditions:
- condition: trigger
id:
- mood
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "mood": "{{ trigger.slots.plex_media_name}}", "maxresults": 1 , "shuffle": 1 }'
- conditions:
- condition: trigger
id:
- style
sequence:
- service: media_player.play_media
target:
entity_id: !input media_player
data:
media_content_type: music
media_content_id: 'plex://{"library_name": "{{target_music_library}}", "style": "{{ trigger.slots.plex_media_name}}", "maxresults": 1 , "shuffle": 1 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment