Skip to content

Commit

Permalink
Load username from .huerc
Browse files Browse the repository at this point in the history
  • Loading branch information
inket committed Jun 30, 2020
1 parent 8bb6ca9 commit 53ae785
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions hue.sh
Expand Up @@ -6,13 +6,20 @@
# Detects Bridge IP automatically
bridgeIP=$(curl -s https://discovery.meethue.com | cut -d: -f3 | tr -d '"}]')

source ~/.huerc

if [ ! "$HUE_USERNAME" ]
then
echo "Must specify HUE_USERNAME in ~/.huerc" >&2
exit 1
fi

# REQUIRED - Get your own token, see link at the top
# Example Token
userToken="8BGXPDAKtXVoBdlDlrauoPJP-6JFENcEq4m6F05t"
username="$HUE_USERNAME"

function getLightsInfo {
# Get all light attributes
curl http://$bridgeIP/api/$userToken/lights/
curl http://$bridgeIP/api/$username/lights/
}

# My Light ID's, yours will differ. Call getLightsInfo
Expand All @@ -21,38 +28,38 @@ lights=(3 4 5)
lightID=$2

function getLightStatus {
curl http://$bridgeIP/api/$userToken/lights/$lightID
curl http://$bridgeIP/api/$username/lights/$lightID
}

function getAllLightStatus {
# Get individual attributes
for i in ${lights[@]}
do
curl http://$bridgeIP/api/$userToken/lights/$i
curl http://$bridgeIP/api/$username/lights/$i
done
}

function lightOn {
# Turn on/change brightness single light
curl -H 'Content-Type: application/json' -X PUT -d '{"on":true, "bri":200}' http://$bridgeIP/api/$userToken/lights/$lightID/state
curl -H 'Content-Type: application/json' -X PUT -d '{"on":true, "bri":200}' http://$bridgeIP/api/$username/lights/$lightID/state
}

function lightOff {
# Turn off single light
curl -H 'Content-Type: application/json' -X PUT -d '{"on":false}' http://$bridgeIP/api/$userToken/lights/$lightID/state
curl -H 'Content-Type: application/json' -X PUT -d '{"on":false}' http://$bridgeIP/api/$username/lights/$lightID/state
}

function lightsOn {
for i in ${lights[@]}
do
curl -H 'Content-Type: application/json' -X PUT -d '{"on":true, "bri":200}' http://$bridgeIP/api/$userToken/lights/$i/state
curl -H 'Content-Type: application/json' -X PUT -d '{"on":true, "bri":200}' http://$bridgeIP/api/$username/lights/$i/state
done
}

function lightsOff {
for i in ${lights[@]}
do
curl -H 'Content-Type: application/json' -X PUT -d '{"on":false}' http://$bridgeIP/api/$userToken/lights/$i/state
curl -H 'Content-Type: application/json' -X PUT -d '{"on":false}' http://$bridgeIP/api/$username/lights/$i/state
done
}

Expand Down

0 comments on commit 53ae785

Please sign in to comment.