I just finished my Cronjob for the Raspberry-Plex-Box under my TV and thought i share my resulting python-script. Nothing fancy, but a nice way to ad some small home-automation-features to the Rasplex.
The Conjob runs every minute on the Pi and has no notable impact on the performance.
It Checks if there is an active Session. If yes, it logs the session (timestamp connected user, show/movie-title) and sends a push-notification to my iOS device using pushover.
If i am the user with the active session, the script reduces the brightness of my Philips HUE lightbulb in the living-room and sets the Volume of the Sonos speaker in the living-room to zero.
If the script has already seen the active session it will not try to notify me (or control the lights/audio) again - until three hours have passed. Thus it will work again the next day, if i resume a show which i quit a day earlier after just having watched half of it.
Phue, a Python library for the Philips Hue system, ist controlling the light.
What I did:
I connected via SSH and remounted the /flash-directory ( mount -o rw,remount /flash ) to have write-access.
Copied my script and all python dependencies to the folder (i did not use pip or any install scripts just copied all the modules i needed).
Setup a cron with crontab:

Used /storage/downloads/ a my logfile-directory because its writable.
This is a typical logfile-Entry if friends are watching
2014-09-19 15:23:11 Tony watches A Great Hollyday in Sweden
This is a Logfile-Entry with actions, if I have an active session
2014-09-20 16:43:31 JohnDow watches To Protect And Infect, Part 2
2014-09-20 16:43:32 Attempting to connect to the bridge...
2014-09-20 16:43:32 Using ip: 192.168.1.109
2014-09-20 16:43:32 Using username from config: 2f724e2f724e2f724e2f724e
2014-09-20 16:43:32 Sending SetVolume [(u'InstanceID', 0), (u'Channel', u'Master'), (u'DesiredVolume', 0)] to 192.168.1.105
2014-09-20 16:43:32 Starting new HTTP connection (1): 192.168.1.105
2014-09-20 16:43:32 Received status 200 from 192.168.1.105
I am glad for any optimization-suggestions.
These are my first steps with python so please excuse the code-quality. But everything seams to work relatively stable. Is it OK to just drop the needed python modules in the directory? Can i read the log two times (as i did in the code)? So many questions...
Notes
One would need a plexpass to read the active sessions from the Plex-Server.
The Pushover-App works fine, but will have a one-time-purchase after a brief trial-period
The HUE-Bridge has to be manually paird on first run (hit the button on the bridge)
I tried to pause the sonos-speaker but settled on the mute commando. I just wanted the living-room Speaker to be silent. But if i send him the pause-commando while he was part of a sonos zone, i would have been required to unjoin him beforehand, which is a bit tricky, because it can throw an exception if i would blindly send the unjoin-commando and the speaker is currently not in a zone. So i just mute him.
Really great work. Would love to add this to my home cinema.. but buying a PlexPass subscribtion just for dimming lights is a bit expensive! :rolleyes:
One would need a plexpass to read the active sessions from the Plex-Server.
The Pushover-App works fine, but will have a one-time-purchase after a brief trial-period
The HUE-Bridge has to be manually paird on first run (hit the button on the bridge)
I tried to pause the sonos-speaker but settled on the mute commando. I just wanted the living-room Speaker to be silent. But if i send him the pause-commando while he was part of a sonos zone, i would have been required to unjoin him beforehand, which is a bit tricky, because it can throw an exception if i would blindly send the unjoin-commando and the speaker is currently not in a zone. So i just mute him.
Why would you need a PlexPass, surely you mean Plex Login.
I have a nifty little gadget for controlling lights and sound, it's called a finger!
“That’s not all. As of today, even if you don’t have a Plex Pass (and really, why wouldn’t you?), we’ve made Multiuser and Now Playing free for everyone. So now everyone you share with gets their own view history, and you can see what’s being streamed, in real time!”
They opened multiuser and Now Playing for people without subscription… is it now possible to use your script without paying for PlexPass?