openHAB2 + Plex

Never tried that, will have to check what the status updates look like. Would be nice if this was working indeed.

I changed my openhab.cfg plex:host back to a hostname (nas.local), not IP address (10.0.1.6), applied your latest test JAR: https://www.dropbox.com/s/dsp3h6t94vjvuwq/org.openhab.binding.plex_1.9.0.201612161814.jar?dl=0, and restarted the openHAB 1.8.3 server. Everything started up correctly, but I did notice this difference in the log before and after:

updated to latest test JAR (while plex:host=10.0.1.6 still in effect):

2016-12-17 12:24:12.648 [INFO ] [.service.AbstractActiveService] - Plex Refresh Service has been shut down
2016-12-17 12:26:17.068 [INFO ] [.service.AbstractActiveService] - Plex Refresh Service has been started
2016-12-17 12:26:18.114 [INFO ] [.b.plex.internal.PlexConnector] - Plex websocket connected to 10-0-1-6.2cea3xxxxxxec8f234b5c5d.plex.direct:32400

Restarted server after changing to plex:host=nas.local (which resolves to 10.0.1.6):

2016-12-17 12:28:21.810 [INFO ] [.b.plex.internal.PlexConnector] - Plex websocket connected to 10-0-1-7.2cea3d624fb24xxxxx4b5c5d.plex.direct:32400

This difference in IP address may be due to the PMS box being a Synology DiskStation with two interfaces onto the private network, but pinging nas.local always seems to resolve to 10.0.1.6.

Iā€™m just sharing this in case it doesnā€™t look right to you, @idserda.

Thatā€™s odd. Could nas.local somehow resolve to 10.0.1.7 on your openHAB machine? Or is 10.0.1.6 listed multiple times with different hostnames in https://plex.tv/api/resources?includeHttps=1? Not really a concern but a bit strange :slight_smile:

The results from https://plex.tv/api/resources?includeHttps=1 show that my PMS is listening on both interfaces 10.0.1.6 and 10.0.1.7 and lists my public IP address listening on a different port. Hostnames are not listed at all. The openHAB server machine only seems to resolve nas.local to 10.0.1.6, but I suppose itā€™s possible that itā€™s configured to answer either address. In any case, it doesnā€™t show as an error, and doesnā€™t seem to be either.

Thanks for having a look.

Even if I put the plex binding log to DEBUG, I didinā€™t see any NotificationContainer in log when I played media on remote serverā€¦ It looks more difficult than expectedā€¦

I had the exact same issue with OH 1.8.1 - neither of the 2 jars linked appeared to work at all. I added <logger name="org.openhab.binding.plex" level="DEBUG" /> in logback.xml and I got no output in the console whatsoever (both plex:host=... and plex:token=... were set properly in openhab.cfg)

This led me to believe there was an issue with the jars so I tried the following:

  1. cloned @idserda openhab repository,
  2. checked out his plex-pmsupdate branch
  3. ran mvn package from within the openhab/bundles/binding/org.openhab.binding.plex directory
  4. copied the resulting target/org.openhab.binding.plex-1.9.0-SNAPSHOT.jar to my OH installation
  5. Restarted and everything was working as before

The only issue I can see with this binding (and maybe itā€™s unavoidable) is it appears to require an internet connection when starting up. Since itā€™s querying https://plex.tv/api/resources on startup, if thereā€™s no internet connection, wouldnā€™t the binding fail to configure itself properly?

If so, I wonder if thereā€™s an alternative way. I would think most users who run this binding are running Plex locally so I feel like this binding should work regardless of an active internet connection.

Exacty my problem is I have no Notification when I played something on a REMOTE server with shared library :slight_smile:

I upgraded my PMS to 1.3.2.3112 and then again to 1.3.3.3148 and both appear to work as expected for me.

Hello!

Should I use .jar from the Dropbox link, or I can download it from the cloudbees repository? Iā€™m having some problems with Plex MS and I know I should update it, so, I will have to use a new version of the binding.

Best regards,
Davor

Yes, because this pull request is still waiting for your (collective) feedback before being merged.

Hello!

Thank you for the quick reply. Iā€™ll test it tonight and post my feedback.

Best regards,
Davor

Been using the plex binding for a week now, and not encountered any problems. HABPanel shows the details nicely, including the cover art.

My only comment is, when status is stopped, Title still contains the last thing that was playing, rather than changing to something like . Is it possible to submit as a feature request? If so, where?

Hello!

Iā€™ve tried a new version with Plex Media Server v1.3.3.3148 and, so far, everything is working well.

@Darren_Poulson As far as Iā€™m aware, it was working the same way from the beginning. Not the most elegant solution, but you could replace title to something else in rules, when status changes to Stopped.

Best regards,
Davor

Yes, tried this over the weekend, there is no update about playing media on a remote server coming from the local server youā€™re connected to. Canā€™t see a solution for now, but maybe we can connect to the client directly, find out the address of the remote server and connect to that somehow. Tried connecting to the (shared) remote server with the Plex token but that doesnā€™t seem to work.

Iā€™ll create a pull request for this. Think I will clear at least these properties when the status is stopped: title, type, playback/cover, playback/progress, playback/endTime.

Yes, that would be a problem :slight_smile: And if you have Plex Home enabled and configured a username/password there is an additional call to plex.tv to request a token.

Do more people feel this is an issue? If you have not enabled Plex Home and have not set ā€˜Secure connectionsā€™ to ā€˜requiredā€™ the binding could in theory work without an internet connection. Should there be support for this?

@MacFly Have you tried the latest jar in this thread? Does it work for you too, apart from the issue with playing media from a remote server? If everything is okay I would like to have the pull request merged.

1 Like

Sorry for the delay, tested your last org.openhab.binding.plex_1.9.0.201612161814.jar and it work flawlessly !

I will try to dig a bit more with the shared library, Iā€™ll post feedback if I find something.

Again thanks you for your work !

So ā€¦ didnā€™t found anything useful on the client side APIā€¦
Got this link with useful info : https://github.com/plexinc/plex-media-player/wiki/Remote-control-API
But no luck ATM when trying to play with timeline/poll, etc ā€¦

On the server side, I found that fetching this URL https://plex.tv/pms/server.xml return the list of servers, my own and the shared servers. The first is my own server (owned=ā€œ1ā€) and the second is my shared server.

<MediaContainer friendlyName="myPlex" identifier="com.plexapp.plugins.myplex" machineIdentifier="ec5..7b2" size="7">

<Server name="ownserver" address="83.148.147.57" port="32400" version="1.3.2.3112-1751929" scheme="http" host="83.148.147.57" localAddresses="192.168.0.1" machineIdentifier="a4655..f42d" createdAt="1480619966" updatedAt="1482485592" owned="1" synced="0"/>

<Server name="remoteserver" address="144.6.23.205" port="32400" version="1.3.3.3148-b38628e" scheme="http" host="144.6.23.205" localAddresses="192.168.50.1" machineIdentifier="a42d...dc088" createdAt="1473242467" updatedAt="1482493210" owned="0" synced="0" accessToken="dMjDz...HaZ8s" sourceTitle="remoteserver" ownerId="7181376" home="0"/>

</MediaContainer>

I noticed the ā€œaccessTokenā€ feature for my shared server, so Iā€™ve got some hope but when Iā€™m trying to reach https://144.6.23.205:32400/status/sessions?X-Plex-Token=dMjDz...HaZ8s it return me a 401 Unauthorizedā€¦

No more luck when trying to reach the Websocket with this accessToken.

So it seem we need to manage to get another token with this accessToken or something else.

Finally, it seem that the Client side API is the good way :

Based on the link previously posted Iā€™ve played with timeline polling.

A GET request directly to the player with good header provide useful information :
http://PLAYER-IP:3005/player/timeline/poll?wait=0&commandID=1
headers :
X-Plex-Client-Identifier 3e4e9b32-d366-47e2-a378-03044e9d1338
X-Plex-Device-Name openHAB

( took openhab2 registration values from plex.tv/devices.xml )

And there is the result :

 <?xml version="1.0" encoding="utf-8" ?>
 <MediaContainer location="fullScreenVideo" commandID="1">
 <Timeline seekRange="0-0" state="stopped" time="0" type="music" />
 <Timeline address="187-9-209-19.11647b51bce....4fee644eb2.plex.direct" audioStreamID="11896" containerKey="/playQueues/177" controllable="playPause,stop,shuffle,repeat,volume,stepBack,stepForward,seekTo,subtitleStream,audioStream" duration="5325320" guid="com.plexapp.agents.imdb://tt1700841?lang=fr" key="/library/metadata/2220" location="fullScreenVideo" machineIdentifier="a42d734d....7328ed8dc088" mute="0" playQueueID="177" playQueueVersion="1" port="32400" protocol="https" ratingKey="2220" repeat="0" seekRange="0-5325320" shuffle="0" state="playing" subtitleStreamID="-1" time="990773" type="video" volume=100" />
 <Timeline seekRange="0-0" state="stopped" time="0" type="> photo" />
 </MediaContainer>

It provide Time Range, Actual playing time, IMDB link, and the key to the library metadata ā€¦ when playing media on my local server as on my shared one, it is all we need :slight_smile:

I think there is a better way for production to connect to this API with the /player/timeline/subscribe methodā€¦ or with the wait=1 option.

Getting Media MetaData from the remote server with the accessToken got from the previous post works !!! (from the server.xml list)

So it seem that we have all we need here, but it will force you to rewrite all the way you get playerā€™s notificationsā€¦ :frowning2:

I hope it will help ā€¦