Play a video file from a remote Plex server on a Nvidia Shield

I’m trying to setup a new Plex media_player component. My server is hosted remotely. I’m using a subdomain (only) over https. I’m trying to play a video on my Nvidia Shield.

I put the following in my configuration file:

# Plex
media_player:
  - platform: plex

And the plex.conf looks like this:

{
    "plex.domain.com:443": {
        "ssl": true,
        "token": "RaNdOmToKeN",
        "verify": true
    }
}

In the logs I can see:

2018-06-22 13:33:07 INFO (SyncWorker_4) [homeassistant.components.media_player.plex] Discovery configuration done (no token needed)
2018-06-22 13:33:07 INFO (SyncWorker_4) [homeassistant.components.media_player.plex] Connected to: https://plex.domain.com:443

Yet if I go to services in the web interface and select the media_player.play_media service, and the json data below it doesn’t do anything.

{
  "entity_id": "media_player.living_room_shield",
  "media_content_id": {
     "library_name" : "Films",
     "video_name" : "Gandhi",
     "shuffle": "0"
  },
  "media_content_type": "VIDEO"
}

If I fire this call I see the Google Cast icon with a dark background. The logs give me this if I fire the above call:

2018-06-22T11:39:54.656048308Z 2018-06-22 13:39:54 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 139650835547304: Received {'type': 'call_service', 'domain': 'media_player', 'service': 'play_media', 'service_data': {'entity_id': 'media_player.living_room_shield', 'media_content_id': {'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}, 'media_content_type': 'VIDEO'}, 'id': 12}
2018-06-22T11:39:54.661458959Z 2018-06-22 13:39:54 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=media_player, service=play_media, service_data=entity_id=media_player.living_room_shield, media_content_id=library_name=Films, video_name=Gandhi, shuffle=0, media_content_type=VIDEO, service_call_id=139651847093832-11>
2018-06-22T11:39:54.661558605Z 2018-06-22 13:39:54 INFO (SyncWorker_3) [pychromecast.controllers] Not launching app CC1AD845 - already running
2018-06-22T11:39:54.661580113Z 2018-06-22 13:39:54 DEBUG (SyncWorker_3) [pychromecast.socket_client] Sending: Message urn:x-cast:com.google.cast.media from sender-0 to aa7dd01d-4bba-40a9-a6e8-ecf6b2b28ad2: {'media': {'contentId': "{'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}", 'streamType': 'BUFFERED', 'contentType': 'VIDEO', 'metadata': {}}, 'type': 'LOAD', 'currentTime': 0, 'autoplay': True, 'customData': {}, 'requestId': 9, 'sessionId': 'aa7dd01d-4bba-40a9-a6e8-ecf6b2b28ad2'}
2018-06-22T11:39:54.661663171Z 2018-06-22 13:39:54 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139651847093832-11>
2018-06-22T11:39:54.662238316Z 2018-06-22 13:39:54 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 139650835547304: Sending {'id': 12, 'type': 'result', 'success': True, 'result': None}
2018-06-22T11:39:54.668476070Z 2018-06-22 13:39:54 DEBUG (Thread-2) [pychromecast.socket_client] Received: Message urn:x-cast:com.google.cast.media from aa7dd01d-4bba-40a9-a6e8-ecf6b2b28ad2 to *: {'type': 'MEDIA_STATUS', 'status': [{'mediaSessionId': 7, 'playbackRate': 1, 'playerState': 'IDLE', 'currentTime': 0, 'supportedMediaCommands': 15, 'volume': {'level': 1, 'muted': False}, 'media': {'contentId': "{'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}", 'streamType': 'BUFFERED', 'contentType': 'VIDEO', 'metadata': {}}, 'currentItemId': 7, 'extendedStatus': {'playerState': 'LOADING', 'media': {'contentId': "{'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}", 'streamType': 'BUFFERED', 'contentType': 'VIDEO', 'metadata': {}}}, 'repeatMode': 'REPEAT_OFF'}], 'requestId': 0}
2018-06-22T11:39:54.668524109Z 2018-06-22 13:39:54 DEBUG (Thread-2) [pychromecast.controllers] Media:Received status {'type': 'MEDIA_STATUS', 'status': [{'mediaSessionId': 7, 'playbackRate': 1, 'playerState': 'IDLE', 'currentTime': 0, 'supportedMediaCommands': 15, 'volume': {'level': 1, 'muted': False}, 'media': {'contentId': "{'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}", 'streamType': 'BUFFERED', 'contentType': 'VIDEO', 'metadata': {}}, 'currentItemId': 7, 'extendedStatus': {'playerState': 'LOADING', 'media': {'contentId': "{'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}", 'streamType': 'BUFFERED', 'contentType': 'VIDEO', 'metadata': {}}}, 'repeatMode': 'REPEAT_OFF'}], 'requestId': 0}
2018-06-22T11:39:54.668535525Z 2018-06-22 13:39:54 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=media_player.living_room_shield, old_state=<state media_player.living_room_shield=idle; volume_level=1.0, is_volume_muted=False, media_content_id={'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}, media_position=0, media_position_updated_at=2018-06-22T13:39:17.290963+02:00, app_id=CC1AD845, app_name=Default Media Receiver, friendly_name=Shield, supported_features=21437 @ 2018-06-22T13:39:08.018262+02:00>, new_state=<state media_player.living_room_shield=idle; volume_level=1.0, is_volume_muted=False, media_content_id={'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}, media_position=0, media_position_updated_at=2018-06-22T13:39:54.666125+02:00, app_id=CC1AD845, app_name=Default Media Receiver, friendly_name=Shield, supported_features=21437 @ 2018-06-22T13:39:08.018262+02:00>>
2018-06-22T11:39:54.668545452Z 2018-06-22 13:39:54 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 139650835547304: Sending {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'media_player.living_room_shield', 'old_state': <state media_player.living_room_shield=idle; volume_level=1.0, is_volume_muted=False, media_content_id={'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}, media_position=0, media_position_updated_at=2018-06-22T13:39:17.290963+02:00, app_id=CC1AD845, app_name=Default Media Receiver, friendly_name=Shield, supported_features=21437 @ 2018-06-22T13:39:08.018262+02:00>, 'new_state': <state media_player.living_room_shield=idle; volume_level=1.0, is_volume_muted=False, media_content_id={'library_name': 'Films', 'video_name': 'Gandhi', 'shuffle': '0'}, media_position=0, media_position_updated_at=2018-06-22T13:39:54.666125+02:00, app_id=CC1AD845, app_name=Default Media Receiver, friendly_name=Shield, supported_features=21437 @ 2018-06-22T13:39:08.018262+02:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2018, 6, 22, 11, 39, 54, 666411, tzinfo=<UTC>)}}
2018-06-22T11:39:54.696304833Z 2018-06-22 13:39:54 DEBUG (Thread-2) [pychromecast.socket_client] Received: Message urn:x-cast:com.google.cast.media from aa7dd01d-4bba-40a9-a6e8-ecf6b2b28ad2 to sender-0: {'requestId': 9, 'type': 'LOAD_FAILED'}
2018-06-22T11:39:54.696517726Z 2018-06-22 13:39:54 DEBUG (Thread-2) [pychromecast.socket_client] Message unhandled: Message urn:x-cast:com.google.cast.media from aa7dd01d-4bba-40a9-a6e8-ecf6b2b28ad2 to sender-0: {'requestId': 9, 'type': 'LOAD_FAILED'}

So what’s going on? Where does this go wrong?

1 Like

I dont use plex but i get this kind of pychromecast error a lot from my nvidia shield.
It kinda fixes itself everytime i restart hassio tho

According to the component page that you pointed to you need { \“library_name\” : \“Films\”, \“video_name\” : \“Ghandi\”, \“shuffle\”: \“0\” } ie quote escaped JSON.

I assumed that was just for scripts, but I tried it with escaped JSON too:

{
  "entity_id": "media_player.living_room_shield",
  "media_content_id": "{ \"library_name\" : \"Films\", \"video_name\" : \"Gandhi\", \"shuffle\": \"0\" }",
  "media_content_type": "VIDEO"
}

and with a TV show:

{
  "entity_id": "media_player.living_room_shield",
  "media_content_id": "{ \"library_name\" : \"Series\", \"show_name\" : \"Game of Thrones\", \"season_number\" : 4, \"episode_number\" : 2, \"shuffle\": \"0\" }",
  "media_content_type": "VIDEO"
}

But I get the same result. I doubt I got a good connection with my Plex server. Is there any way to extensively debug this? Perhaps on the Plex side?

I don’t know any more than what is in the docs.

It does strike me though - why are you using chromecast when you could plug the shield directly into the TV via HDMI?

I appreciate the help.

I want to automate certain things and for that I need some connections with programs, like Plex. I won’t bore you with my use case. Also, this is just a way for me to learn how Home Assistant works.

Of course when I’m on the couch I’ll just use the Shield’s Plex app.

That doesn’t answer the question of why you are complicating the setup by including chromecast, but each to their own.

Then perhaps I don’t understand your question. Are you suggesting that there is another way to play files on the Shield? As far as I know this component uses the chromecast functionality from the NVidia Shield. There is no alternative to that.

I thought you were questioning why I would want to programmatically play files through Home Assistant.

No chromecast is not required to use plex client on an Nvidia Shield. Just plug the shield in to the tv with an HDMI cable.

Ah, so I did understand you correctly in the first place!

Chromecast is the only option for this component though. And that’s why I created this topic. My use cases aren’t relevant. They didn’t create this component for nothing. :smiley:

If anyone else had any success with this component and remote Plex servers I’d be happy to hear it.

Chromecast is not used anywhere in the documentation for this component, you pointed to the docs in your first post.

I think by having the server play to the shield which plays (or casts) to the chromecast is just over complicating things.

I’m going by this in the documentation:

Any (when casting)

I assume the devices mentioned don’t all have an API, so how would an external HA compenent be able to play something on the native app on the media player? While the Google cast API is mostly universal and has it all. Also, I’m doing exactly what is being said in the documentation and it fires the Chromecast functionality inside the Shield. It doesn’t look like it can do much more? Just explaining my logic here.

As I said I’m using this to learn HA in the first place. If I’m doing something wrong or I’m not understanding it correctly you could have told me how to do it right 5 posts ago. And for the sake of this topic lets assume I’m not able to control the Shield directly through a remote in the location it’s at. A part of the reason this component exists is to programmatically play or pause a video. So how do I do that from a remote Plex server?

Can I just clarify: Do you have the plex client on the shield?

Yes, I do have the Plex client on my Shield.

OK so when you manually (nothing to do with HA) play a movie on the shield client, how does it play on the TV, casting or via HDMI?

I’m going along with you. When I’m on the couch I use the Plex app present on the Shield. The Shield is connected to HDMI and it plays through that. No casting involved.