openHAB2 + Plex

I have just got Alexa working too. I must say, i think it’s great as an interface to openhab. Now it would be really fantastic if we could control plex via alexa! I’m sure it could be done.

1 Like

Apparently a official plex skill is in the works for alexa… https://forums.plex.tv/discussion/173499/amazon-echo-and-plex-alexa-tell-the-home-theater-to-put-on-a-good-episode-of-always-sunny

that looks amazing. Hope he releases it soon!

hi i have problem adding the plex binding.

I put the org.openhab.binding.plex-1.8.3.jar into this folder /usr/share/openhab2/addons/

then i put a plex.cfg into /etc/openhab2/services

# IP address of the Plex server
host=---.---.--.--

# Optional, port that the Plex server is running on. Default = 32400
port=32400

# Refresh interval in ms. Default = 5000
refresh=5000

than i enabled in the paper.ui “Include Legacy 1.x Bindings” and restartet my server.
Now i have the following error in my logfile:

[WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.binding.plex-1.8.3.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.plex [193]
  Unresolved requirement: Import-Package: org.codehaus.jackson

	at org.eclipse.osgi.container.Module.start(Module.java:434)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[8:org.apache.felix.fileinstall:3.5.0]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[8:org.apache.felix.fileinstall:3.5.0]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1207)[8:org.apache.felix.fileinstall:3.5.0]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:504)[8:org.apache.felix.fileinstall:3.5.0]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[8:org.apache.felix.fileinstall:3.5.0]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[8:org.apache.felix.fileinstall:3.5.0]

PS: I solved it by my self. You have to enable it with karaf by using “feature:install openhab-runtime-compat1x”

1 Like

Has anyone else had an issue with the latest version of plex not working?.. getting this error…

09:32:03.210 [ERROR] [.binding.plex.internal.PlexConnector] - Error handling player state change message
java.lang.NullPointerException
at org.openhab.binding.plex.internal.PlexConnector$PlexWebSocketListener.onMessage(PlexConnector.java:494)[213:org.openhab.binding.plex:1.8.3]
at com.ning.http.client.providers.netty.NettyWebSocket.onTextFragment(NettyWebSocket.java:202)[213:org.openhab.binding.plex:1.8.3]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$WebSocketProtocol.handle(NettyAsyncHttpProvider.java:2380)[213:org.openhab.binding.plex:1.8.3]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.messageReceived(NettyAsyncHttpProvider.java:1220)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)[213:org.openhab.binding.plex:1.8.3]
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)[213:org.openhab.binding.plex:1.8.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_111]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]

Yep, the last version of Plex Media Server doesn’t work anymore with the binding.
Not sur about when the modifications have been made, PMS 1.1.4 works but not PMS 1.3.0.

The websocket notification message have been modified.

You can look at this post to see my search about the changes :

but unfortunatly my dev skill isn’t enought strong to update the binding myself so I hope someone will take care of it :slight_smile:

Yes, I’m getting this error too after updating to the latest PMS (1.3.2.3112). I’ll look into it.

Hi @idserda !

You can have a look at the post I have previous linked, the notification service seem to need an auth token too and the notification json content have been modified.

glad to see you will looking into it ! :slight_smile:

Thanks for reporting this! I had authentication disabled for my local IP-range so didn’t see this problem. I fixed both this and the changed message format of the websocket connection in this PR: https://github.com/openhab/openhab/pull/4900

Here’s a snapshot version of the Plex jar if anyone wants to try: https://www.dropbox.com/s/byvjz8woujp4lwh/org.openhab.binding.plex_1.9.0.201612152032.jar?dl=0

1 Like

Just update my PMS to 1.3.2.3112, and your fix works flawlessly, thanks you so much !

I tried the binding JAR linked above on openHAB 1.8.3 runtime, and I get this JSON payload logged:

2016-12-15 23:49:01.364 [DEBUG] [.b.plex.internal.PlexConnector] - [nas.local]: Message received: {"_elementType":"NotificationContainer","type":"playing","size":1,"_children":[{"_elementType":"PlaySessionStateNotification","sessionKey":"10","guid":"local://2056","ratingKey":"2056","url":"","key":"/library/metadata/2056","viewOffset":69,"state":"paused"}]}

error:

2016-12-15 23:39:51.454 [ERROR] [.b.plex.internal.PlexConnector] - Error mapping JSON
org.codehaus.jackson.map.JsonMappingException: Root name '_elementType' does not match expected ('NotificationContainer') for type [simple type, class org.openhab.binding.plex.internal.communication.websocket.NotificationContainer]
 at [Source: java.io.StringReader@cb2456; line: 1, column: 2]
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163) ~[jackson-mapper-asl-1.9.2.jar:1.9.2]
	at org.codehaus.jackson.map.ObjectMapper._unwrapAndDeserialize(ObjectMapper.java:2787) ~[jackson-mapper-asl-1.9.2.jar:1.9.2]
	at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2721) ~[jackson-mapper-asl-1.9.2.jar:1.9.2]
	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1854) ~[jackson-mapper-asl-1.9.2.jar:1.9.2]
	at org.openhab.binding.plex.internal.PlexConnector$PlexWebSocketListener.getSessionUpdateFrom(PlexConnector.java:556) [bundlefile:na]
	at org.openhab.binding.plex.internal.PlexConnector$PlexWebSocketListener.onMessage(PlexConnector.java:527) [bundlefile:na]
	at com.ning.http.client.providers.netty.NettyWebSocket.onTextFragment(NettyWebSocket.java:202) [async-http-client-1.8.4.jar:na]
	at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$WebSocketProtocol.handle(NettyAsyncHttpProvider.java:2380) [async-http-client-1.8.4.jar:na]
	at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.messageReceived(NettyAsyncHttpProvider.java:1220) [async-http-client-1.8.4.jar:na]
	at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) [netty-3.9.0.Final.jar:na]
	at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) [netty-3.9.0.Final.jar:na]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]

repeated in the log. My Plex server is Version 1.2.7.2987. I have an update Version 1.3.2.3112 ready to install after this log message is understood.

Thanks for your updates!

Sure the new fix for the binding doesn’t work anymore with old plex media server release as the Json message has been modified.

Update to 1.3.2 and it should work.

The pull request says

Latest Plex Media Server (>= 1.3.2.3112) sends a different message format over the websocket connection. The binding now supports both this and the earlier format.

so I expected the change to work with new and previous. @idserda?

Oops sorry I didn’t see that !

Yes both versions should work. I think there is a problem with detecting the version number of your PMS. The binding tries to get the PMS version from https://plex.tv/api/resources?includeHttps=1 (log in to plex.tv first). It selects the right Device by the address of the the underlying Connection. Have you configured localhost/127.0.0.1 maybe instead any other (public) IP of your server? Could you try configuring an IP that is listed there? If that’s the case this extra step should go in the binding wiki (plus maybe some more debug logging).

Thanks Jeroen,

I provided plex:token in my openhab.cfg, but no username or password.

Here is my slightly redacted response to the URL you gave above. Some of the masked IP addresses are my public IP address, others are private network addresses:

<MediaContainer size="4">
<Device name="Media" product="Plex Media Server" productVersion="1.2.7.2987-1bef33a" platform="Linux" platformVersion="3.10.77 (#8451 SMP Fri Dec 9 10:50:24 CST 2016)" device="DiskStation" clientIdentifier="xxxxxx" createdAt="1477008456" lastSeenAt="1481874533" provides="server" owned="1" publicAddress="xx.xx.xx.xx" httpsRequired="0" synced="0" relay="1" publicAddressMatches="1" presence="1">
<Connection protocol="https" address="xx.xx.xx.xx" port="32400" uri="https://xx.xx.xx.xx.plex.direct:32400" local="1"/>
<Connection protocol="https" address="xx.xx.xx.xx" port="32400" uri="https://xx.xx.xx.xx.plex.direct:32400" local="1"/>
<Connection protocol="https" address="xx.xx.xx.xx" port="21393" uri="https://xx.xx.xx.xx.plex.direct:21393" local="0"/>
</Device>
<Device name="Nexus 5" product="Plex for Android" productVersion="5.2.0.477" platform="Android" platformVersion="6.0.1" device="Nexus 5" clientIdentifier="xxxx-com-plexapp-android" createdAt="1474978965" lastSeenAt="1481887356" provides="player,controller,sync-target" owned="1" publicAddress="xx.xx.xx.xx" publicAddressMatches="0" presence="1">
<Connection protocol="http" address="xx.xx.xx.xx" port="32500" uri="http://xx.xx.xx.xx.22:32500" local="1"/>
</Device>
<Device name="Plex Web (Chrome)" product="Plex Web" productVersion="2.10.10" platform="Chrome" platformVersion="55.0" device="OSX" clientIdentifier="xxxx" createdAt="1479759072" lastSeenAt="1481860495" provides="player" owned="1" publicAddress="xx.xx.xx.xx" publicAddressMatches="1" presence="1">
<Connection protocol="http" address="xx.xx.xx.xx" port="32400" uri="http://xx.xx.xx.xx:32400" local="1"/>
<Connection protocol="http" address="xx.xx.xx.xx" port="32400" uri="http://xx.xx.xx.xx:32400" local="1"/>
</Device>
<Device name="Plex Web (Chrome)" product="Plex Web" productVersion="2.12.3" platform="Chrome" platformVersion="54.0" device="OSX" clientIdentifier="xxxx" createdAt="1481831553" lastSeenAt="1481831562" provides="player" owned="1" publicAddress="xx.xx.xx.xx" publicAddressMatches="1" presence="0">
<Connection protocol="http" address="xx.xx.xx.xx" port="32400" uri="http://xx.xx.xx.xx:32400" local="1"/>
<Connection protocol="http" address="xx.xx.xx.xx" port="32400" uri="http://xx.xx.xx.xx:32400" local="1"/>
</Device>
</MediaContainer>

When I try http://localip:32400/api/resources?includeHttps=1 from the browser, I get a 401 Unauthorized. Does this query need the X-Plex-Token?

Ok, but what did you configure for plex:host? That IP should be in the list under the first Device.

I actually configured a hostname for plex:host, but I see the wiki says to use an IP address (the local IP of the PMS running on a Synology DiskStation). Is it required to use an IP address for plex:host?

After changing the host name to IP address and restarting my 1.8.3 instance, the ERROR log has stopped and it seems to be parsing the JSON, so it would appear that it was able to determine that it is an older version. Would it be possible to allow hostnames in the .cfg file in addition to IP addresses, to avoid this issue? Or in the (slightly less appealing) alternative, updating the wiki page to say that hostnames are not acceptable?

I think I can make it work with both hostname and IP-address. I’ll have a look tonight.