Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created June 5, 2018 17:07
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 AndrewVos/253c799e2448d8fc1b9a6ca5f8b5573d to your computer and use it in GitHub Desktop.
Save AndrewVos/253c799e2448d8fc1b9a6ca5f8b5573d to your computer and use it in GitHub Desktop.
Flash your hue lights on and off
#!/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