Plex + Smartthings

Hey all,
So I have done a bit of reading, I know there was a thread out on an XBMC —> ST integration. I am actually more interested in having Plex control a set of dimmer switches, rather than having Smartthings control Plex (although I can see a few uses there as well). Think movie night. Push play, pause, or stop on the movie and each one of these actions has a different effect with the switches. My thought is, push play --> dim the lights, push pause or stop --> lights go to 100%.

This seems like one of those match made in heaven SmartThings apps. There is a HUGE Plex community. I have two Smart TVs that both have Plex installed as an app, Roku has it preinstalled as well. I know of a handful of people that would buy SmartThings just for this functionality alone (if they haven’t already)

So I currently have a very basic setup going right now using Plex and IFTTT. I setup PlexWatch (https://github.com/ljunkie/plexWatch)(https://forums.plex.tv/index.php/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/) on my PMS PC, which monitors,logs and notifies via Pushover, Prowlapp, Growl, Twitter, Boxcar and Email anytime anything is played via Plex,

I setup IFTTT to monitor any new emails coming in with Gmail, and once a search matches, it flips the switch. So it works…sort of. IFTTT doesn’t really work for applications like this because they have 15 minute polling. For this to be a functioning app, would need it to be near instant.

Most all of the core code is done at this point, I think. I’m not really a programmer, I just like to tinker. So at this point I just need some help.

The code is rather modular, see (https://github.com/ljunkie/plexWatch/blob/master/plexWatch.pl) Check out line 2203: sub NotifyPushOver() {

For instance, Using JSON, they are submitting the notifications to Pushover/Boxcar. Not sure how simple it would be to use this same type of setup with ST graph/API/REST.

Appreciate any help with this!

Mark

10 Likes

This is awesome and I’m going to look at it in detail once I’m not drinking wine.

Try using tweets with hastags to IFTTT, they trigger instantly!

I’ve been interested in this for a while as well. It seems it’s lacking the ability to know if you are watching a movie or TV show though. I wanted it to set lights only during a movie initially, though I’m sure there are plenty more uses.

At least I know my next project now!

Hi, any updates on this? I think it’s a fantastic idea.

Subscribed. I love Plex.

Per Pete, any updates?

So do SMS. I’m using SMS (Siri) on my phone to open garage door. It triggers instantly 90% of the time. A glitch occasionally but I’m happy with the integration. It’s far superior to ST presence sensors or iPhone presence/iOS presence and can be done hands free via Siri.

If the MS Sync system in my F150 would allow iPhone text messages I’d be ecstatic.

I want this too!!!

I recently wrote a little script that runs every 10 seconds on my mac and checks to see what’s playing (only on home machine). If it’s a movie, it sends a command to SmartThings to set the lights. When paused or no movie playing, the lights come back up.

A far as I know you need PlexPass for it to work, the page where I’m checking what’s playing is only available then. I’ll share if anyone is interested.

Hi Ronny, I would be interested in this script. Cheers.

@ronnycarr can you show us how you did this?

Thanks!

@Sjbeeny @Pete

This is what I am currently using to accomplish this, it’s pretty simple I suppose. It does use a text file to keep track of the current player state. The script will need to be configured for your environment; server address, player name, text file location and the switch url from the endpoint example should be edited.

To have the script run (every 10 seconds in my case) you’ll need to create a LaunchAgent (.plist) if you are on a Mac. I don’t know what one would need to do on Windows.

Let me know if you have any questions!

The script:

#!/usr/bin/env python
import urllib2
import xml.etree.ElementTree as ET

### Configure to support plex server and player
plexState = 'http://172.16.1.200:32400/status/sessions' # The URL to the Plex-Session XML (PlexPass Required?)
mainPlayer = "cubert.private" # Name of player to watch
statusFile = "/Users/ronnycarr/Plex_Connect/playStatus.txt" # Text file to save current player state

moviePlaying = False
statusTemp = open(statusFile, "r")

switchStatus = statusTemp.read()
statusTemp.close()

server = urllib2.urlopen(plexState)
data = server.read()
server.close()

tree = ET.fromstring(data)
for video in tree.iter('Video'):
    vtype = video.get('type')
    player = video.find('Player').get('title').split('@')[0]
    playerState = video.find('Player').get('state').split('@')[0]
                
    if player == mainPlayer:
        if vtype == "movie":
            moviePlaying = True
            if playerState == "playing" and switchStatus == "off":
                switchStatus = "on"
                urllib2.urlopen("https://graph.api.smartthings.com/api/smartapps/installations/XXXXXXXXXX/switches/XXXXXXXXXX/on?access_token=XXXXXXXXXX").read()
            elif playerState == "paused" and switchStatus == "on":
                switchStatus = "off"
                urllib2.urlopen("https://graph.api.smartthings.com/api/smartapps/installations/XXXXXXXXXX/switches/XXXXXXXXXX/off?access_token=XXXXXXXXXX").read()

if moviePlaying == False and switchStatus == "on":
    switchStatus = "off"
    urllib2.urlopen("https://graph.api.smartthings.com/api/smartapps/installations/XXXXXXXXXX/switches/XXXXXXXXXX/off?access_token=XXXXXXXXXX").read()

statusTemp = open(statusFile, "w")
statusTemp.write(switchStatus)
statusTemp.close()

The LaunchAgent:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>EnvironmentVariables</key>
	<dict>
		<key>PYTHONPATH</key>
		<string>/usr/bin/python</string>
	</dict>
	<key>Label</key>
	<string>com.movie.plex</string>
	<key>Program</key>
	<string>/Users/ronnycarr/Plex_Connect/movie.py</string>
	<key>StandardErrorPath</key>
	<string>/tmp/com.movie.plex.err</string>
	<key>StandardOutPath</key>
	<string>/tmp/com.movie.plex.out</string>
	<key>StartInterval</key>
	<integer>10</integer>
</dict>
</plist>

It would be awesome to have a smartapp be able to do something like this:

Hey, what smartapp are you connecting this to?

Just using the Endpoint Example found here. Not really sure where the current tutorial for setting it up is.

I have plex and have a previous endpoint example. I will try and make a tutorial for this over the weekend.

@ronnycarr oh okay, mind posting your example file here?

@jody.albritton Sounds good, I’ve made plenty of these ‘API’ groovy scripts now I was just looking for the plex-specific one. Mind tossing over the example you have as well for now? Till you can get your tutorial done?

Thanks

My example file is at

This was created to log events to firebase. I am just now getting to look at the plex api and what kinds of integration could be done there.

1 Like

Sweet! Thanks, I got my sample one working but nice to see what you have done here as well, gave me some ideas.

I did not get to do anything this weekend. We had yet another flood in Texas and I was without internet access most of the weekend. Do you have anything to share?

like OP’s approach to this but the delay is far to olong to work. If you use twitter to post it - is it that much faster in responding via ifttt? if so that should solve the requirement