Skip to content

Instantly share code, notes, and snippets.

@trieloff
Created October 24, 2015 17:23
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save trieloff/76c7c24ecff7d694602d to your computer and use it in GitHub Desktop.
Save trieloff/76c7c24ecff7d694602d 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
@if-drew
Copy link

if-drew commented Dec 13, 2017

You need to wrap the $USERNAME variable in quotes. If line #18 returns '' then line #20 resolves to if [ == "null"]; then which throws an error.

More info https://stackoverflow.com/a/15573770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment