Plex PLAY_MEDIA

I have:

  1. dune HD
  2. plex server
    Trying to launch a playlist using media_player.play_media

entity_id: media_player.plex_plex_for_android_tv_tv292a
media_content_type: PLAYLIST
media_content_id: ‘{“playlist_name”: “vk.com”, “shuffle”: “1”}’

But nothing happens.
Tried to run tracks, same thing.
Help is needed.
Thank.

1 Like

The experiments are ongoing and that’s what happens …
If I try to play a playlist on a web plex client, then the music starts to play.
But if I try to do the same, on Plex for AndroidTV, then nothing happens.

For Plex clients to be controllable (i.e., able to use play_media) then the Plex client and Plex server must be on the same network subnet. It’s possible to get around this requirement with UDP repeaters/reflectors, but that’s a more advanced use case.

To validate this, check the supported_features attribute on the media_player.plex_plex_for_android_tv_tv292a entity. I’m guessing it’s showing up as “0” right now. This means it’s not possible to control the client in the current state.

I’m not familiar with Dune HD, but it seems to run the Plex Android TV client. I’ve had similar issues with the Nvidia Shield Plex client (also Android TV) not being controllable even with proper networking in place. It seems to be an issue with the Plex client and I have an open case on the Plex forums to investigate.

I’ve also improved the play_media handling in the upcoming 0.111 release. Perhaps that will help troubleshoot when it’s out.

Thanks for the answer.
All devices have one network.
Yes, indeed on media_player.plex_plex_for_android_tv_tv292a, supported_features: 0
While on media_player.plex_plex_web_chrome_windows, supported_features: 21053.
I will wait for the update.
Hope this helps.

Once you’re on 0.111 (or perhaps now) it would be helpful to include config for debug logging in the integration and library:

logger:
  logs:
    homeassistant.components.plex: debug
    plexapi: debug

When running media_player.plex_plex_web_chrome_windows
information about the playlist gets into the log.

When I get confused to run media_player.plex_plex_for_android_tv_tv292a, nothing happens.

It’s 99% related to the Plex client not being discovered properly by the Plex server. There’s no immediate solution for that as it relies on 1) a Plex client update/fix or 2) implementing a different discovery method. I’m hoping to find some time to look into #2 in the next month or two.

Any issue open on GitHub or anywhere else so we can keep up with updates? It’s kind of unfortunate that the client has to be on the same subnet as the server as none of my Plex servers are local, or they’re layer 3 routed… which is annoying because I can’t toss in any automations to start media playback.

Any oddball workarounds? Doesn’t sound like it if it’s fundamental client problem other than bridging layer 2 over. And this is on a Shield, so maybe it’s even more broken.

The new discovery method is in 0.112 and later. The Plex clients must be active to show up, but now it doesn’t rely solely on UDP broadcast discovery. Let me know if it helps at all.

Got it - I’ll give it a shot. Been hanging on the .110.3 docker container for a bit because of another unrelated component issue with the latest stable, but I can at least test the Plex media_play functionality or try one the latest build.

Did a quick test with the current RC and latest and it looks like it’s working now. Ran into an issue with a TV show where it failed due to something being returned as None and it was trying to split it with the assumption that a string was being returned, but I can probably look later to see where it’s actually bombing out. Other shows appear to work, so this might just be an issue with the way Plex is returning the metadata.

Otherwise it seems to work, which is great. Are there any docs that show how media_content_id relates to Plex? The current HA docs on it are a bit vague on how actual “show_name” and “video_name” are determined and doesn’t seem entirely consistent. If not I can probably dig through the source, though I suspect again it’s the way Plex is presenting the metadata for this particular show.

Share the error and backtrace if available.

Output linked. Looks like the filter attrib in Marker._loadData is empty, I’m guessing whatever is calling that method is feeding it an empty data parameter. Let me know if you want to bump it up to debug logging or you want me to try and make some API request against the Plex server manually.

This is against 0.114.0b1.

Can you share the script used when this service call fails?

Sure, no problem. These are three test script sequences; test_ep_0 gives the error, and test_ep_1 and test_ep_2 work fine. If I put the year in test_ep_0 it can’t find it (get the standard can’t find media error), so it looks like it’s finding it, it just doesn’t like what it returns after it does.

test_ep_0:
  sequence:
    - service: media_player.play_media
      entity_id: media_player.plex_hose_shield_living_room
      data:
        entity_id: media_player.plex_hose_shield_living_room
        media_content_type: "EPISODE"
        media_content_id: '{ "library_name": "TV Shows", "show_name": "Cowboy Bebop", "season_number": 1, "episode_number": 1 }'

test_ep_1:
  sequence:
    - service: media_player.play_media
      entity_id: media_player.plex_hose_shield_living_room
      data:
        entity_id: media_player.plex_hose_shield_living_room
        media_content_type: "EPISODE"
        media_content_id: '{ "library_name": "TV Shows", "show_name": "The Americans (2013)", "season_number": 1, "episode_number": 1 }'

test_ep_2:
  sequence:
    - service: media_player.play_media
      entity_id: media_player.plex_hose_shield_living_room
      data:
        entity_id: media_player.plex_hose_shield_living_room
        media_content_type: "EPISODE"
        media_content_id: '{ "library_name": "TV Shows", "show_name": "Curb Your Enthusiasm", "season_number": 10, "episode_number": 1 }'

Interesting, all those payloads look fine. It must be something specific to the media itself.

Could you run this python script and share the results? Fill out the baseurl and token values with your own. Make sure to redact any tokens or identifying info:

from plexapi.server import PlexServer

baseurl = 'https://192-168-1-80.997198749174.plex.direct:32400'
token = '<YOUR_TOKEN_HERE>'

server = PlexServer(baseurl, token)
show = server.library.section('TV Shows').get('Cowboy Bebop')
print(f"show: {show}")
season = show.season(1)
print(f"season: {season}")
episode = season.episode(episode=1)
print(f"episode: {episode}")
print(vars(episode))

Sure, here’s the raw output / kept the vars dict output as a single string. Script was run from inside the running HA docker container.

bash-5.0# ./cb-dump 
show: <Show:1497:Cowboy-Bebop>
season: <Season:1498:Cowboy-Bebop-s1>
episode: <Episode:1499:Cowboy-Bebop-s01e01>
{'_server': <PlexServer:https://*****>, '_data': <Element 'Video' at 0x7f9d44f814a0>, '_initpath': '/library/metadata/1498/children', '_details_key': '/library/metadata/1499?checkFiles=1&includeExtras=1&includeRelated=1&includeOnDeck=1&includeChapters=1&includePopularLeaves=1&includeMarkers=1&includeConcerts=1&includePreferences=1', 'listType': 'video', 'addedAt': datetime.datetime(2019, 7, 20, 21, 39, 15), 'key': '/library/metadata/1499', 'lastViewedAt': datetime.datetime(2019, 7, 20, 22, 48, 27), 'librarySectionID': None, 'ratingKey': 1499, 'summary': 'It\'s a normal day on the Bebop for bounty hunters Spike and Jet, until they find out about a new bounty hunter. Asimov Solensan is going around selling a new drug that he stole from the syndicate. It is an eyespray called "Bloody Eye" which makes all of its users very fast and almost invincible, but they also go crazy. Spike and Jet do whatever it takes to catch the culprit. At the same time the syndicate is trying to kill Asimov and get the drug back from him.\r\n', 'thumb': '/library/metadata/1499/thumb/1579807241', 'title': 'Asteroid Blues', 'titleSort': 'Asteroid Blues', 'type': 'episode', 'updatedAt': datetime.datetime(2020, 1, 23, 13, 20, 41), 'viewCount': 1, 'sessionKey': None, 'usernames': [], 'players': [], 'transcodeSessions': [], 'session': [], 'viewedAt': None, 'accountID': None, 'playlistItemID': None, '_seasonNumber': '1', 'art': '/library/metadata/1497/art/1579807242', 'chapterSource': 'media', 'contentRating': 'TV-MA', 'duration': 1482111, 'grandparentArt': '/library/metadata/1497/art/1579807242', 'grandparentKey': '/library/metadata/1497', 'grandparentRatingKey': 1497, 'grandparentTheme': '/library/metadata/1497/theme/1579807242', 'grandparentThumb': '/library/metadata/1497/thumb/1579807242', 'grandparentTitle': 'Cowboy Bebop', 'guid': 'com.plexapp.agents.thetvdb://76885/1/1?lang=en', 'index': 1, 'originallyAvailableAt': datetime.datetime(1998, 10, 24, 0, 0), 'parentIndex': '1', 'parentKey': '/library/metadata/1498', 'parentRatingKey': 1498, 'parentThumb': '/library/metadata/1498/thumb/1579807242', 'parentTitle': 'Season 1', 'rating': 7.9, 'viewOffset': 0, 'year': 1998, 'directors': [], 'media': [<Media:2143>], 'writers': [<Writer:Keiko-Nobumoto>], 'labels': [], 'collections': [], 'chapters': [], 'markers': []}

The strange thing appears to be a missing librarySectionID for this item. If you edit the show name in the script and run again, do the working examples provide a value for this field?

Running it against the working examples, librarySectionID still returns None; here it is against The Americans (2013):

bash-5.0# ./cb-dump                                                                                                                                                                                                                                                           
show: <Show:10:The-Americans-(2013)>
season: <Season:93:The-Americans-(2013)-s1>
episode: <Episode:94:The-Americans-(2013)-s01e01>
{'_server': <PlexServer:https://p00.bluemagg>, '_data': <Element 'Video' at 0x7fd6b6bb35e0>, '_initpath': '/library/metadata/93/children', '_details_key': '/library/metadata/94?checkFiles=1&includeExtras=1&includeRelated=1&includeOnDeck=1&includeChapters=1&includePopularLeaves=1&includeMarkers=1&includeConcerts=1&includePreferences=1', 'listType': 'video', 'addedAt': datetime.datetime(2018, 8, 29, 17, 55, 56), 'key': '/library/metadata/94', 'lastViewedAt': datetime.datetime(2018, 8, 30, 23, 56, 22), 'librarySectionID': None, 'ratingKey': 94, 'summary': 'The Americans is a period drama about the complex marriage of two KGB spies posing as Americans in suburban Washington D.C. shortly after Ronald Reagan is elected President. The arranged marriage of Philip and Elizabeth Jennings grows more passionate and genuine by the day, but is constantly tested by the escalation of the Cold War. Tensions heighten upon the arrival of a new neighbor, Stan Beeman, an FBI agent. ', 'thumb': '/library/metadata/94/thumb/1579807227', 'title': 'Pilot', 'titleSort': 'Pilot', 'type': 'episode', 'updatedAt': datetime.datetime(2020, 1, 23, 13, 20, 27), 'viewCount': 1, 'sessionKey': None, 'usernames': [], 'players': [], 'transcodeSessions': [], 'session': [], 'viewedAt': None, 'accountID': None, 'playlistItemID': None, '_seasonNumber': '1', 'art': '/library/metadata/10/art/1579807227', 'chapterSource': None, 'contentRating': 'TV-MA', 'duration': 4265248, 'grandparentArt': '/library/metadata/10/art/1579807227', 'grandparentKey': '/library/metadata/10', 'grandparentRatingKey': 10, 'grandparentTheme': '/library/metadata/10/theme/1579807227', 'grandparentThumb': '/library/metadata/10/thumb/1579807227', 'grandparentTitle': 'The Americans (2013)', 'guid': 'com.plexapp.agents.thetvdb://261690/1/1?lang=en', 'index': 1, 'originallyAvailableAt': datetime.datetime(2013, 1, 30, 0, 0), 'parentIndex': '1', 'parentKey': '/library/metadata/93', 'parentRatingKey': 93, 'parentThumb': '/library/metadata/93/thumb/1579807227', 'parentTitle': 'Season 1', 'rating': 7.8, 'viewOffset': 0, 'year': 2013, 'directors': [], 'media': [<Media:145>], 'writers': [<Writer:Joe-Weisberg>], 'labels': [], 'collections': [], 'chapters': [], 'markers': []}

Against season 10 of Curb Your Enthusiasm:

bash-5.0# ./cb-dump 
show: <Show:3566:Curb-Your-Enthusiasm>
season: <Season:3567:Curb-Your-Enthusiasm-s10>
episode: <Episode:3568:Curb-Your-Enthusiasm-s10e01>
{'_server': <PlexServer:https://p00.bluemagg>, '_data': <Element 'Video' at 0x7faaa20094f0>, '_initpath': '/library/metadata/3567/children', '_details_key': '/library/metadata/3568?checkFiles=1&includeExtras=1&includeRelated=1&includeOnDeck=1&includeChapters=1&includePopularLeaves=1&includeMarkers=1&includeConcerts=1&includePreferences=1', 'listType': 'video', 'addedAt': datetime.datetime(2020, 4, 15, 14, 7, 44), 'key': '/library/metadata/3568', 'lastViewedAt': None, 'librarySectionID': None, 'ratingKey': 3568, 'summary': 'Larry kicks off the new year with a new rival – Mocha Joe. Later, at a cocktail party hosted by Jeff and Susie, Larry gets roped into lunch plans and has a misunderstanding with a caterer.', 'thumb': '/library/metadata/3568/thumb/1586989710', 'title': 'Happy New Year', 'titleSort': 'Happy New Year', 'type': 'episode', 'updatedAt': datetime.datetime(2020, 4, 15, 17, 28, 30), 'viewCount': 0, 'sessionKey': None, 'usernames': [], 'players': [], 'transcodeSessions': [], 'session': [], 'viewedAt': None, 'accountID': None, 'playlistItemID': None, '_seasonNumber': '10', 'art': '/library/metadata/3566/art/1586989712', 'chapterSource': None, 'contentRating': 'TV-MA', 'duration': 2247804, 'grandparentArt': '/library/metadata/3566/art/1586989712', 'grandparentKey': '/library/metadata/3566', 'grandparentRatingKey': 3566, 'grandparentTheme': '/library/metadata/3566/theme/1586989712', 'grandparentThumb': '/library/metadata/3566/thumb/1586989712', 'grandparentTitle': 'Curb Your Enthusiasm', 'guid': 'com.plexapp.agents.thetvdb://76203/10/1?lang=en', 'index': 1, 'originallyAvailableAt': datetime.datetime(2020, 1, 19, 0, 0), 'parentIndex': '10', 'parentKey': '/library/metadata/3567', 'parentRatingKey': 3567, 'parentThumb': '/library/metadata/3567/thumb/1586989712', 'parentTitle': 'Season 10', 'rating': None, 'viewOffset': 0, 'year': 2020, 'directors': [], 'media': [<Media:4070>], 'writers': [], 'labels': [], 'collections': [], 'chapters': [], 'markers': []}

Ah, that’s one of the lazy loaded attributes and you need to ask for it it directly. Can you throw this at the end of the script?

print(f"Library Section: {episode.librarySectionID}")

Maybe it’s a bad lead to chase this param, but that’s what the original backtrace seemed to imply.