[OBSOLETE] PlexPlus - Control Lighting with Plex Play Status

PlexPlus (with Plex2SmartThings)

*NO LONGER MAINTAINED - New revision in comments as " Plex Communicator"

Using either a Windows EXE, direct from Plex webhooks (Plex Pass only) or a Plex custom device type to translate status changes in Plex Media Server and passing these status changes to the Plex Plus SmartThings App to control lighting and switches. Different statuses include Play, Pause, Stop & Trailer

Note: This is a modified version of @ChristianH’s Excellent Plex2SmartThings exe.

Code and Program Location:

Latest Code for Plex Communicator can be found here:

Program Here:

PlexPlus Features:

  • Recieve Plex events from either the Plex2SmartThings exe, the Plex Server (Plex Pass only) or the Plex HT device type.
  • Player identification (IP Address, Player Name, User Name, Device Type)
  • State identification: (Play, Pause, Stop)
  • Content identification (Movie, TV Episode, Music or Trailer)
  • SmartThings Mode restrictions
  • Scenes include control over (on/off/color/mode/switches)
  • Switches can return to original state on stop
  • Lights can be set to only change if already on
  • Delay scene changes for pause and stop actions
  • Create and change a virtual device type so that events can be triggered to other apps

Additional Requirements

Either:

- Plex2SmartThings - Windows Application - This is the most reliable method at the moment due to ST reliability issues and also should be able to handle any client and can select based on many variables. A computer will need to run a program to poll Plex, so will need to be switched on when you are using Plex for this to work (This does not need to be on the same computer as the Plex server)

- Plex Webhook (Requires Plex Pass) - Plex can now directly talk to SmartThings, to get the webhook URL install the SmartApp using the instructions below, open Live Logging in IDE, enable debugging then press done on the app, the webhook URL will be posted in the Live Logging. Instructions on how to setup Plex can be found here, please also ensure that your plex server is up to date: Webhooks | Plex Support

- Plex HT Manager - Non Windows / NAS etc. - This is an app and custom device type, which uses ST to poll Plex every 10 seconds, as such is subject to ST reliability issues, but offers greater server support and easier to setup - [OBSOLETE] Plex Home Theatre Manager SmartApp

- Plex Plus Device Type (Optional) - Now you can install this device type under “My Device Handlers” and then create new devices in the Smart App then associate the device under the “Trigger These Actions” section. This allows you to interface with other applications such as Core and Rule Machine.

How To Install:

1. Create the SmartApp

PLEASE NOTE GITHUB INTEGRATION IS NOW LIVE:
Owner: jebbett
Name: Plex2SmartThings
Branch: PlexPlus

A. Go to your IDE location, the below link should re-direct you to the correct IDE location.

https://graph.api.smartthings.com/ide/apps

B. Select “From Code”

C. Paste App source code with the code from the file PlexPlus.groovy.

D. Save and publish the app for yourself.

E. Enable OAuth in IDE by going in to IDE > My Smart Apps > Plex Plus > App Settings > Enable OAuth.

F. Get the Token and API Endpoint values via one of the below methods:

  • Open the PlexPlus smart app and click API Information for your region, you can then send it to your computer via email from the app.
  • Enable debugging, open live logging in IDE and then open the app again and press done and values will be returned in Live Logging.
  • If the above does not work (usually as ST have introduced a new region) then you can just get the App ID and Token from the “Last Event / App ID / Token” screen, but you will manually need to write this down.
  • Configure the app online and note down the API Token and API Endpoint values.

2. Configure Your Chosen Polling Method (Choices detailed in “Additional Requirements section”)

If you have chosen Plex2SmartThings EXE continue below, otherwise follow the guide provided via the link in the “Additional Requirements” section then resume at step 4

A. Download Plex2SmartThings.exe and config.config. (I have also put a ZIP file containing all of these in the same folder)

B. Open the config.config file.

C. In config/smartThingsEndpoints fill in your API token and add the APP ID to the endpoint urls from the previous section.

