Skip to content

Instantly share code, notes, and snippets.

@dkordik
Last active December 21, 2015 20:39
Show Gist options
  • Select an option

  • Save dkordik/6363065 to your computer and use it in GitHub Desktop.

Select an option

Save dkordik/6363065 to your computer and use it in GitHub Desktop.
SleepWatcher setup for Hue lights to turn off and on when my screen does. SleepWatcher lets you run arbitrary commands on wake/sleep/displaydim/displayundim. It can be found here: http://www.bernhard-baehr.de/ - get an API key for your Hue by following these steps: http://developers.meethue.com/gettingstarted.html
#!/bin/bash
APIKEY="newdeveloper"
function turnOff {
curl -X PUT -d"{\"on\": false }" http://192.168.2.142/api/$APIKEY/lights/$1/state
}
turnOff 1
turnOff 3
#!/bin/bash
APIKEY="newdeveloper"
function turnOn {
curl -X PUT -d"{\"on\": true }" http://192.168.2.142/api/$APIKEY/lights/$1/state
}
turnOn 1
turnOn 3
#this goes in: /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher-20compatibility.plist
#start daemon with: launchctl load /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher-20compatibility.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>de.bernhard-baehr.sleepwatcher</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/sleepwatcher</string>
<string>-V</string>
<string>-s /etc/rc.sleep</string>
<string>-w /etc/rc.wakeup</string>
<string>-S /Users/dkordik/.displaysleep</string>
<string>-W /Users/dkordik/.displaywake</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment