Introduction: Amazon Dash Button Hack (Raspberry Pi IOT Button)

Picture of Amazon Dash Button Hack (Raspberry Pi IOT Button)

So I have a Raspberry Pi running a lot of home automation and I wanted a standalone button that could trigger an event. There are a lot of expensive IOT buttons out there but I had heard that you could re-purpose an Amazon Dash Button (£5) to do the job. I tried a lot of the online tutorials out there and couldn't get them to work so I went my own route...

My method requires:

  • An Amazon Dash Button
  • A Raspberry Pi
  • Limited knowledge of Python
  • A router that allows you to send its logs to a SysLog server (I have a Sky Hub)

And works as follows:

  1. The Dash Button is pressed
  2. It connects to the router and tries to establish a connection to the internet but this is blocked by a firewall rule
  3. The connection attempt is logged in the routers logs and sent to the Raspberry Pi which is acting as a SysLog server
  4. The Raspberry Pi receives the log entry (which contains the MAC address of the Dash Button) and triggers an event

Step 1: Partially / Fully Setup the Amazon Dash Button

As with most other Amazon Dash Button hacks you first need to register your Amazon Dash Button but stop the process just before you select a product. This sets up the Dash Button to talk to your router but stops it going so far as to order you loads of Finish Dishwasher Tablets :-)

Optional: The hack method I am using will eventually stop the Dash Button from talking to Amazon at all and so you could (in theory) fully setup the Dash Button at this stage and perhaps even put in a quick order to get your £5 off.

Step 2: Send Router SysLog to Raspberry Pi

Picture of Send Router SysLog to Raspberry Pi

The method of doing this will vary from router to router but it was very easy on my Sky Hub. I simply logged into the admin page of the router and provided the IP address of my Raspberry Pi in the SysLog Server address.

Note: My Raspberry Pi has a static IP address and so it will not change.

Step 3: Setup Raspberry Pi As SysLog Server

To get the Raspberry Pi to receive the SysLog now being sent by my router I found a neat little script on GitHub:

https://gist.github.com/marcelom/4218010

I made some minor alterations to the code for my purposes. Note the MAC address in the script will need to be swapped out for the MAC address of your Dash Button.

<p>#!/usr/bin/env python</p><p>import SocketServer
import time
import datetime</p><p>HOST, PORT = "0.0.0.0", 514
lastRun = datetime.datetime.now() - datetime.timedelta(seconds=60) #This initiates the lastRun variable with an arbitrary time</p><p>class SyslogUDPHandler(SocketServer.BaseRequestHandler):
	
	def handle(self):
		data = bytes.decode(self.request[0].strip())
		socket = self.request[1]
		global lastRun
		if '<strong>ac:63:be:b9:e2:f1</strong>' in str(data)\
		and datetime.datetime.now() > lastRun + datetime.timedelta(seconds=35): #You need to replace the MAC address with the MAC address of your Dash Button
		    print "Button Pushed!"
		    lastRun = datetime.datetime.now()</p><p>if __name__ == "__main__":
	try:
		server = SocketServer.UDPServer((HOST,PORT), SyslogUDPHandler)
		server.serve_forever(poll_interval=0.5)
	except (IOError, SystemExit):
		raise
	except KeyboardInterrupt:
		print ("Crtl+C Pressed. Shutting down.")</p>

Step 4: SysLog the Button Press

So the SysLog is being sent to the Raspberry Pi and the Raspberry Pi is set up to receive the log.

Now we need to get the MAC address of the Dash Button to appear in the SysLog when pressed, this way the Python script will see it and will register a button press.

The way I was able to do this on my Sky Hub was as follows:

  1. First give the Dash Button a static IP address
  2. Next setup a firewall rule to prevent that local IP from accessing the web at all
    1. You need to enable logging for this firewall rule so that it appears in the SysLog
    2. This has the added benefit of preventing the Dash Button from talking to Amazon (and placing orders!)

Step 5: Final Test

Now for the final test:

  1. Run the python script on the Raspberry Pi
  2. Press the Amazon Dash Button
  3. The router should catch the attempt to connect to the internet and block it (firewall rule)
  4. The attempt should be logged in the SysLog
  5. The Raspberry Pi should receive the SysLog entry and detect the specified MAC address in the log text
  6. "Button Pushed!" should be printed on the Pi terminal

Notes:

  • You will see that the python script prevents "Button Pushed!" from being printed if it has already done so in the last 35 seconds. This is because the Sky Hub would log a number of SysLog entries whilst the Dash Button made repeated attempts to connect. After 30 seconds the Dash Button gives up.
  • You can change the "print "Button Pushed!" line for any event you want to trigger. I've set my one up to turn all my downstairs lighting on when pressed.

Comments

daigakusei (author)2016-09-14

Why use an extra router ?

With an Usb/Wlan Dongle and some config, an Raspi can work as Wireless-Hotspot and the syslog send to localhost:portnumber.

No extra device necessary.

Here an link for RPI-Wireless-Hotspot config tutorial.

http://elinux.org/RPI-Wireless-Hotspot

Dullage (author)daigakusei2016-09-18

Nice idea! I'll have to give this a go at some point.

DIY Hacks and How Tos (author)2016-09-11

Clever idea. The possibilities are endless.

About This Instructable

2,635views

22favorites

License:

More by Dullage:Amazon Dash Button Hack (Raspberry Pi IOT Button)
Add instructable to: