Plex + Smartthings

I have started looking at the plex api and it’s going to be tricky to build a service manager and device types for plex. You can retrieve a list of connected clients, but the list is ephemeral. There is a way to list all clients, but it will list every browser version and device you have ever connected with.

Here are the bits I am puzzling on.

  • How do you create a device type to handle transient devices?
  • I want to see what is playing on each client and have basic control.
  • Will the existing capabilities work for this scenario.

PLEX API docs:

https://code.google.com/p/plex-api/w/list

I’m a HUGE Plex junkie. There are a few of us here at ST. Let me know how I can help :smile:

1 Like

Oh, it’s going down. I started a while ago but then plex lost its forums due to hackers . I have already figured out how to send basic commands to a client. I am going to hit up @pstuart because I have not messed too much with local ip stuff. I am also trying to figure out what kinds of xml parsing is available in our version of groovy.

Want to do it live on camera on Friday? Hehe, if not, let me know your questions.

Pretty easy to do, as long as you don’t need to wait for a response.

Is it two way or just sending commands?

I just though of something. Will have to try it out on Friday.

Let me know if you want to try to tackle this during my live session.

Yeah. I was joining anyway. If you want to do this that would be great.

It’s just one way if I am understanding you. I don’t think it provides any sort of callback. I think you can only query the api. You can query for players, what’s playing, what’s in the library, etc. You can also send control commands.

Created a quick and easy Plex->SmartThings integration for a windows server where Plex runs.
Every n seconds it calls localhost:32400/status/sessions and retrieves the clients playing from Plex and sends updates to a smartapp endpoint when the play state changes where it sets some hue lights and switches depending on the play/pause/stopped state.
Since I only use Plex with a single client I’m just checking for a few needles in the xml response from Plex, but it should be quick to add support for storing states per user and send the state, user, and player to the smartapp.
Seems to be about no performance impact on the server calling it every second.

Are you willing to share your code?

Source for the c# console application: http://gosulabs.com/st/Plex2SmartThings_DotNet.zip
And the smartapp: http://gosulabs.com/st/SmartApp.php

The first check after it starts takes a few seconds at times for some reason, but after that it’s faster.

Endpoint urls, plex server url, and needles are all in the app.config file. Forgot to put the ‘timer’ interval in the config, so you have to change that one in the code if you want, but it has worked fine so far when set to 1s.
Might add some extra state handling for multiple devices/users tomorrow if I feel like it :smiley:

1 Like

thanks for sharing. is the zip file just a simple install or do I need to do some trickery?

also will it work on windows 8.1?

It’s pretty straightforward, and as long as you have .net framework 4.5 installed it should run fine. It should be preinstalled on windows 8 if I’m not mistaken.
If you don’t have visual studio installed to compile the code then I’ve upped another version without the source but with a few improvements at http://gosulabs.com/plex2smartthings.php, as well as a small readme here on how to get it up and running quick: https://docs.google.com/document/d/1r3R_j1qQrw70f6yoEhoZDIIw53Pcv3_YJCasacGay2g/pub

3 Likes

thanks so much. can’t wait to try it out.

Christian, this is awesome. I am going to check this out soon. Great job!

Thank you for the apps. Working great except I have multiple devices with plex client and my lights are going crazy when we use multiple devices with plex client at the same time. Is it possible to just have one device controls the lights?

@markh Thanks :smile:

@Navat604 In the config file there’s a whitelist and ignorelist.
If you set onlyAllowWhitelisted=true then only the devices on the whitelist will be monitored.
Uncomment the line <item type=“player” value=“Test Player B” /> and set the name of the player instead of ‘Test Player B’ and it should hopefully work.

Awesome, thank you!
20 characters…

works nicely ! thank you!

Showed my wife as I was quite excited… but she didn’t really care… though I did test it whilst she was watching devious maids…

If I may ask for a feature next time you work on this project - can you set a mode when it plays / pauses/stops? As right now it overrides my lifx color settings.

thanks again. this was one of those massive features I have been looking forward to.

I’m glad it works :smiley:
The application sends the plex states (play/pause/stop) to the smartthings app, so changing modes is just a quick addition to the script. I’ve added inn optional mode changes in the example script (SmartApp_Source.txt) in the download, haven’t been able to test the changes yet but most likely it works :slight_smile:

awesome. thank you. so the new code should work without any changes or do I need to do something to it?

Edit: looks like it will just checked the code. thank you!

Other ideas incase you’re interested:
Run hello home phrases.
Identify type of media. i.e different change/mode for tv or movie?

Glad to hear it :smiley:
Thanks for the suggestions, I’ll try to implement them soon! The different media types are already halfway implemented at least, since it’s already sent to the script as well as the states and player name :smile:

Great work! This is exactly what I have been waiting for! I am having a little problem though… I am very basic when it comes to making apps, etc - I followed the instructions however when I go to configure I do not see API token or API end point - what am I missing? On the right hand column where it shows that on your instructions, my options are just locations and preferences - there is no simulator option. Is my hub not up to date?

I also have a v2 hub coming any day now and I plan on starting fresh with that anyway but I would love to get this app to work!

Thanks so much!