Skip to content

Instantly share code, notes, and snippets.

@AndrewVos

AndrewVos/hue.sh

Created Jun 5, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.