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 !
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 !
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
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.
Hello!
Could someone tell me why Plex binding isnāt available in the Paper UI, even though I have enabled Legacy bindings?
Best regards,
Davor
A 1.x binding needs some extra metadata to be installable from the Paper UI, adding that is next on my to-do list
Thanks! That would be a nice improvement if possible.
Something i noticedā¦ I have the PMS running on another Server, which i shut down sometimes. If i do so i have to restart Openhab or restart the binding completely.
It would be nice if you can implemtent some kind of regularly polling interval.
Another info, the Progress Tracking, Title, Cover, etc doesnāt work if you play media from a shared library on another server.
Not sure if it is possible to fix that and if it is hard or not, but it would be wonderful !
Thanks again @idserda.
Iāve added some code that resolves the hostname to an IP, so you can use both now. Also added some more logging.
New jar: https://www.dropbox.com/s/dsp3h6t94vjvuwq/org.openhab.binding.plex_1.9.0.201612161814.jar?dl=0
There is some code to reconnect the websocket connection on disconnect but there might be something missing, Iāll check.