Free yourself from the phone

Make an IoT button for under a fiver

According to a recent Business Insider report*, companies are going to spend almost $5 trillion on the Internet of Things in the next five years. Big money. But what can you do for a fiver now? 

How about hack your own light switch with an Amazon Dash button. Why? Because how smart is it if you have to turn your smart light bulb on in your smart home with your smart phone? Surely a switch is simpler? It is. And here’s how. 

What you need 

Take one Amazon Dash button (I used a Pedigree one but any will do). One Mac. And, for this tutorial, one Lifx bulb. 

Step one

Set up your dash button Except for the last step. You do not want to select a product - Just exit the Amazon app.

Just open the Amazon app then Menu > Your Account > Set up a new device (under Dash Devices).

Step two


Download node-dash-button: 
https://github.com/hortinstein/node-dash-button

This repo was massively helpful so a big thanks to https://github.com/hortinstein for creating it!

In the terminal CD to that directory and run: 
npm install node-dash-button

Note: If you’re getting an installation error, I added ‘-test’ to the end of the project name in the package.json and it fixed it for me. 

Then run: 
cd node_modules/node-dash-button

Finally, run:
node bin/findbutton

Once this command runs you should see your network activity - it’s easier if you’re somewhere with a quiet network as it may get confusing. You’ll need to click the button a few times to make sure you’re getting the right one - it should say something like this:
line of code
Step three - Test it out

You can just quickly create a new app and paste in the following code or you can download this test project from my GitHub: https://github.com/sonnyprince/dash-button-connection

var dash_button = require('node-dash-button');
var dash = dash_button("YOUR_MAC_ADD", null, null, 'all'); 
dash.on("detected", function (){
    console.log("found it, yay");
});

Step four - Making an IFTTT Recipe

If you’ve not used IFTTT before, it’s great. IFTTT stands for If This Then That and that’s pretty much how it works. 

All you need to do is create a new task - which they call recipes or applets.

If Amazon Dash button clicked, toggle my Lifx lights.

You can do whatever you like here, you can have it send you an email, post a Tweet, etc.

Go to https://ifttt.com/maker
Sign up and get yourself a user key.
In the main navigation click “Create Applet”
Click “This” then search for Maker - Choose the one that looks on brand with the IFTTT logo
Click “Recieve a web request”
Type in an event name - It should be named “button_pressed”
Click “Create trigger”.

Step five - firing your recipe

Another helpful repo for me was Dasher - I didn't want to reinvent the wheel and maddox had already created a great app for what I needed - that’s firing off an http request on click of my Dash button. You can download it here: https://github.com/maddox/dasher

Once downloaded, in terminal, CD to that directory and run:
npm install

Create a config.json in the root directory and paste in the following code:

{"buttons":[
  {
"name": "lights toggle",
"address": "YOUR_MAC_ADDRESS",
"url":"https://maker.ifttt.com/trigger/button_pressed/with/key/YOUR_KEY",
"method": "POST"
 }
]}

In terminal run:
node app.js

Wow it works! But it’s slow, you have to have the node app running constantly and events queue so now I’m sitting in my room with the lights toggling every ten seconds (they did it twice in this last sentence).

Just as I was talking about how pants these Dash buttons are for home automation I learn about Flic buttons. They look ten times cooler, they connect directly to your phone and they are so responsive. I actually had to fake the Dash button light switch on using a Flic button otherwise the gif would’ve been too big. Plus you can make them have different actions for a click, double click and a hold. I’ve got mine hooked up to Lifx, Sonos and Uber. 

So if you’re looking to hack a Dash button for your Lifx lights - don’t. Buy a Flic button because they’re a better implementation for home automation or get up, and use the switch as it’ll be quicker.

Sources

*http://uk.businessinsider.com/the-internet-of-things-2017-report-2017-1?r=US&IR=T

Post by

Sonny Prince