Created
December 21, 2016 05:02
-
-
Save ryo1kato/4793cc14a6daa8b6f894f15105ebb09d to your computer and use it in GitHub Desktop.
hue toggle script for hue-cli
This file contains hidden or 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 | |
| # SETUP: | |
| # Install hue-cli and register it to a Hue bridge first: | |
| # $ npm install -g hue-cli | |
| # Search the bridge IP | |
| # $ hue search | |
| # 1 stations found | |
| # 1: 192.168.0.106 | |
| ## Then register the CLI to the bridge | |
| # $ hue -H 192.168.0.106 register | |
| # | |
| # USAGE: | |
| # hue-toggle LIGHT_NUM1[,LIGHT_NUM2...] [STEP1[,STEP2...]] | |
| get_state () { | |
| total_brightness=255 | |
| total_onoff='off' | |
| # off -> on -> dim | |
| for l in $lights | |
| do | |
| # format: "num on_off dimmer name..." | |
| state=( $(hue lights $l) ) | |
| onoff=${state[1]} | |
| brightness=${state[2]} | |
| [ $brightness -lt $total_brightness ] && total_brightness=$brightness | |
| [ $onoff = on ] && total_onoff='on' | |
| done | |
| case $onoff in | |
| off) echo 'off';; | |
| on) echo $total_brightness;; | |
| esac | |
| } | |
| rotate () { | |
| local state="$1" | |
| if [[ $state = off ]] | |
| then | |
| echo "{\"on\": true, \"bri\": ${steps[0]}}" | hue lights $lights state | |
| else | |
| for step in "${steps[@]}" | |
| do | |
| # Looks the max value is 254, even when we set it to 255 | |
| if (( state < step && step <= 254 )) | |
| then | |
| hue lights ${lights} "=$step" | |
| return | |
| fi | |
| done | |
| hue lights ${lights} off | |
| fi | |
| } | |
| lights="$1" | |
| steps_comma="${2:-30,254}" | |
| steps=(${steps_comma//,/ }) | |
| rotate $(get_state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment