Plex Binding: Player State not updating/no updates on stop

Hi,

i am using the Plex Binding snapshot (#1324) with openHAB2 (build #560).

So far i get some information from the binding, like current title, progress, if the client is online, etc. However i don’t get the Player State (Playing, Paused, Stopped) and after the show or movie finishes the items arent cleared. So i don’t now if a movie was playing yesterday or just now.

Should i open a github issue for that?

Thank you

hello all,

This is worst for me, I can send order to my player but I can’t get any information like Title, cover, time, etc.
I retrieved my token like explain in the binding wiki.
When I going to online webapp and get a detailed media xml, this is what the url looks like :
https://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/status/sessions?X-Plex-Token=tokenhere

I checked directly from my server CLI with a curl and it work, I can see the current playing status of my rasplex.
(curl https://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/status/sessions?X-Plex-Token=tokenhere)

So in /conf/services/plex.cfg I set :
host=172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct
port=32400
refresh=5000
token=tokenhere

I also retrieved my Rasplex Device ID and set the items file like the Wiki.

Here is the OpenHAB logs in loop:

[DEBUG] [javax.xml.bind] - Trying to locate org/openhab/binding/plex/internal/communication/jaxb.properties
[DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@72009f8514 pairs: {GET /clients HTTP/1.1: null}{X-Plex-Provides: controller}{X-Plex-Device: Java™ SE Runtime Environment}{X-Plex
-Client-Identifier: 3e4e9b32-d366-47e2-a378-03044e9d1338}{X-Plex-Platform-Version: 1.8.0_111}{X-Plex-Token: tokenhere}{X-Plex-Device-Name: openHAB}{X-Plex-Product: openHAB}{X-Plex-Version: 1.9.0.201611240211}{X-Plex-Pla
tform: Java}{User-Agent: Java/1.8.0_111}{Host: 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400}{Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2}{Connection: keep-alive}
Origin: http://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400
Host: 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400
[id: 0x74a4b9b0, null :> 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct/172.19.64.45:32400]
[DEBUG] [.binding.plex.internal.PlexConnector] - [172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct]: Websocket error: Invalid Status Code 401
[DEBUG] [.binding.plex.internal.PlexConnector] - [172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct]: Websocket error: Invalid Status Code 401
[DEBUG] [oviders.netty.NettyAsyncHttpProvider] - Channel Closed: [id: 0x74a4b9b0, null :> 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct/172.19.64.45:32400] with attachment NettyResponseFuture{cu
rrentRetry=5,
Origin: http://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400
Host: 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400
uri=ws://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications,
[oviders.netty.NettyAsyncHttpProvider] - Closing Channel [id: 0x74a4b9b0, null :> 172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct/172.19.64.45:32400]

Controlling the rasplex player with play/pause, navigations, etc commands works and on the logs I can see :
[DEBUG] [.binding.plex.internal.PlexConnector] - Calling url http://192.168.0.104:3005/player/playback/play

so it seem it can correctly retrieve the player IP Address.

I also tried to use localhost IP, LAN IP as Plex and OpenHAB is on the same boat with no success.
I test also without the token in plex.cfg but with username and password, and I saw in the logs that the binding correctly retrieved a valid Token, but same error on websocket.

Plex Media Server Version : 1.3.0.3059-6277334 without PlexHome activated. (EDIT : Just tried with PlexHome Activated with same errors)
Openhab Version : 2.0
Plex Binding Version Tested :
org.openhab.binding.plex-1.9.0.b2.jar
org.openhab.binding.plex-1.9.0-SNAPSHOT.jar
org.openhab.binding.plex-1.8.3.jar

At this point I don’t know what to do more …

I hope to see someone with an idea for me :slight_smile:

1 Like

Another strange thing, but I’m not sure this is the right way :
I noticed the line uri=ws://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications,
( I have wws:// in the 1.9.0:2 jar)
When I try this in http with curl :
curl https://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications

Unauthorized

401 Unauthorized

But when I add the token to the request, I have no more error :
curl https://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications?X-Plex-Token=tokenhere
result : curl: (52) Empty reply from server
(But no 401 error)

Not sure, but does the websocket require a token too ?

EDIT : Ok, so I found a javascript to test websocket : WebSocket Echo Server | WebSocket.org

Testing with ws://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications and got errors. But with token it work : ws://172-19-64-45.9ff6bf756548baef87cb7595658.plex.direct:32400/:/websockets/notifications?X-Plex-Token=tokenhere and I receive playing notification.

On plex binding, when I watch the logs more deeper I can see :

GET /:/websockets/notifications HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Origin: http://172.19.64.45:32400
Sec-WebSocket-Key: ovT0B+TVWkrzeFEe6VmGXeg==
Sec-WebSocket-Version: 13
Host: 172.19.64.45:32400
Accept: /
User-Agent: NING/1.0,
content=null,
uri=ws://172.19.64.45:32400/:/websockets/notifications,
keepAlive=true,
httpResponse=DefaultHttpResponse(chunked: false)
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
X-Plex-Protocol: 1.0
Cache-Control: no-cache
Access-Control-Expose-Headers: Location
Access-Control-Allow-Origin: *
Date: Thu, 24 Nov 2016 18:37:00 GMT,
exEx=null,
redirectCount=0,
timeoutsHolder=null,
inAuth=false,
statusReceived=false,
touch=11656863834}

So it seem to forget to put the token … and I just don’t know why…

After looking in the binding sources, it seem that changing only one line is enought (or maybe I’m wrong), but I don’t know how to build the binding.

File : org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexConnector.java

Line 149:

Original :

 this.wsUri = String.format("%s://%s:%d/:/websockets/notifications",

Probable modification :

  this.wsUri = String.format("%s://%s:%d/:/websockets/notifications?X-Plex-Token="+connection.getToken(),

I will try to look how to build this thing…

I edited the binding source and websocket works with the Token.
It is more related to a Plex Media server update (1.3 ATM) and it is not the only change :
The Json response has also been modified so the Json parsing doesn’t work anymore.

This is a message from a 1.1.4 Plex server :
{"_elementType":“NotificationContainer”,
“type”:“playing”,“
size”:1,"_children":[{"_elementType":“PlaySessionStateNotification”,“sessionKey”:“20”,“guid”:"",“ratingKey”:“708”,“url”:"",“key”:"/library/metadata/708",“viewOffset”:136121,“state”:“playing”,“transcodeSession”:“vcb0zbdxcjrlrrcfirr6647vi”}]}

and This is a 1.3 websocket message :

{“NotificationContainer”: {
“type”:“playing”,
“size”:1,
“PlaySessionStateNotification”:
[{
“sessionKey”:“2”,
“guid”:"",
“ratingKey”:“1”,
“url”:"",
“key”:"/library/metadata/1",
“viewOffset”:0,
“state”:“playing”,
“transcodeSession”:“ut7ptt05h0qs2kidmibe2914”
}]
}
}

Can anyone confirm if they’re having a similar problem?

I can pause/play/stop. So I can seemingly SEND commands. But nothing else works. my PlexTVStatus is coming in as STOPPED, no matter what. If I force Progress, Title, etc. to stay visible, they’re all just blank.

But for some reason, I can stop and start and pause. I cannot for the life of me figure this out.

Are you using the latest nightly build of the binding?

should be. just installed it fresh a few days ago.

Looks similar to this issue: https://github.com/openhab/openhab/issues/4875

Could you turn on debug logging for the binding? And please let us know what version of the Media Server you are using and which clients.

Is there any update on this issue? I noticed that the issue (4875) has been closed for no apparent reason.

I definitely see the no update on stop issue and I have a fairly recent 2.1.0-SNAPSHOT

Small update (some debugging info?

I get the following in my log file (repeating over and over again) when playing:

2017-01-29 10:22:03 org.openhab.binding.plex.internal.PlexConnector$PlexWebSocketListener.onMessage(PlexConnector.java:532) - [192-168-1-101.d823fa18d96348edb196f091a7a3d0f0.plex.direct]: Message received: {"NotificationContainer":{"type":"playing","size":1,"PlaySessionStateNotification":[{"sessionKey":"166","guid":"","ratingKey":"22840","url":"","key":"/library/metadata/22840","viewOffset":396552,"state":"paused","transcodeSession":"1hciplcix2f56hil41ns46lx"}]}}
2017-01-29 10:22:03 org.openhab.binding.plex.internal.PlexConnector$PlexWebSocketListener.onError(PlexConnector.java:515) - [192-168-1-101.d823fa18d96348edb196f091a7a3d0f0.plex.direct]: Websocket error: null

I’m running the latest plex binding jar file (from the other thread)

191 | Active   |  80 | 1.9.0.201612161814    | openHAB Plex Binding

Here is my items file:

// Chrome player on new iMac
String ChromePlexTVStatus     "Chrome Status [%s]"   <video>     {plex="nlji4n02ywtvkkaxwc67axla#state"}

// Chrome player on new iMac
String AppleTVPlexTVStatus     "Apple TV Status [%s]"   <video>     {plex="871ADCDB-B844-47B8-A94C-286BF43729FE#state"}

and my rules file

rule "Apple TV Pause/resume"
when
    Item AppleTVPlexTVStatus received update
then 
    logInfo("rulelog", "Apple TV Play to pause")
end
rule "Chrome TV Pause/resume"
when
    Item ChromePlexTVStatus received update
then 
    logInfo("rulelog", "Chrome Play to pause")
end

Here is my plex.cfg

# IP address or hostname of the Plex server
#host=192.168.1.101

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

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

# If you're using Plex Home you need to supply the username and password of your
# Plex account here. If you don't want to enter your credentials you can also
# directly set your account token below instead.
#username=<redacted>

 # Plex password
#password=<redacted>

# Plex account token, use instead of username/password when using Plex Home.
token=<redacted>

I never get a pause or play when I pause and/or play in Chrome

That Websocket error: null does not look good. What version of the Plex Media Server are you using? And could you try and find this line in the log for the Plex binding: Server found, version xxx, api level xxx ? You’ll have to enable debug logging for this. I’ll try to reproduce this with the web client and maybe add some more debug logging.

Thanks for looking into it:
Server found, version 1.2.0.3167-aa897d8, api level v1

Okay that’s odd. You have the new websocket message format on v1.2 of PMS, which we thought was there only after v1.3. Upgrading PMS >=1.3.2.3112 will definitely fix this but we might have to change this in the binding.

I cannot upgrade the PMS, since I am running the Plex DVR beta (on QNAP). Good to know that a fix is there waiting for me for when they release a new DVR version!