Philips hue : dim lights when movie starts

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

Very cool. Thanks for sharing with the community!

AWESOME!

Cool, I am going to give this a go as well. Be nice if there was just a way to run a script as a move starts/stops etc. Would save the whole emailing bit and you could just run the script to fire off HUE Server. Perhaps this does exist already? I haven't had a chance to look a great deal for it. 

This is probably the best work around at the moment. Thanks!

Plex team, is there amy chance to implement that “future” to pht native?

Anyone here clever enough to hack up the plexWatch perl script to just run an apple script instead of sending a notification message? Ideally we get this just built into plex but I would suspect that is a while away given the small number of users that would want this. using plexwatch to run an apple script combined with HUE SERVER would be a decent workaround while we all wait :) 

plexWatch supports external scripts now, https://forums.plex.tv/topic/72552-plexwatch-plex-notify-script-send-push-alerts-on-new-sessions-and-stopped/?p=658098


Current version: https://github.com/ljunkie/plexWatch/tree/v0.3.1

fantastic ljunkie! Thanks for commenting. Will try this in the next day or two and see how it all goes. 

Amazing idea! 

Thanks everyone for all these improvements !

Can't wait to test the new plexWatch with external script.

Just set it up and works perfectly. 

Just set it up and works perfectly. 

@ skam

maybe you could share with us the steps to make it "work perfectly" ? that would be great :)

Great! Thanks.

@ skam

maybe you could share with us the steps to make it "work perfectly" ? that would be great :)

Sorry, I don't have time at the moment to write up a full guide but basically following the guide above, instead of modifying config.pl from plexwatch to send an email scroll down a bit further to the 'home automation' section.

        'homeAutomation' =>     {
            'enabled'       => 1, ## 0 or 1 - set to 1 to enable homeAutomation script
            'push_watched'  => 1, #stop
            'push_watching' => 1, #start
            'push_paused'   => 0, #pause
            'push_resumed'  => 0, #resume
 
            'script_format' => {
                'start'   =>  'osascript /opt/plexWatch/livingroomoff.scpt',
                'paused'  =>  '/usr/local/bin/homeAutomation.pl {user} {state}',
                'resumed' =>  '/usr/local/bin/homeAutomation.pl {user} {state}',
                'stop'    =>  'osascript /opt/plexWatch/livingroomon.scpt',
 

Set which items you want it to trigger on. I just put it on start and stop, not pause and resume, but you could do those too. Then I created 2 scripts using the AppleScript Editor. One for turning the lights off and one for turning them on. 

I have a couple of lamps setup in my living room  and they are in a group called "Living Room" so the script to turn them off when the movie starts is saved here /opt/plexWatch/livingroomoff.scpt and looks like this

tell application "Hue Server" to run command "Living Room off"

and when the movie finishes or is stopped I have them turn on again by running the script saved here /opt/plexWatch/livingroomon.scpt and that looks like this

tell application "Hue Server" to run command "Living Room on"

I configured plexwatch to run everyevery 5 seconds so the lights turn off and come on fairly quickly. The timing on this can be configured whens setting up the LaunchAgent which is described here  https://github.com/ljunkie/plexWatch

Hopefully that is enough info to get you started, sorry if i have missed anything I wrote this in a bit of a rush. 

Exciting!!! Keep up the good work!  :)

I wish more were developed to support Phillipps Hue in its application in Plex!

I have been doing this with Plex, Alexa, Harmony Hub and Samsung smartthings hub.
When I ask Alexa to turn on Plex she launches the app on my FireTV and turns the lights off…
If I ask Alexa to pause she pauses Plex and brings my lights up in my theater to 10%… (kitchen light too for popcorn or snacks)
Ask Alexa to play and she resumes the file and dims the lights back down to off…
Ask Alexa to stop and she does that and brings the lights back to the previous state.

This works in all of my apps… Netflix, Amazon Video, Hulu, Plex, HBO.

A real theater style experience!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.