30th November 2015

You may have heard of Amazon’s Dash Button – the tiny wireless device featuring one button, that when clicked will order a pre-selected household item from Amazon, such as washing powder or wet wipes. Useful, if you start running low on something. The devices are $5 each, so quite cheap considering these are WiFi enabled buttons!

I wondered whether it would be possible to “hack” these buttons, to control my Philips Hue bulbs. After a quick Google search, I came across the Node Dash Button library, that lets you listen for Dash Button ARP requests on your network, using Node.js.

There’s also a separate library that enables you to interact with the Philips Hue bridge, Node Hue API.

Combined, these two libraries would enable me to turn on/off my Philips Hue lights through the Amazon Dash Button, as an alternative to using the Philips Hue app on my phone.

So I went ahead and ordered a couple of Amazon Dash Buttons, and here is how I very quickly was able to set them up to control my Hue lights.

Enable the Dash Button

First, I needed to set up the Dash Button on my network, which can be done via the Amazon mobile app (Your Account >> Dash Devices >> Set up a new device). This enabled me to type in the password for my WiFi network, then I had to hold down the button on the Amazon Dash device for 6 seconds to switch it to activation mode.

My phone then played a series of sounds that the Dash Button listens for. Presumably, this is an encoded message containing the WiFi network ID and password. Pretty clever! After a few seconds, the Dash Button connected to my home network.

I then had to make sure I skipped the last part of the Dash Button Setup. Basically, I had to make sure I didn’t select a product to be associated with the Dash Button, otherwise I would end up ordering a bunch of things I didn’t want from Amazon!

Install the two Node libraries

After the Dash Buttons have been activated, I then installed the two Node libraries:

npm install node-dash-button

and

npm install node-hue-api

Finding the Dash Button hardware (MAC) address

The whole process of listening for ARP requests on the network requires that I know which hardware address to listen for. To figure out the Dash Button’s hardware address, I ran the “findbutton” script:

cd node_modules/node-dash-button
node bin/findbutton

This listens for ARP requests on the local network. I then pressed the button on Amazon Dash, to reveal the MAC address:

Watching for arp requests on your local network, please try to press your dash now

possible dash hardware address detected:  dc:ef:09:92:4b:c6

I could then take this address, and build up an array of Dash Buttons to listen for:

var dash = dash_button(["df:eb:09:22:3b:a6", "dc:ef:09:92:4b:c6"]); 

dash.on("detected", function (dash_id){
    console.log("Dash button " + dash_id + " was clicked!");
});

Registering a new user on the Philips Hue bridge

I then needed to connect to the Philips Hue bridge, in order to issue requests to turn lights on/off.

First, I had to add a new user account on the bridge, which can be done by pressing the button on the Hue bridge, then running the script below (all scripts below are based off of the examples from here: https://github.com/peter-murray/node-hue-api).

var HueApi = require("node-hue-api").HueApi;

var hostname = "10.0.0.16",  // IP of the Philips Hue Bridge
    newUserName = null;  // The Hue Bridge will generate a User ID
    userDescription = "Amazon Dash Button User";

var displayUserResult = function(result) {
    console.log("Created user: " + JSON.stringify(result));
};

var displayError = function(err) {
    console.log(err);
};

var hue = new HueApi();

hue.registerUser(hostname, newUserName, userDescription)
    .then(displayUserResult)
    .fail(displayError)
    .done();

This returned a username I could then leverage for the next steps.

Creating a group of lights

Lights can either be controlled individually, or as a group. As I have three Philips Hue bulbs located in the Lounge area, with IDs “1”, “2”, and “3”, I wanted to create a group for those bulbs.

(IDs of each bulb can be obtained by using the “lights()” API, which returns an object containing a list of light bulbs registered with the bridge.)

I used this script to create the group:

var dash_button = require("node-dash-button"),
    hue = require("node-hue-api"),
    HueApi = hue.HueApi,
    lightState = hue.lightState
    dash = dash_button(["dc:ef:09:92:4b:c6"]),
    hostname = "10.0.0.16",
    user = "36b624a82526d45f3ef77a58149cd04f",
    api = new HueApi(hostname, user);

var displayResult = function(result) {
    console.log(JSON.stringify(result, null, 2));
};

api.createGroup("Lounge", [1, 2, 3])
    .then(displayResult)
    .done();

The result returns the ID of the group, which is “1” in my case, as I don’t have any existing groups.

Turning the lights on and off!

I then ended up with this script, which would allow me to turn the group of bulbs on and off by using the Amazon Dash Button:

var dash_button = require("node-dash-button"),
    hue = require("node-hue-api"),
    HueApi = hue.HueApi,
    lightState = hue.lightState
    dash = dash_button(["dc:ef:09:92:4b:c6"]),
    hostname = "10.0.0.16",
    user = "36b624a82526d45f3ef77a58149cd04f",
    api = new HueApi(hostname, user),
    on = false,
    state;

var displayResult = function(result) {
    console.log(JSON.stringify(result, null, 2));
};

state = lightState.create().hue(25000); // Green

dash.on("detected", function (dash_id) {
    console.log("Dash button " + dash_id + " was clicked!");

    if (!on) {
        // Turn on the group of lights
        api.setGroupLightState(1, state.on())
            .then(displayResult)
            .done();
    } else {
        // Turn off the group of lights
        api.setGroupLightState(1, state.off())
            .then(displayResult)
            .done();
    }

    on = !on;
});

And the lights turn on, then off, with each press of the Dash Button! Result!

Green Lights

And this time with red:

...
state = lightState.create().hue(65535); // Red
...

Red Lights