Created
March 2, 2020 02:02
-
-
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
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 | |
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