Skip to content

Instantly share code, notes, and snippets.

@thomasjonas
Created September 9, 2019 16:19
Show Gist options
  • Save thomasjonas/5d05c9e651e06270841f54a6a2897e07 to your computer and use it in GitHub Desktop.
Save thomasjonas/5d05c9e651e06270841f54a6a2897e07 to your computer and use it in GitHub Desktop.
Bash script to turn off all Philips Hue Lights
# This script requires jq (https://stedolan.github.io/jq/) for JSON parsing. Would be great to get rid of that dependency.
# Besides that you need to create an API user for you Philips Hue Bridge as described here:
# https://developers.meethue.com/develop/get-started-2/#so-lets-get-started
#!/bin/bash
HUE_API_ADDRESS=IP_ADDRESS_OF_HUE_GOES_HERE
HUE_API_USER=USER_OF_HUE_API_GOES_HERE
LIGHTS=$(curl -s http://$HUE_API_ADDRESS/api/$HUE_API_USER/lights | jq 'keys[]')
for i in $LIGHTS
do
ID=$( echo "$i" | tr -d '"')
curl -X PUT -s http://$HUE_API_ADDRESS/api/$HUE_API_USER/lights/$ID/state -H 'Content-Type: application/json' -d '{"on": false }'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment