openHAB2 + Plex

Hi @idserda ! happy new year :slight_smile:
Can I ask you if you think work in the way described before ?
This is just to know if I must do my setup in another way, no pressure at all :slight_smile:

Great stuff, thanks! Looks like we can use this API indeed. It does rely on the client being reachable on the given ip/port however. Do you know if this works for all clients, so also on Android and iOS? Probably won’t work for web clients I guess. I’ll try to create a proof of concept version for this method anyway!

Glad to read that !

Unfortunately, I just checked and the android app doesn’t listen to port 3005 or 32400. I think only the Plex Media Player allow to be remote controlled but not the Plex App.

Might be a different port, have you checked https://plex.tv/api/resources for the correct port?

You’re right,
Android app are listed in resources and listen to port 32500, timeline api works too.

For the Plex Web, the IP returned in the Connection protocol tag is the server IP address so, as you said, It probably won’t works or not in the same way.

Hello!

@idserda If you are going to change current binding mechanism, please take into account that your binding currently works really good with Samsung Plex app, which is pretty specific.

Best regards,
Davor

Yes good point. The ‘direct’ connection to the client should be optional somehow.

HI, I have been using Idserda’s dropbox linked .jar file with openhab2 quite successfully until i updated to the latest official release of OH2 yesterday. Now I’m experiencing similar issues where I can send commands to the plex player but the status is always showing as STOPPED. Despite partially working, I’m getting this in the logs:

13:41:39.739 [WARN ] [.binding.plex.internal.PlexConnector] - Server not found in plex.tv device list, setting URI from configured data. Try configuring IP-address of host.

However, play, stop and pause buttons still work but just don’t get a status update. I also get the usual ‘Plex item PlexTVPlay bound to client
’ on all of my items showing in the logs.

Can anyone offer any insight?

Many thanks.

Just in case 

I’ve got the same problem in the past and I noticed that I have two version of Plex binding running in Openhab.

Did you check that in the Karaf console ? ( with “bundle:list | grep Plex” )

Thanks, MacFly, I just checked and only one entry is showing:
225 | Active | 80 | 1.9.0.201612161814 | openHAB Plex Binding

Thanks

Just an update on my issue. I decided to update to latest snapshot (2.1.0). Cleared caches etc. Plex binding working fine now. Not sure if it was the update to the latest snapshot or clearance of cache but working now.
Thanks

Hi,
I cant get it to work either - I did some tests in the past with no success, so i decided to kind of start all over again. Here is what I did:

  • removed configuration for plex in services, using PaperUI instead
  • removed items file, want to start with this again once plex is running fine and not logging any errors anymore
  • stopped openhab
  • cleaned tmp and cache directories
  • started openhab again

I’m running openhab on a different virtual machine than plex, openhab IP is enabled in plex server setting, and i checked my token multiple times - it seems correct.

I’m on 2.1.0-SNAPSHOT Build #767

openhab> bundle:list | grep Plex
203 | Active   |  80 | 1.10.0.201701300211   | openHAB Plex Binding

in openhab.log I get the following messages:

2017-01-30 18:10:43.219 [DEBUG] [org.openhab.binding.plex            ] - BundleEvent STARTING - org.openhab.binding.plex
2017-01-30 18:10:43.277 [DEBUG] [.binding.plex.internal.PlexActivator] - Plex binding has been started.
2017-01-30 18:10:43.278 [DEBUG] [org.openhab.binding.plex            ] - BundleEvent STARTED - org.openhab.binding.plex
2017-01-30 18:10:43.282 [DEBUG] [org.openhab.binding.plex            ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/command/*, service.pid=org.openhab.plex, port=32400, token=<mytoken>, refresh=5000, host=KGTec1NAS, component.name=org.openhab.binding.plex.binding, component.id=217, service.id=361, service.bundleid=203, service.scope=bundle} - org.openhab.binding.plex
2017-01-30 18:10:43.288 [DEBUG] [ab.binding.plex.internal.PlexBinding] - Plex config, server at KGTec1NAS:32400
2017-01-30 18:10:43.663 [DEBUG] [.binding.plex.internal.PlexConnector] - Server found, version 1.3.3.3148-b38628e, api level v2
2017-01-30 18:10:43.833 [DEBUG] [.binding.plex.internal.PlexConnector] - Connecting web socket to Plex
2017-01-30 18:10:43.838 [DEBUG] [org.openhab.binding.plex            ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.plex.PlexBindingProvider}={component.name=org.openhab.binding.plex.genericbindingprovider, component.id=218, service.id=360, service.bundleid=203, service.scope=bundle} - org.openhab.binding.plex
2017-01-30 18:10:43.841 [INFO ] [b.core.service.AbstractActiveService] - Plex Refresh Service has been started


 some messages from Astro, Weather etc


2017-01-30 18:10:58.900 [DEBUG] [.binding.plex.internal.PlexConnector] - 192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct
java.net.UnknownHostException: 192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)[:1.8.0_121]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_121]
        at java.net.Socket.connect(Socket.java:589)[:1.8.0_121]
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)[:1.8.0_121]
        at sun.net.NetworkClient.doConnect(NetworkClient.java:175)[:1.8.0_121]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)[:1.8.0_121]
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)[:1.8.0_121]
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)[:1.8.0_121]
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)[:1.8.0_121]
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)[:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)[:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)[:1.8.0_121]
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)[:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)[:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)[:1.8.0_121]
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)[:1.8.0_121]
        at org.openhab.binding.plex.internal.PlexConnector.doHttpRequest(PlexConnector.java:617)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexConnector.getDocument(PlexConnector.java:594)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexConnector.refresh(PlexConnector.java:587)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexBinding.execute(PlexBinding.java:61)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[178:org.openhab.core.compat1x:2.1.0.201701271943]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)[178:org.openhab.core.compat1x:2.1.0.201701271943]
2017-01-30 18:10:58.925 [DEBUG] [.binding.plex.internal.PlexConnector] - [192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct]: Websocket connection error
2017-01-30 18:10:58.926 [DEBUG] [.binding.plex.internal.PlexConnector] - Error connecting to Plex
java.util.concurrent.ExecutionException: java.net.ConnectException: wss://192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct:32400/:/websockets/notifications?X-Plex-Token=<mytoken>
        at com.ning.http.client.providers.netty.NettyResponseFuture.abort(NettyResponseFuture.java:341)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:107)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChannelFuture.java:145)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1130)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:927)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:524)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.AsyncHttpClient$BoundRequestBuilder.execute(AsyncHttpClient.java:236)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexConnector.open(PlexConnector.java:198)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexConnector.connect(PlexConnector.java:479)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.openhab.binding.plex.internal.PlexConnector.run(PlexConnector.java:186)[203:org.openhab.binding.plex:1.10.0.201701300211]
Caused by: java.net.ConnectException: wss://192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct:32400/:/websockets/notifications?X-Plex-Token=<mytoken>
        at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103)[203:org.openhab.binding.plex:1.10.0.201701300211]
        ... 9 more
Caused by: java.nio.channels.UnresolvedAddressException
        at sun.nio.ch.Net.checkAddress(Net.java:101)[:1.8.0_121]
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)[:1.8.0_121]
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:108)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:70)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.handler.ssl.SslHandler.handleDownstream(SslHandler.java:608)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:54)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.handler.codec.http.HttpClientCodec.handleDownstream(HttpClientCodec.java:97)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.channel.Channels.connect(Channels.java:634)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:207)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:229)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:182)[203:org.openhab.binding.plex:1.10.0.201701300211]
        at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1091)[203:org.openhab.binding.plex:1.10.0.201701300211]
        ... 6 more

What am I doing wrong here ? KGTec1NAS is the hostname of my plex server which i configured in PaperUI, it resolves to 192.168.178.11. I put the IP of my openhab server, 192.168.178.39, into the server configuration:

Hi Max1968, I think you’ll need to have your items defined first in order for the web socket connection to be established. The items should have your device id defined.

I’m pretty novice to all of this so please take with pinch of salt.

The DNS configuration for Plex is a bit “special”. Could you see if 192-168-178-11.872bac4ae7b84ed1bd8076d9ef332412.plex.direct resolves to 192.168.178.11 on your openHAB VM? If not, try adding it to the host file manually.

1 Like

that did the trick, thx :slight_smile:

this is likely pertinent to the discussion:

https://support.plex.tv/hc/en-us/articles/115002267687

This could really, really simplify things, right? Official home automation support.

2 Likes

year they also finshed their alexa skill. Has someone testet if the binding still works with this new update?

These webhooks look interesting, would indeed simplify the binding a lot. Will definitely try to incorporate this in the binding. Does anyone know how to publish an endpoint for this in openHAB to receive the webhook calls? Any other bindings doing this?

Did a quick check, the current binding works fine with updated PMS with webhooks (1.3.4.3285).

Assuming that the PMS has a route to the openHAB server (obviously it won’t work otherwise), your code could register a servlet with the OSGi HttpService.

Interesting
 Plex published a sample app for integrating with a Wink hub using the webhooks:

1 Like