Skip to content

Instantly share code, notes, and snippets.

@choffee
Created January 5, 2016 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choffee/062e8fa6622028da67ef to your computer and use it in GitHub Desktop.
Save choffee/062e8fa6622028da67ef to your computer and use it in GitHub Desktop.
Post the cheerlight color to a hipchat room.
#!/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