Amazon Dash + LIFX

Intro

I love my LIFX. It a little on the pricer side of things, but it does provide a great experience. I mean after all it is lighting, an essential part of the modern world. Although great, one thing I think it lacks is a stand-alone remote. It's super cool that I can control my lights from the comfort of my iPhone, but when I get home or am leaving the house, I sometimes crave for that immediacy a switch gives.

As someone with a hardware background, I was thinking of developing hardware to fulfill this task. I literally daydreamed about this and exactly how to do it. In the end, I wanted a polished product too in a nice form factor. In my head, it was this: source parts, buy parts, create a physical prototype, program the board, create PCB, create enclosure, iterate. This to me involved a ton of time and probably around $100-$150. Although super tempting, I dedicate my spare time in indie app making so this wasn't a viable option.

Reading many articles online, I stumbled upon this article one day.

How I Hacked Amazon’s $5 WiFi Button to track Baby Data

Uhm...yes. EVERYTHING I COULD WISH FOR, FOR $5. YES YES YES! This made me super excited and I immediately found a Dash button in my hands.

Now for the fun part: putting the pieces together.

By applying Atwood's Law, I decided to write it in JavaScript, also because I'm quite a fan of the breath of projects you can find as you will soon see.

"Any application that can be written in JavaScript, will eventually be written in JavaScript." - Atwood's Law

Concept

There are two parts to this.

Since the Amazon Dash is a low-power device, that means there is no way it can stay connected to your WI-FI network 24/7. The battery, in that case, would be drained immediately. That means everytime the button is pressed, it has to connect to the network. This is done via an ARP probe. By scanning the network for the presence of the Dash's ARP probe, we can then map that to anything we want. Bingo.

Next we take care of the LIFX. Lucky for us, LIFX provides us with a developer's API! So you can guess the next step, when we detect the presence of the Dash's ARP probe, call an LIFX API endpoint, in this case I would like to toggle power.

Tutorial

Step 1: Prevent Amazon Dash from ordering anything Follow the instructions Amazon gives you to get going. Do everything they ask for, but do not complete the last step of selecting the particular product you want to order.

Step 2: Finding Amazon Dash's MAC address I found my Dash's MAC address simply by following the steps in: node-dash-button
To be sure of the correctness of the Dash's MAC address I pressed the Dash a few times. Make sure to copy down the MAC address.

Step 3: Get a LIFX API token Use this link to register and get your API token. Make sure to copy down the token. https://cloud.lifx.com

Step 4: Putting it all together

var DASH_MAC_ADDRESS = "PLACE_AMAZON_DASH_HERE";  
var LIFX_API_TOKEN = "PLACE_LIFX_API_TOKEN_HERE";

var dash_button = require('node-dash-button');  
var dash = dash_button(DASH_MAC_ADDRESS);

var lifxObj = require('lifx-api');  
var lifx = new lifxObj(LIFX_API_TOKEN);

dash.on("detected", function (){  
    lifx.listLights('all', function(res) {
        var jsonRes = JSON.parse(res);
        var id = jsonRes[0].id; //using LIFX bulb ID

        lifx.togglePower(id, function(res) {
            console.log(res);
        });
    });
});

So what this program does is simply look for the presence of the dash button being pressed and act upon it. (Full source code below)

Conclusion

I can't really be disappointed. Hacking a $5 device to do something it was not intended for without any physical hacking. I also like the fact that I can change the intent of the button at the flick of a switch (pun intended) since it does not have to be programmed into the Dash.

The only downside I've found is that the program must continuously run. I have yet to profile the program I wrote, but the idea of having a program continuously poll for a damn button press makes me feel uncomfortable.

Shout out to @edwardbenson for showing us the first Proof-of-Concept and viability of the Dash button beyond it's true intent.

Full project: https://github.com/StevenTso/LIFX-Dash-Button

I'm @steventsooo on Twitter. I would love to hear what you think!


© 2017
© 2017