<!ENTITY accessToken "123-123-123">
<!ENTITY appId "abc-abc-abc">
<!ENTITY ide "https://graph-eu01-euwest1.api.smartthings.com">
<!ENTITY plexStatusUrl "http://localhost:32400/status/sessions">

D. Be sure to also check that your IDE URL matches the URL in config.config, if you have the URL from the app then this should be correct, if you were unable to get this from the app then you willl need to copy from IDE, it’ll be somethign like “graph-na02-useast1.api.smartthings.com

E. If Plex and this application is not running on the same server then enter the URL to the session status page of your Plex server in the plexStatusUrl attribute.

F. If you have Plex Pass users with PINs (and also possibly non Plex Pass users now) be sure to append your plex_token to the end of the url in the step above. (e.g. http://localhost:32400/status/sessions?X-Plex-Token=‘MYPLEXTOKEN’). To find your plex token follow this guide.

G. The polling interval and debugging can also be configured, however the standard value should suffice.

3. Run Plex2SmartThings

You can now run Plex2SmartThings.exe and the SmartApp should be notified whenever any media plays on plex.

To run this on mono you will need to download mono for Mac, or for Linux install “mono-complete”, the standard runtime doesn’t contain everything you need.

On Linux you can run “mono Plex2SmartThings.exe” or “mono Plex2SmartThings.exe &” to run in the background (“jobs” will show running instances and “kill $1” will kill process 1)

4. Configure the Smart App

Configuration should be self explanatory however come back here with any questions.

If using Plex2SmartThings EXE you will need to populate “Player name, User or IP” If you require device details from then the App has a section called “Last Event” which will tell you the details of the last event recieved.

5. Errors / Debugging

Plex2SmartThings.exe - SendGetRequest: the remote server returned and error: (403) Forbidden
There is an issue with the URL in config.config re-check section 2.D

The remote server returned an error: (401) Unauthorized.
You need to get the Plex token mentioned in section 2.F.

No error in the EXE and no “Last Event” present in the App
This is because SmartThings is not reciving an event, this is usually because the App ID or Token are incorrect, if you re-install the app these values will change and need to be setup again.

“Last Event” in the app, but hasn’t triggered the lights to change.
This is likely to that the “Room” is not configured correctly, re-check the name or IP you have setup

Live Logging - java.lang.NullPointerException: Cannot get property ‘authorities’ on null object @ line xx
You have not enabled OAuth in the parent app, go to Section 1.B.iii

I’ve played a video via Plex but no “Last Event” is showing
If the event is not appearing here then the config.config is not setup correctly and you will need to revisit step 2. (If using Plex2SmartThings) If using the Plex Webhook then either you have pasted in the URL incorrectly or your server is not up to date.

12 Likes

Just to say that if you are not running a windows computer, to run the polling script on then check this out:

1 Like

this is awesome thank you.

I have Christians working nicely as it is - but am hoping to have it go back to whatever mode it was in prior to playing or pausing - - (I have a movie mode to stop actions occuring, and when it stops it goes back to home evening - but i can only choose a set one… not what it was prior to going to movie if that makes sense? )

1 Like

So a quick question on this, how is the mode currently set? The reason I ask is that I have 1 away mode and 4 home modes based on time, however I have a dummy mode that triggers rule machine to evaluate all rules relating to mode.

Also is returning to the previous mode valid always? In my instance it wouldn’t be as I could start watching a film in one mode then the mode could change based on time?

I would also question if mode, which should really be used to identify house state rather than a specific room, I’m using virtual switches to achieve this but depends on your use case…

I may take a look at writing a separate app to deal with reverting to previous if it doesn’t already exist…

thanks for the response mate.

Sounds like I may be using it wrong — but it worked for a while.

Home evening is set on sunset… basically when it’s dark out I have a different brightness for all internal lights…

but when watching plex in my lounge - i don’t want certain smartapps (Smarlights app) to run. As my lounge motion sensor picks us up moving whilst watching plex.

Then when the show stops, it goes back to home evening. the issue is it goes back to home evening even if it was home day before… I can only choose one.

returning previous mode could be wrong based on time also - you are correct as well there :slightly_smiling:

How can I enable a virtual switch (can I use your code?) and then i assume smarthings smart lighting app can check to ensure if a switch is not on before it turns the lights on?

Just at work at the moment, will respond properly later, but in short smart lighting is reliant on mode and doesn’t have provision for switches to control if the automation is active or not, you could use rule machine which is what I use for everything now, but in doing that you lose local processing and if your internet or smartthings servers go down you also lose your lighting automation and depending on how they are controlled you could lose the lighting entirely!

So I’ve been thinking about this long and hard, and I don’t think there is a workable solution here, without moving away from SmartLights, or at least introducing another smart app that does not run locally.

So the way mine is setup to work, I have the modes (Away, Day - no auto lights, Night - dimmed lighting and Evening normal lighting) although this is largely irrelevant.

As my auto lighting in the living room is controlled by a simple rule in rule machine, I then have specified “switch to disable rule” as a “Simulated Switch”, the Plex app then turns this on when playing and off when stopped.

The simulated switch is added via my devices in IDE> Add new device…

I guess it depends on if you are happy moving away from local running, if you internet is even slightly flakey I’d advise against it… even if it’s not sometimes there can be a delay…

Edit: Actually you could create a rule machine rule to do this… When mode = “Home Evening” & Time is before sunset, set mode to “Home Day”, that way the Plex App can set to Home Evening when stopped and Rule machine will change it to day form there if it is still day time… Make sense?

1 Like

thanks for putting so much thought into it. i like your last idea of using rule machine to fix the mode… that could work nicely!

Just built that rule and it seems to work but will try it out tonight! thanks for the idea :slight_smile:

1 Like

Hey @Entityxenon would it be possible to add an option to only turn switches off/on if they are already on/off?

I’m trying to think of the circumstance that would make sense?

For lighting if only makes sense to dim to 20% if the light is already on… otherwise playing a movie would turn the light on…

For switches, if it’s off, then you want to turn it on, if it’s on and you turn it on again, it’s still on?

I don’t mind adding something, but I can’t see the instance where it actually does something :slightly_smiling:

:slight_smile:
it would be useful for me because for example in my bedroom i have a fan on a switch that i have setup to turn off if i start playing something (Cause its loud) but i noticed that once it stopped playing it turns it on even though it was initially off.

kind of the same thing in our living room i have a scentsy setup to turn off when something starts playing and if its already off when something stops playing it turns it on.

Ahh ok makes sense, that’s different to the functionality that is there for the lighting as it needs to record state when it plays and reverts to that state when finished.

Unfortunately it’s not as simple either as multiple switches can exist under these options, some maybe on and others off, so will need to work out how to store the states of each…

Won’t be able to look tonight as its late here, and working away tomorrow so may be a couple of days for me to see if it can work it out…

You’re the bomb!, thanks for spending the time on it. i appreciate it. :slight_smile:

@Big_Webstas

Child app updated:

v2.4 - Added the ability to return switches to the state before Plex started playing.

Not tested it fully, but any issues let me know!

Note: Just an observation, last night I had noticed that my plex token had changed, not sure what had caused this, perhaps the last update?

So if yours has stopped working, then I’d suggest checking your Plex token.

YOU’RE AWESOME!!! thank you so much

No worries, if it’s worth adding then don’t mind adding it!

I am having an issue getting the windows app to work. When ever I start playing plex on any device it just says “failed to parse xml”. Any ideas?

Ok, got it sort of working. Turns out my plex server was not updated. I updated the server and now I can see the state of clients. But it doesn’t seem to be able to connect to smartthings, I get a failed to “SendGetRequest: the remote server returned and error: (403) Forbidden”

Sounds like either your app ID or token are incorrectly configured, open the PlexPlus app go to “API Information - US” and ensure that the 3 instances of ID and the one token instance are correct in the config.config file on your plex server…

If I have assumed incorrectly and you are actually in the EU then you will also need to update the URL as described in config.config