PlexDevices - Custom Media Player Component

Do you have an example of another component doing that?

Let me make sure I understand - things you directly play from the watch later queue do not show up. If that’s the case, send me (don’t post here as I’m not sure if that page has any sensitive data in it) the contents of http ://IP:PORT/status/sessions (where ip and port are the IP address and network port of your plex server)? Make sure the item is playing from the watch later queue when you pull up that page and send me the contents. Thanks

I’m using it in a component that Im writing, and it works there.

Did a search for it in home assistants GitHub project: https://github.com/home-assistant/home-assistant/search?utf8=✓&q=device_state_attributes&type=

Cool, I just want to be sure that’s the right way to do it (as you know I was doing group things in my component which I had to yank because it was not the right way to do it).

I understand. In this case many components seem to use it the same way though.

1 Like

OK. I have sent you the content. It is confirm that it only appears when the video is played from Rasplex. I have tried with Plex Web and Plex Android and both are empty.

Thanks, I’ll take a look. Not all plex clients support watch later - for example my plexconnect apple tv’s do niot. So if I get this working, it will only be on clients that support it.

Btw - I got the username working.

1 Like

I know. But my kids like to watch Youtube videos added to the Watch Later and they can keep on repeating the same videos for gazillions of times without ever getting bored. Since I am using Rasplex on my TVs, I really hope that you can implement both support for Watch Later and User so that I can implement some sort of time control using HA. I already have some idea going on in my head.

That’s great. Can’t wait to see this in the next version.

Those videos are actually ‘clips’, which was an unsupported feature in the previous ha plex component. I added some compatibility for it but it depends on how the clip presents itself (some look like a tv episode, some look like garbage - there seems to be no rules on how to structure a clip from the provider perspective). I’ll test with some of the YouTube samples I see in your config and get back to you.

I have a few plex clients I can test from but I won’t be able to match your setup. Hopefully one of them will let me reproduce what you’re seeing. So far: Playing Watch Later via web safari client shows nothing under Now Playing or via http://server_ip:32400/status/sessions. There is no Watch Later on the iPhone app and no watch later on on PlexConnect Apple TV’s. Using the shield as a client produces the same results on the web safari client. Going to test with the shield as a plex server.

No good with shield as plex server - nothing will display the content. What I think is happening is my plex servers (and most others) redirect the client to play the watched later video directly where rasplex plays them directly. Unfortunately I only have one production PI and cannot run rasplex to test. However I’m going to forget this watched later thing and see if I can emulate what you are seeing another way (maybe through channels) - as ultimately I just have to get the component to recognize youtube clips as valid media (you’ll have to stick to a client like rasplex that will provide the component with the data needed).

@JesseWebDotCom - First this is an AMAZING upgrade. Thank you so much for the contributions.

I had one quick question - what is the point of ‘shuffle’ when you have to pass in a season/episode for the TV/EPISODE PLAY_MEDIA? What is it going to shuffle?

We like to turn on some shows for background noise, and usually just ‘shuffle’ a show or a season. I’ve tried to accomplish this with the PLAY_MEDIA, but if I don’t provide a episode/season, it fails (as expected since it tries to find SXXEYY).

Is this something that is possible today, or could be updated by chance?

I have shared the time limit automation I told you before at Plex media player time limit control automation (parental control)

Can’t wait to put it in good use. The missing piece is the username in the attributes. I am wondering is it possible to share the changes you made to the component that support username to me first so that I can use it as custom component until the official version is released.

I plan to stick to Rasplex for long term. It seems far superior than any players out there including the official Plex Media Player.

Sure - I’ll post that when I get home tonight

1 Like

Just add this to the end of your custom component:

    @property
    def device_state_attributes(self):
        """Return the scene state attributes."""
        attr = {}
        attr['media_content_rating'] = self._media_content_rating
        attr['session_username'] = self._session_username
        attr['media_library_name'] = self._app_name

        return attr

Thanks.

Since https://github.com/JesseWebDotCom/home-assistant-configuration/blob/master/custom_components/media_player/plexdevices.py is no longer available, I went to get a copy of plex.py from /usr/local/lib/python3.4/dist-packages/homeassistant/components/media_player and paste it to /home/pi/.homeassistant/custom_components/media_player.

From there, I added the code to the last line and restart HA. The Plex media player component couldn’t load and gave this error in the log…

ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 359, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 215, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 247, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "/home/pi/.homeassistant/custom_components/media_player/plex.py", line 862, in device_state_attributes
    attr['media_content_rating'] = self._media_content_rating
AttributeError: 'PlexClient' object has no attribute '_media_content_rating'

Download, rename to plex.py, and place in your custom_components/media_player folder:
plex.py.yaml (31.7 KB)

thank you so much! that works marvelously. now, my kids gonna hate me more.

I also added the rating so you can alert or stop when they watch media rated higher than you want them to

1 Like

Thanks. That can be useful. You can make it even better if you can include genre in there as well.