Hello everyone,
A few topics here requests philips hue integration in PHT, either for "ambilight" style integration, or just a feature that would dim the lights when a movie starts, and light them back on when paused or stopped watching.
I found no plex plug-ins whatsoever that would do this, and it is a bit sad as XBMC has add-ons ready for it !
I am not a developer, and not a script/plug-in specialist, but I found a way for the second solution, the dim feature, which is a bit dodgy but works well, and I thought I could share it here in the waiting of a genuine integration.
I can only guarantee that it works on my Mac OS X environnement.
How does it work ?
I'm using PLEXWATCH, a script that gets infos from your plex account about movies being watched. I configured it to send me an email when watching, pausing, resuming and stopping a film.
Then, I made a little script that works with HUE SERVER (this app costs 5€ in the mac app store) and asked the osX mail client to launch that script when getting the plexwatch email.
Basically it does this :
PHT starts playing => plexWatch send email with "watching" in the email subject => mail client apply rules that launches a script when getting the "watching" email => hue server execute the script and dims the lights.
It works really well. You have to expect a 10-15 seconds delay, which is the refresh rate of plexWatch (5 seconds) and the time for the email to arrive.
HOW TO :
1 ) install PLEXWATCH
This is the tricky part. Excpect at least 30 minutes for this part, and a few fails. Dont panic.
You will have to use the Terminal. I had not used it before installing plexwatch, and I managed to do it, so you should too ;)
Follow their instructions at https://github.com/ljunkie/plexWatch.
Don't download anything from the webpage, everything will be done in the terminal. Bascially what you have to do is copy the lines of commands they give on their website and paste them in the terminal, then click "Enter". Sometimes it asks for your password, which is your mac password. When you type, letters don't show, this is normal. type on the blind and press enter.
So, scroll down the webpage, and the sections you wanna read are "install", "how do I setup a launch agent in MacosX" and "how do I install on OS X".
The first section, "install", will make you download the two files you will need, and put them in the right folder.
Do Step 1 (use the "curl" code), to step 3. you don't wanna do 4-5-6 (its for windows users).
For step 3, you have to edit the script file. You just have to enter a few infos like your plex username/password, and the important section : "email", where you enter your email address, smtp server, etc... in order to send the email.
There is tons of lines, again don't panic, and read well, the plexwatch team put comments in the file telling you what to do : everything that is written after a # is not code, there are guidelines, read them !
I found editing the script in the terminal very tricky, so you can also open the file (config.pl) with an app like textwrangler, i found it easier.
Once you edited your script, go to the "install on mac os X" section and follow the tutorial to install some plug-ins that your mac needs to run the script, the tuto is very good, and you will feel like Neo in "matrix" as tons of lines will scroll by themselves in the terminal when you launch the commands. You will have to install xCode.
When it's done, you have to set up the agent, which will tell your OS to run your script every 5 seconds to check the plex status.
the "how do I setup a launch agent in MacosX" is again very well detailed. The only thing is that you have to change is in the text file the "refresh rate" section, you should put 5 instead of 30.
Check if you get the mails by starting / stopping a film on plex. Remember your mail can take 10-20 seconds to arrive, and it may be considered as spam. use an iCloud or gmail account as they are checked with "push", which is faster.
2) install HUE SERVER
Now the easy part.
Buy it in the app store, and starts it. a small icon appears on the menu bar. you have to pair the app to your philips hue dock, just follow the assistant configuration steps.
then you can give it a try : click on the menu icon, and starts typing "name of one of your lamp ON", and this lamp should lights on !
3) Create two scripts for ON and OFF :
launch apple script, and type :
tell application "Hue Server" to run command "name of your lamp ON"
Save it
make a new script and type
tell application "Hue Server" to run command "name of your lamp OFF"
Try to run them (click "execute"), your lights should switch.
Add Hue Server to your "open on launch" list of apps in the system preferences
4) configure MAIL
In Mail, go to the preferences, and then "rules".
Make a first rule saying that if a mail comes in with the words "Watching" or "Resuming", mail must launch your "off" script.
You will have to copy your script in a folder that mail indicates (click "open in finder" in the "execute script" operation to open this folder and copy the script files in it, then you can choose them in the list).
Make a second rule saying that if a mail comes in with the words "Paused" or "Watched", mail must launch your "on" script.
You can add an operation to delete the emails then if don't wanna keep them.
and you're all done !
Of course step 3 and 4 can be set up as you like, you can make scripts for lights to go to a specific color, to switch multiple lights, to fade, etc... just explore HUE SERVER fonctions.
Step 4 can do other stuff too.
As I am no developer, I can help you if you expect some troubles but please try to look trough by yourself, even I could do it !
The tricky part is definitively the install of plexwatch, there is tons of forums to help you if you have problems.
I myself got an error message the first time, what you can do is type this exact error message in google, and you will for sure find someone who got the same, plexwatch forums are very active.
And for the PLEX TEAM, if you can find some spare time to integrate philips hue, and other home automation products, that would be awesome, even more awesome than the job you're already doing !
I hope this tuto can help,
cheers
Quentin