Plex Play Media (Movie, TV Show, Playlist)

I finally got the Plex integration working with Home Assistant and an Nvidia Shield. I believe the docs are outdated and ask for “/” in the media_content_id but that is no longer needed. Below are three examples for playing a movie, a tv show episdoe, and a video playlist.

################################################################################
script_test1:
alias: “Play MOVIE Test”
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.plex_shield_android_tv
media_content_id: ‘{“library_name”: “Movies”, “video_name”: “Blade”, “shuffle”: 0 }’
media_content_type: ‘VIDEO’
################################################################################
script_test2:
alias: “Play EPISODE Test”
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.plex_shield_android_tv
media_content_id: ‘{ “library_name” : “TV Shows”, “show_name” : “According to Jim”, “season_number” : 1, “episode_number” : 1, “shuffle”: “1” }’
media_content_type: ‘EPISODE’
################################################################################
script_test3:
alias: “Play PLAYLIST Test”
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.plex_shield_android_tv
media_content_id: ‘{ “playlist_name” : “According to Jim”, “shuffle”: “1” }’
media_content_type: ‘PLAYLIST’
################################################################################

5 Likes

Hmm
This has me thinking I could link this to google. Pass a movie title to home assistant which then triggers said movie.

2 Likes

Hey there! Mind sharing your config for getting the Nvidia Shield Plex client work with HA ?

Do you feel like we could do the same for the AppleTV Plex client? or the Kodi Plex addon? Thanks a bunch!

1 Like

Nice! The docs should probably be updated. This section was written a looooong time ago.

FYI, the shuffle parameter is now optional and defaults to “0”.

1 Like

Would this work on a sonos/chromecast media player ?

It cold work for a Sonos player but you must add Plex to the list of services in Sonos. Then the Sonos player should show up as a client. So if you have an audio playlist in Sonos you could use my playlist example above. This will not work for chrome cast because Plex does not register chrome cast devices as Plex clients.

@millsx2 have you done any configuration to your players (Plex Clients)?! I’m absolutely not able to start an episode to any of the plex clients I have… I’ve tried Plex on Apple TV, Plex Kodi Add-on, two browsers (Safari and Firefox) and Plex on iOS with the same sad result.

It just doesn’t work… :frowning: It doesn’t show errors in the logs too…

Thanks!

The configuration for the players/clients should be automatic as long as you have the plex configuration set up correctly. Anytime a new client is added, for example, you install plex on a PS4, a new media player should be created in hassio that represents the ps4 plex client. Once a new media player is available for that plex client, you can then use it to send the play media command to it utilizing my methods above. If the plex client goes unavailable after a while (due to inactivity), you can look in to sending a rest command of “idle” to basically wake up that plex client to then allow for the play media comand to be send to it.

1 Like

Can you list out the plex media players that are visible to you in hassio? For example, my plex client is called media_player.plex_shield_android_tv

Well I,ve been able to make the whole thing work! It was because of the formatting of the commands you posted on this forum… Quotes were copy/pasted to `(accent grave, in French).

For those reading this in desparate need of a solution, here is what i’ve done in “code block”:

      - type: custom:button-card
        name: ATV
        size: 90%
        show_entity_picture: true
        entity_picture: /local/graphics-lovelace/kidstvshowsicons/paw-patrol.png
        tap_action:
          service: media_player.play_media
          action: call-service
          service_data:
            entity_id: media_player.plex_home_theater
            media_content_id: "{ \"library_name\" : \"TV Shows\", \"show_name\" : \"Paw Patrol\", \"season_number\" : 1, \"episode_number\" : 10, \"shuffle\": \"1\" }"
            media_content_type: "EPISODE"

and yeah, I needed Double Quotes instead of Single Quotes for specifying EPISODE as media_content_type:

Thanks for your help @millsx2 ! It is much appreciated! :slight_smile:

What version of hassio are you on? I am on .103 and I am surprised you still need to use the “” escaped brackets. I think those were removed in some of the updated versions of hassio.

It’s not necessary to escape the double quotes as long as the whole payload is enclosed in single quotes. Make sure that all the quotes are “plain” and not open/close versions.

I am on .103 as well… but @jjlawren is right, I had the opened/closed versions. :wink:

Are any of you able to cast plex to a standard, non-built-in Chromecast? I can cast to my Shields, but not my Chromecast. see here for full issue details

I think you need to have the plex app installed on a device in order to cast to it. Since my nvidia sheild has plex installed, my home assistant integration sees the plex client and I am able to install to it. I cannot install the plex app on my Google Home so I cannot cast directly to it. I can cast to it through the plex app on my phone though.

@millsx2 That’s what I’m leaning towards. It would be great if we could cast to any device that Plex can.

Sidenote…when you use play_media, does Plex track it? My Plex Server Dashboard won’t show that anything is playing and played/unplayed and play position don’t get tracked even though the video plays on the Shield.

Yeah I would love to be able to cast plex to any device that is supported by Plex. As a workaround I can cast the .mp4 file directly to a Google Home without needing Plex but the features are limited compared to what you can do with plex.

As for the dashboard, play_media used to show what was playing on Plex on my shield. This was working great until a couple weeks ago where I think something changed either on Plex’s end or in the plex component code.

Aha! So it’s not just me! I could’ve sworn it used to work, too, but I only just started integrating Plex like this.

Is this working for anyone? I am on 0.106.0, trying to implement this for the first time, and running into the following two errors:

File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 595, in play_media
raise NotImplementedError()
NotImplementedError

and

Error executing script script.1582866973363. Unknown error for call_service at pos 1:

The script:

'1582866973363':
  alias: Plex Test
  sequence:
  - data_template:
      media_content_id: '{ "playlist_name" : "Oldies", "shuffle": "1" }'
      media_content_type: 'playlist'  
    entity_id: media_player.roku_kitchen
    service: media_player.play_media

Any advice?

It seems the media_player.roku_kitchen entity was not created by the Plex integration.