Created
January 6, 2020 20:11
-
-
Save wido/4e9ea46c628a1c84f049d77c27e37848 to your computer and use it in GitHub Desktop.
Philips Hue control with cURL
This file contains 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
#!/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 <[email protected]> | |
# | |
# 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