Using HASS to play a Plex playlist

Hello team

I have been really happy with some progress lately, getting a custom dash to play a selection of radio stations to a selection of remote players - and now I want ti throw some plex playlists in the mix.

According to documentation we can use media_player.play_media to play media on a ‘connected’ client, using the following detail:

  • entity_id - media_player.theater_plex
  • media_content_id - { \“playlist_name\” : \“The Best of Disco\” \“shuffle\”: \“0\” }
  • media_content_type - PLAYLIST

I have noticed that the template example above is missing the comma between the playlist_name and shuffle entries. I have included that but keep getting the same error.

NOTE: The JSON requires the quotation charaters be escaped, hence the backslashes:

2018-06-21 17:43:25 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=media_player, service=play_media, service_data=entity_id=media_player.surf_kodi, media_content_id={ \"playlist_name\" : \"Chilled\", \"shuffle\": \"1\" }, media_content_type=playlist, service_call_id=139739065784192-410>
2018-06-21 17:43:25 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall media_player.play_media: entity_id=['media_player.surf_kodi'], media_content_id={ \"playlist_name\" : \"Chilled\", \"shuffle\": \"1\" }, media_content_type=playlist>
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/", line 1007, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/src/app/homeassistant/components/media_player/", line 415, in async_service_handler
    await getattr(player, method['method'])(**params)
  File "/usr/src/app/homeassistant/components/media_player/", line 245, in wrapper
    yield from func(obj, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jsonrpc_async/", line 45, in send_message
    return message.parse_response(response_data)
  File "/usr/local/lib/python3.6/site-packages/jsonrpc_base/", line 181, in parse_response
    raise ProtocolError(code, message, data)
jsonrpc_base.jsonrpc.ProtocolError: (-32602, 'Invalid params.', {'error': {'code': -32602, 'message': 'Invalid params.'}, 'id': 7416810882365111645, 'jsonrpc': '2.0'})

PS I get a different error now. I think the change was entering the media_content_type in capitals (PLAYLIST) but I can’t be sure. The subsequent error (RE media_content_id) reads: “ValueError: invalid literal for int() with base 10:” no matter what I enter for that field. Which leads me to wonder if the actual requirement in the PLEX API has changed, and is now an integer - such as the playlist ID.

If I enter the playlist ID (a 5 digit integer) I then get ‘Received value does not match any of the union type definitions’.

Safe to say the Plex music playlist option is broken?

I’m also experiencing this problem - has anyone found the solution or workaround? I resorted to creating a shell script, but it is flaky and probably still needs some more work to rely on regularly.

I never got it to work.

I ended up reverting back to my Synology Audio Station for playing stored music - the web APIs allow for some very decent automation and control

The combination of Plex + Chromecast needs work from the Plex devs, and it’s taken so long I wonder if they every will.

Perhaps any update?

I made a few fixes to play_media in 0.100 for Plex media_player devices as the service was semi-broken for quite a while. I’m not totally sure if the problems in this thread are similar, but if anyone is willing to share more details I can try to take a look.

It should probably be noted in the documentation, but you can only control Plex clients from HA when both the Plex server and target Plex client are on the same subnet. There are workarounds, but they’re not super trivial.

The backtrace in the original post looks like it’s targeting a Kodi entity in HA, not a Plex one.

Did the syntax change with 0.100? I’m trying to get a google home mini to play a plex playlist, but nothing is working. It just stays quiet.

@nr_005 the syntax actually became slightly more permissive, but previously working payloads should still work as-is.

Did the media_player.play_media command and the specific targeted Plex client work previous to 0.100? Can you share the command you sent?

Thanks for getting back to me so quick.
I actually never tried it before, so I’m not sure if it would have worked before 0.100.

For testing purposes I’m using the services tab in the webinterface and use the following service data:

entity_id: media_player.plex_chromecast
media_content_id: "{\"playlist_name\": \"Random\", \"shuffle\": \"1\"}"
media_content_type: playlist

When I hit “call service” it does nothing. No reaction from the mini and not even any errors in the log.

Please try to start a specific song or movie. If that works, we can figure out what’s different about using playlists.

Also, it looks like it requires the media_content_type to be in all caps (“PLAYLIST”).

I tried

entity_id: media_player.plex_chromecast
media_content_id: "{\"library_name\": \"Musik\", \"artist_name\": \"Tool\", \"album_name\": \"Fear Inoculum\", \"track_name\": \"Pneuma\", \"shuffle\": \"0\"}"
media_content_type: MUSIC

It behaved exactly the same. No errors in the log, but no reaction from the home mini. It doesn’t seem to work at all for me. I’m using secure connections in plex, in case that matters.

Are you able to play/pause this player from the UI via a media player card?

Can you look at the attributes for the media_player.plex_chromecast entity and see what supported_features shows? If it’s 0 then it cannot be controlled. If it is 0 then the usual cause is the Plex server and client being on different networks/subnets.

I just set the lovelace card up to test this. I’ve got plex set to show all controlls, but none of them work.

It says: supported_features: 21309
Both server and client are on the same network. The Plex server runs in a docker container but is set to use the host network, so I figured it shouldn’t be an issue.

Same subnet, though? That matters as Plex client/server discovery is done via UDP broadcast. That discovery is necessary to set up Plex client control.

Also, using the “show all controls” is an old hack that doesn’t seem to have any real value. I should probably remove it as it will make the supported_features lie to you, making troubleshooting more difficult. If you disable that feature I’d bet it would show 0.

Damn, you’re right. After changing it now it shows supported_features: 0. The same goes for the Plex app on my PC. So does that mean these players can’t be automated, or is something wrong with my setup?
Everything is on the same subnet btw.

I just tried out plex web in chromium, since it shows up with supported_features: 21309 in hass, but still no luck. The following service data for play_media does nothing:

entity_id: media_player.plex_chrome
media_content_id: "{\"library_name\": \"Musik\", \"artist_name\": \"Tool\", \"album_name\": \"Fear Inoculum\", \"track_name\": \"Pneuma\", \"shuffle\": \"0\"}"
media_content_type: MUSIC

Not sure it matters, but have you disabled GDM discovery on your Plex server?

GDM discovery is enabled on my server. The only thing I changed in the network settings of the Plex server is to require secure connections.