Skip to content

Instantly share code, notes, and snippets.

@DrEsteban
Forked from trieloff/README.md
Created January 26, 2017 04:30
Show Gist options
  • Save DrEsteban/b8c7fd03d9acaad712cfbde6632b7736 to your computer and use it in GitHub Desktop.
Save DrEsteban/b8c7fd03d9acaad712cfbde6632b7736 to your computer and use it in GitHub Desktop.
A command line alternative to LampStealer

The LampStealer app for Hue does not work with newer versions of the bridge, as the API has changed. This shell script works with fewer dependencies and achieves the same. Install jq and run the shell script after pushing the big button on the bridge.

#!/bin/sh
curl --help >/dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }
jq --version >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. Aborting."; exit 1; }
IP=$@
if [ -z $IP ]; then
# trying to figure the IP address myself
IP=`curl https://www.meethue.com/api/nupnp 2> /dev/null | jq -r ".[0].internalipaddress"`
fi
if [ -z $IP ]; then
echo "Call this script with the IP address of your Hue bridge. You can find it in the iPhone app"
exit 1
fi
USERNAME=`curl -X POST -d '{"devicetype": "HueLights#API"}' http://$IP/api 2> /dev/null | jq -r ".[0].success.username"`
if [ $USERNAME == "null" ]; then
echo "Could not get a username. Press the big button on the bridge before running this script."
exit 2
fi
echo $IP
echo $USERNAME
curl -X PUT -d '{"touchlink":true}' http://$IP/api/$USERNAME/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment