Skip to content

Instantly share code, notes, and snippets.

@wido
Created January 6, 2020 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wido/4e9ea46c628a1c84f049d77c27e37848 to your computer and use it in GitHub Desktop.
Save wido/4e9ea46c628a1c84f049d77c27e37848 to your computer and use it in GitHub Desktop.
Philips Hue control with cURL
#!/bin/bash
#
# Simple script to change lights on Philips Hue using cURL
#
# Source: http://hkionline.net/posts/using-phillips-hue-from-the-command-line
#
# Author: Wido den Hollander <wido@denhollander.io>
#
# YES! Philips Hue also talks IPv6! :-)
IP="[fe80::217:88ff:fea2:7b66%wlp4s0]"
USERNAME="XXXyyyZZZ"
LIGHTS=$(curl -s -H "Accept: application/json" http://${IP}/api/${USERNAME}/lights|jq -r 'keys[]')
change_light_state() {
curl -s -H "Accept: application/json" -X PUT --data "{\"on\": $2}" http://${IP}/api/${USERNAME}/lights/${1}/state
}
for ID in $(echo $LIGHTS); do
change_light_state $ID false
done
for ID in $(echo $LIGHTS); do
change_light_state $ID true
done
sleep 5
for ID in $(echo $LIGHTS); do
change_light_state $ID false
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment