Plex binding for OH3 | Will it be ported?

Hey,

so here is what I did: I have two things so far, the bridge and a player (plexamp on linux). Player and Server are on same computer, which is different from my openhab installation.

  1. Enabling Bridge:

2021-02-25 10:02:11.441 [DEBUG] [ex.internal.handler.PlexApiConnector] - Plex Api fetched.  Found configured PLEX server in Api request, applied. 

2021-02-25 10:02:11.454 [DEBUG] [ex.internal.handler.PlexApiConnector] - Connecting to WebSocket
2021-02-25 10:02:30.601 [DEBUG] [x.internal.handler.PlexPlayerHandler] - Initializing PLEX player : 9215b0eb-3341-42c1-832e-4f9a3d4923b6

2021-02-25 10:02:30.603 [WARN ] [x.internal.handler.PlexServerHandler] - Bridge: Monitor handler was initialized for plex:player:265e8db400:17e35f31f1 with id 9215b0eb-3341-42c1-832e-4f9a3d4923b6
  1. Enabling Thing (Player)

2021-02-25 10:02:30.591 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'plex:player:265e8db400:17e35f31f1' changed from UNINITIALIZED (DISABLED) to INITIALIZING

2021-02-25 10:02:30.603 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'plex:player:265e8db400:17e35f31f1' changed from INITIALIZING to UNKNOWN

2021-02-25 10:02:32.505 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'PlexServer_CurrentPlayers' changed from 0 to 1
  1. Starting playback on player

2021-02-25 10:04:42.845 [WARN ] [x.internal.handler.PlexServerHandler] - An exception occurred while polling the PLEX Server: 'null'


2021-02-25 10:04:42.850 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'plex:server:265e8db400' changed from ONLINE to OFFLINE

2021-02-25 10:04:42.855 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'plex:player:265e8db400:17e35f31f1' changed from UNKNOWN to OFFLINE (BRIDGE_OFFLINE)

Edit: Bridge thing goes offline as soon as playback is start (device doesnt matter, tried with plexamp on android and on linux).

Setup:
PMS-Version: 1.21.3.4046
Openhab-Version: openHAB 3.0.1
JAR Binding: org.openhab.binding.plex-3.1.0-SNAPSHOT.jar v0.8 (also tested 0.6)

I’m guessing that when it goes offline it’s status is also “Plex is not returning valid session data”?

No, its simply “Offline”.

I just installed another plex server on the same machine as OH3 instance and still get same result.

Some input on my plex setup:
I have more than one user setup, the user that I used to get the token with is admin and has a passcode enabled. I tried adding the ip from OH3 instance to “trusted domains” in network options but didnt help.

Have to admit that I never got the old Plex-Binding for OH2 running (OH3 was just about to be released when I started taking an interest).

So the token is fetched from plex.tv, not your local machine. What that request does is list out your instances as well as provide the token. To do this, it uses your username/password. If the username/password that you are putting into the binding is a “user” of plex and not the admin for the plex.tv account you’re likely going to have problems.

Once that token is fetched, then the binding connects to the actual machine running plex. Possibilities here I would think are the IP that you’re putting into the binding doesn’t match the IP that is configured for PLEX. At this point, I’m more interested than anything and would love to help you get this going. Let me add in some more debug here and post a version for you to try.

Hey,

That would be great!

Most probably the mistake is sitting in front of the computer as usual. :slight_smile:

Thank you for this rewrite. I will be testing this. It was one of the things that I was missing.

Also, I have the exact scenario, you are describing with multiple devices:
Smart-TV and then via HDMI switch (Hue Sync) a Smart-BluRay Player and a Chromecast connected. So it shall be interesting.

/M

I can’t seem to get the bridge to work at all.

Binding: v0.8
PWS: 1.20.0.3181 and 1.22.0.4163 (I tried to downgrade in an attempt to get it working)
OpenHAB: 3.1.0M2

I have extracted both hostname and token, even tried using the IP. It has to be said though, that the server is not on my local network, but remote. I’m not sure, if that is an issue.

Debug output from the openhab.log:

2021-03-14 18:33:28.889 [WARN ] [ex.internal.handler.PlexApiConnector] - An exception occurred while fetching API :'null:{}' java.lang.NullPointerException: null at org.openhab.binding.plex.internal.handler.PlexApiConnector.getApi(PlexApiConnector.java:182) [bundleFile:?] at org.openhab.binding.plex.internal.handler.PlexServerHandler.initialize(PlexServerHandler.java:106) [bundleFile:?] at org.openhab.core.thing.binding.BaseThingHandler.handleConfigurationUpdate(BaseThingHandler.java:107) [bundleFile:?] at org.openhab.core.thing.internal.ThingRegistryImpl.updateConfiguration(ThingRegistryImpl.java:94) [bundleFile:?] at org.openhab.core.io.rest.core.internal.thing.ThingResource.updateConfiguration(ThingResource.java:504) [bundleFile:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?] at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) [bundleFile:1.0.9] at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) [bundleFile:1.0.9] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) [bundleFile:1.0.9] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) [bundleFile:1.0.9] at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) [bundleFile:1.0.9] at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) [bundleFile:1.0.9] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [bundleFile:1.0.9] at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [bundleFile:1.0.9] at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) [bundleFile:1.0.9] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:237) [bundleFile:1.0.9] at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) [bundleFile:3.1.0] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) [bundleFile:1.0.9] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813] at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [bundleFile:?] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813] at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?] at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813] at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813] at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813] at java.lang.Thread.run(Thread.java:829) [?:?]

Another quite peculiar thing is, that the Plex Binding is not listed under Bindings. But yet, when I want to add a Plex Bridge etc. it is listed there.

/M

Anyone else getting a problem with the binding since doing an update to Openhab? The binding isn’t starting, and when I try to start it manually, I see this error:

Error starting bundle 262: Could not resolve module: org.openhab.binding.plex [262]
Unresolved requirement: Import-Package: org.apache.commons.lang; version="[2.6.0,3.0.0)"

Edit: 7th April 2021 - should have been clear this is when I used the latest Milestone build. Dropped back to Stable and all OK again.

Trying out the 0.8 Binding on Plex Server: 1.22.1.4275, no Plex Pass. - vanilla out of the box configuration and observing odd behavior on OH3 Plex Bridge Thing. (binding added manually to addons folder)

The bridge goes from “Online” To “Offline” when a player starts - Bridge shows error: Plex is not returning valid session data. And then Offline to Online when the player stops (if paused it does not go to online, has to be stopped)

I have entered username and password, doesn’t seem to do anything until I add a x-token which I got from “view xml” on a library item. Deleted all player monitor things, still same online then offline behavior.

Clarification request on x-tokens : The token you get from visiting via: app.plex.tv is one thing, the token from localnetworkIP:32400 is another - which token should one use? ( I tried both same result)

The log doesn’t say much:

[ab.event.ThingStatusInfoChangedEvent] - Thing ‘plex:server:26ff5b0919’ changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Plex is not returning valid session data.

[ab.event.ThingStatusInfoChangedEvent] - Thing ‘plex:server:26ff5b0919’ changed from OFFLINE (COMMUNICATION_ERROR): Plex is not returning valid session data to ONLINE

What would anyone like me to try?

I previously had monkeyed around with .1 release and had things and items from that, that I re-assigned to the new binding - probably a bad idea.
Deleted all things and items related to plex, restarted OH3 and recreated them (via UI) its working now, picking up the play pause stop events on players within 0.5 sec or so and most importantly staying online !

I had to use the x-token from the app.plex.tv browsing of your library, not the one from direct browsing you local plex install ip. Plex pass not required.

Great work @bhomeyer , Thank you !

Hi, just been playing around with a new OH3 install to see if I can migrate everything over from 2.5 to 3 and stumbled upon this binding for Plex.

I seem to be able to get it working mostly, but I seem to be hitting a timeout issue when connecting to the Plex server

[DEBUG] [lex.internal.handler.PlexApiConnector] - java.util.concurrent.TimeoutException: Total timeout 2000 ms elapsed
java.io.IOException: java.util.concurrent.TimeoutException: Total timeout 2000 ms elapsed

If upon first connection it fails, it never seems to retry and just sits in error state, but if it succeeds everything seems to work fine. Are you able to add a parameter to increase the timeout to see if it helps things (my plex server can be a bit slow at times)?

Thanks for all your work on this binding, I’ll keep playing now and see if I find any other bugs

I had the same issue with Milestone.
Though switching back appears to still be an issue as of today
 I’m getting a null pointer exception error


my openhab.log

2021-05-28 11:38:44.801 [WARN ] [ex.internal.handler.PlexApiConnector] - An exception occurred while fetching API :'null:{}'
java.lang.NullPointerException: null
	at org.openhab.binding.plex.internal.handler.PlexApiConnector.getApi(PlexApiConnector.java:182) [bundleFile:?]
	at org.openhab.binding.plex.internal.handler.PlexServerHandler.initialize(PlexServerHandler.java:106) [bundleFile:?]
	at jdk.internal.reflect.GeneratedMethodAccessor90.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]

my plex.things:

Bridge plex:server:plexrServer "Bridge Plex : Plex" [host="<redacted>", password="<redacted>", token="<redacted>", refreshRate=5, username="<redacted>" ]
{
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
	Thing plex:player:<redacted> "<redacted>" [playerID="<redacted>"]
}

I’m currently running on OpenHAB 3.0.2 and Plex 1.23.1.4571
Assistance would be appreciated

And on a side note, I’m also finding this in my log (but it’s been there when it was working so, lower priority):

Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>

Thanks in Advance,
Aaron

Hi @bhomeyer thanks for your work on the migration of this binding.
I wanted to try it on a recent snapshot, however some dependencies seem to be broken currently.
I was wondering what your plans are with this binding.


300 │ Installed │  80 │ 3.1.0.202102201422    │ openHAB Add-ons :: Bundles :: Plex Binding
openhab> bundle:start 300
Error executing command: Error executing command on bundles:
        Error starting bundle 300: Could not resolve module: org.openhab.binding.plex [300]
  Unresolved requirement: Import-Package: org.apache.commons.lang; version="[2.6.0,3.0.0)"

@bhomeyer , me too! This binding is great but doesn’t work on OH3.1. Luckily, I managed to downgrade to 3.0.2-1 where it works. :slight_smile:

OK, I’ve found out why this is: org.apache.commons has been removed from the core API (as per Removal of dependency on 'org.apache.commons.*' · Issue #7722 · openhab/openhab-addons · GitHub) so the binding needs to be re-created using Java methods
 If @bhomeyer is no longer updating the binding :cry:, can anyone else help?

1 Like

I can confirm this is the issue with v0.8 of the binding and newest version of OH3.

I can confirm the same (3.1). I’m forced to use another 2.5-10 OH with the old 1.x binding. There is a similar problem/error with the Chamberlain binding, so hopefully it’s not a huge problem to fix long term.

This should work in 3.2 without issue : Release OH3 PLEX binding · bigbasec/openhab-addons · GitHub

Not 100% yet, though should function fine.

1 Like

Thank you, thank you @bhomeyer ! This works fine and I’ve just successfully upgraded to 3.1.0. :grinning:

1 Like

How do I get this addon installed? I placed it in the addons folder but it doesn’t show up.