Created
June 5, 2018 17:07
-
-
Save AndrewVos/253c799e2448d8fc1b9a6ca5f8b5573d to your computer and use it in GitHub Desktop.
Flash your hue lights on and off
This file contains hidden or 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
#!/usr/bin/env bash | |
# WARNING: THIS ACTUALLY MADE ME FEEL A BIT SICK. Maybe make the sleeps longer below before you try this out | |
set -euo pipefail | |
IFS=$'\n\t' | |
HUE_IP=$(curl https://www.meethue.com/api/nupnp 2> /dev/null | cut -d '"' -f 8) | |
function create-hue-user() { | |
curl \ | |
--request POST \ | |
--header "Accept: application/json" \ | |
--data '{"devicetype":"my_hue_app#andrew"}' \ | |
"http://$HUE_IP/api" | |
} | |
if [[ ! -f "hue-api-key" ]]; then | |
RESULT=$(create-hue-user) | |
if [[ "$RESULT" =~ "link button not pressed" ]]; then | |
echo | |
echo "Press the button on the Hue hub and then press ENTER..." | |
read | |
fi | |
KEY=$(create-hue-user | cut -d '"' -f 6) | |
echo "$KEY" > "hue-api-key" | |
fi | |
KEY=$(cat "hue-api-key") | |
function set-brightness() { | |
for light in $(seq 1 2); do | |
curl \ | |
--request PUT \ | |
--header "Accept: application/json" \ | |
--data '{"on": true, "bri": '"$1"'}' \ | |
"http://$HUE_IP/api/$KEY/lights/$light/state" | |
done | |
} | |
for x in $(seq 1 100); do | |
set-brightness 100 | |
sleep 0.5 | |
set-brightness 150 | |
sleep 0.5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment