Created
January 5, 2016 11:06
-
-
Save choffee/062e8fa6622028da67ef to your computer and use it in GitHub Desktop.
Post the cheerlight color to a hipchat room.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Expects some env variables set | |
readonly auth_token="${HIPCHAT_AUTH_TOKEN}" | |
readonly room="${HIPCHAT_CHEER_ROOM}" | |
if [[ s"$auth_token" == "s" ]] ; then | |
echo "You need to set HIPCHAT_AUTH_TOKEN and HIPCHAT_CHEER_ROOM" | |
echo "environment variables" | |
echo "Get your auth token from: https://www.hipchat.com/docs/apiv2" | |
exit 1 | |
fi | |
oldcolor="black" | |
while true; do | |
color=$(curl http://api.thingspeak.com/channels/1417/field/1/last.txt) | |
if [[ $color != $oldcolor ]] ; then | |
oldcolor=$color | |
if echo "'yellow', 'green', 'red', 'purple', 'gray'" |grep $color >/dev/null ; then | |
bg_color=$color | |
else | |
bg_color=random | |
fi | |
curl -d '{"color":"'${bg_color}'","message":"Cheerlights are now '${color}'","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://uoyits.hipchat.com/v2/room/${room}/notification?auth_token=${auth_token} | |
echo $color | |
fi | |
sleep 30 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment