PlexDevices - Custom Media Player Component

I created a custom component called PlexClients out of necessity as the built-in Plex component didn’t meet my needs.

Here are the advantages and disadvantages of this component over the HA
standard media_player.plex component

Advantages:

  • No discovery needed (queries your plex server directly for connected players)
  • Control volume (media_player.plex doesn’t even show the volume control)
  • Displays proper player names (i.e. Living Room Apple TV instead of Plex Web Safari - This is because media_player.plex grabs the name from the session instead of the player object)
  • Works with all Plex Clients (media_player.plex never displays the below)
  • Mobile (iPhone, iPad, etc)
  • PlexConnect (How earlier generation Apple TV’s can access Plex)
  • Displays episode specific data (when playing a season, media_player.plex will only display the first episode name and TV show thumbnail)
  • Current episode thumbnail
  • Current show and episode name
  • Current season and episode number
  • Shows disconnected clients as idle (when a player disconnects, media_player.plex keeps the player as ‘playing’ and adds a hidden player as ‘idle’.)
  • No configurator, plex.conf, or plex token required (this probably works for me because I’ve set Plex to NOT require authentication for my local LAN)

Disadvantages:

  • Crappy, hardly tested, non-supported code
  • Probably more

To Do:

  • Clean up code
  • Resolve local names (i.e. “Jesse’s Macbook” instead of “Plex Web (Safari)”")
  • Dynamically create an HA group with all players
  • Separate the group between local and remote (using plex_client[‘player_location’])
  • Remove playback control (ex. SUPPORT_PLEXCLIENT = None) per player type

Limitations:

  • Can’t retrieve current volume (but can set)
  • No functional playback controls on PlexConnect clients
  • No functional playback controls on web clients (probably same reason above)
  • No functional playback controls on ios clients (apple thing?)

Feel free to improve this code and even incorporate into HA (which I do not have the time to do) - I just ask that you let me know (so I can add your improvements or migrate to something better).

Thanks

Code:
https://github.com/JesseWebDotCom/home-assistant-configuration/blob/master/custom_components/media_player/plexdevices.py

Documentation:
https://github.com/JesseWebDotCom/home-assistant.github.io/blob/plex-documentation/source/_components/media_player.plex.markdown

31 Likes

Really looks good!

2 Likes

You should submit this in a pull request! It’s a massive improvement!

5 Likes

Sounds awesome!

Will this also take advantage of the new webhooks recently released from Plex?

Awesome! Or should I say, Schwifty! Further proof that sometimes coding is more art than science. A lot of people don’t get that.

I’m going to test this today!

2 Likes

This indeed should be part of HA. I am sure you will find help in finalizing it once you submit a PR.

Thanks - I’ll need help as I can’t spend too much time figuring out how the process works and then working through the process (maybe the process is not as big a deal as I think)

Also does anyone know how to add/remove a group, add/remove group members, and force HA to refresh or display them. I also want to add a feature of dynamically create group memberships (i.e. a group of actively connected clients, disconnected clients, and any client that has ever connected).

As is, I have to add each client I know about to a group in order for HA to display them. I’d rather have HA display any client that connects.

Hmm, not sure how well the dynamic refresh would work for your use case but you can use:

service: group.reload
entity_id: group.plexclients

check out dev-service for details around it but it’s pretty straight forward.

Easiest way I can think would be to create a group/plexclients.yaml (for those using !include_dir_merge_named group) where you could generate or update the file and force a refresh using group.reload.

file could look like:

  active:
    name: Active
    entities:
      - plexclients.roku

  inactive:
    name: Inactive
    entities:
      - plexclients.appletv

  allclients:
    name: All
    entities:
      - plexclients.roku
      - plexclients.appletv

You probably have forgotten to mention chmod +x in your instruction for plexclients.py.

I changed from media_player.kodi to media_player.shield_android_tv in automation section for controlling my living room lights and as you mentioned, I can’t control the Plex client from Home Assistant. In the bright side, this could replace Kodi as I use it in conjunction with Plex addon and automation. However, the media player won’t show up in Home Assistant unlike Kodi and to do that, I had to start a movie or play music or something. Another downside is it takes a couple of seconds until the poll interval is up and Home Assistant will notice that I have either started or paused the playback. For that, I would have to make a feature request in Plex forum for a feature to send a command whenever I pause or play the movie.

Thank you for the custom component. This is why I love the Home Assistant community so much.

I’ll try and update it so it refreshes immediately (as fast as querying plex and having ha respond) when you send an action

Kyle - I’m trying to do dynamic grouping (i.e. The component will group for you) which ha does example for automations (ex. Group.all_automations). The code has to be out there somewhere - just need to find it

Doesn’t currently. Convince me that I need to add in a feature? What coolness can you accomplish?

Ahh I understand now. Looks like they may be here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/automation/services.yaml

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/automation/init.py

More improvements coming in a few days - like a duration/progress bar (which shows how much of the video has played), and off button (which stops the video - sorry, no start), and hopefully mute and unmute

3 Likes

Realtime updates and no polling, is that good enough? :slight_smile:

I set this up yesterday and while it shows the info and thumbnails accurately none of the media controls seem to work for me; volume, play/pause/next. I downloaded the plexclients.py from the link in the thread yesterday and followed the instructions. My PMS is running on my ShieldTV (2017) like your screen shot.

What am I missing?

I tested by casting from my phone to my shield. Can you test that? I’ll test playing directly in the shield tonight

Also can you test using the standard ha plex component and tell me what you get?

1 Like

Will do and get back to you with the results.

Awesome, thanks, it works! (only tested with OpenPHT for now).