Skip to content

Instantly share code, notes, and snippets.

@quantenschaum
Created October 9, 2017 12:52
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 quantenschaum/f0b0810268177ce26a8e6111d292f9e1 to your computer and use it in GitHub Desktop.
Save quantenschaum/f0b0810268177ce26a8e6111d292f9e1 to your computer and use it in GitHub Desktop.
simple shell script for Philips HUE
#!/bin/bash
# !!!!!!!!!!!!!! edit URL and TOKEN
URL="http://hue/api/TOKEN/lights/"
LIGHTS=""
while [[ "$1" -gt 0 ]]; do
LIGHTS="$LIGHTS $1"
shift
done
JSON=""
while [ "$#" -gt 0 ]; do
V=$2
case $1 in
--on)
X="\"on\":true"
shift 1
;;
--off)
X="\"on\":false"
shift 1
;;
--bri)
if [ "$V" -eq 0 ]; then
X="\"on\":false"
else
X="\"on\":true,\"bri\":$(echo $[(V*254)/100])"
fi
shift 2
;;
--hue)
X="\"hue\":$(echo $[(V*65535)/100])"
shift 2
;;
--sat)
X="\"sat\":$(echo $[(V*254)/100])"
shift 2
;;
--ct)
X="\"ct\":$(echo $[(V*346)/100+154])"
shift 2
;;
--fade)
X="\"transitiontime\":$(echo $[V*10])"
shift 2
;;
esac
JSON="$JSON,$X"
done
JSON="{${JSON#,}}"
echo "request"
echo "$JSON" |jq
echo "response"
for L in $LIGHTS; do
curl -s -XPUT "${URL}${L}/state" -d "${JSON}" |jq
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment