Skip to content

Instantly share code, notes, and snippets.

@mogenson
Created March 2, 2020 02:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogenson/b653f714e1e6a69fa14d73bfe9f2a033 to your computer and use it in GitHub Desktop.
Save mogenson/b653f714e1e6a69fa14d73bfe9f2a033 to your computer and use it in GitHub Desktop.
A bash script to change the color of a Philips Wiz WiFi light bulb throughout the day
#!/bin/bash
IP=192.168.86.24
PORT=38899
while :
do
HOURS=$(date +"%-H")
MINUTES=$(date +"%-M")
MINUTES=$(($HOURS * 60 + $MINUTES))
HUE=$(($MINUTES * 360 / 1440))
case $(($HUE / 60)) in
0)
R=255
G=$((255 * ($HUE - 0) / 60))
B=0
;;
1)
R=$((255 * (120 - $HUE) / 60))
G=255
B=0
;;
2)
R=0
G=255
B=$((255 * ($HUE - 120) / 60))
;;
3)
R=0
G=$((255 * (240 - $HUE) / 60))
B=255
;;
4)
R=$((255 * ($HUE - 240) / 60))
G=0
B=255
;;
5)
R=255
G=0
B=$((255 * (360 - $HUE) / 60))
;;
*)
R=255
G=255
B=255
;;
esac
printf '{"method":"setPilot","params":{"r":%d,"g":%d,"b":%d}}' $R $G $B > /dev/udp/$IP/$PORT
printf "It's $MINUTES minutes past midnight for a hue of $HUE degrees and an RGB value of #%02X%02X%02X\n" $R $G $B
sleep 240
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment