Amazon Dash button hacks: 6 ways to build your own low-cost connected home

Amazon Dash button hacks: 6 ways to build your own low-cost connected home

How to set up your Dash button to do anything

Setting up your Dash button isn’t as complex as you would think, requiring only a Raspberry Pi or an always-on computer, a bit of basic Python coding (which we will show you in a moment) and an application such as IFTTT’s Maker system or Cloudstitch’s free, Google Docs-powered Magic Form.

To get started, you’ll first need to download the Unix-powered Scapy and a Python editor. Don’t worry if you’re not running Linux or OS X; you can also get Scapy to work on Windows (with a bit of effort).

When you’re ready to go, write a short Python program in your Python editor to tell Scapy to look out for your Amazon Dash button’s unique Mac address. Paste the below into your Python program’s editor:

from scapy.all import *

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
	if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
  	print "ARP Probe from: " + pkt[ARP].hwsrc

print sniff(prn=arp_display, filter="arp", store=0, count=10)

This code will listen in for an ARP probe (the request your Dash button makes to join your Wi-Fi network), and spot the button’s Mac address. When you press a Dash button, the Python script you’ve just written will record the device’s Mac address, allowing you to hard-code it in to your Python program, using custom names to indicate what’s what.

To do this, copy and paste the Python code below, replacing the empty fields with the correct information.

from scapy.all import *
def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
	if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
  	if pkt[ARP].hwsrc == '[button MAC address]':
        # [insert button1 name]
    	print "Pushed [button name]"
  	elif pkt[ARP].hwsrc == '[button MAC address]':
        # [insert button2 name]
    	print "Pushed [button name]"
  	else:
    	print "ARP Probe from unknown device: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)

At this point, you have two options:

  1. Use Magic Form to push the data to a Google Sheets document that you can view or integrate with an IFTTT recipe
  2. Link your button directly to an IFTTT recipe using its Maker API

Doing it the Magic Form way

If you want to use the Magic Form, create a Cloudstitch account for free and set up your own Magic Form. This will give you a unique URL to which you can send data packets for adding to a spreadsheet.

Add this URL to your Python program, so it can feed the relevant data to the spreadsheet. Your final Python code should look something like this:

from scapy.all import *
import requests
import time
MAGIC_FORM_URL = '[INSERT URL HERE]'
def record_[insert parameter name]():
  data = {
	"Timestamp": time.strftime("%Y-%m-%d %H:%M"),
	"Measurement": '[What you want to record]'
  }
  requests.post(MAGIC_FORM_URL, data)
def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
	if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
  	if pkt[ARP].hwsrc == '[button MAC address]':
        # [insert button1 name]
    	print "Pushed [button name]"
  	elif pkt[ARP].hwsrc == '[button MAC address]':
        # [insert button2 name]
    	print "Pushed [button name]"
  	else:
    	print "ARP Probe from unknown device: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)

Doing it the IFTTT Maker way

IFTTT’s Maker Channel allows tinkerers to connect any internet-enabled device capable of making URL requests to an IFTTT recipe. Maker also allows any other connected service to send requests to an internet-enabled device, but this isn’t important for setting it up to work with an Amazon Dash button.

After writing the Python script to determine which Dash button is which, create an automation that can work with a Raspberry Pi (find instructions here if you’re unsure) to trigger Maker recipes.

When you’ve linked your IFTTT account to the Maker Channel, you can set about creating events for your triggers. Event names are there to help you remember what you’ve created the trigger for. Once events are named, Maker will spit out a unique code for you to incorporate into the Pi automation’s web request.

For an event to be triggered successfully, your Python code has to direct the Pi to a specific web address:

https://maker.ifttt.com/trigger/[event_name]/with/key/[unique_code]

When this is done, you can use IFTTT to link that Maker request to any of its 218 channels, opening a Dash button’s potential up to hundreds of different applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.