Amazon Dash button and EventGhost

If you have a question or need help, this is the place to be.

Amazon Dash button and EventGhost

Postby luma » Thu Sep 24, 2015 12:20 am

I ran across this article about hacking the Amazon Dash button and thought I'd order myself one to see what I can do. Using the code in the article I was able to kludge together a script to send commands to EG like so:

Image

There is a latency on the order of 5 seconds between the button press and event showing up in EG, so this won't make a great light switch. Still, for $5 it's a button that you can use anywhere in WiFi range to send an event to EG which is pretty reasonable.

The source code I'm using appears below. Here are a few notes on how this is setup:
  • I have no idea what I'm doing with Python, so getting all the modules setup was the hardest part for me. Also, don't laugh too hard at my code as I'm pretty sure I'm doing any number of dumb things.
  • I'm running the 32bit version of Python 2.7 on this system (installed some time ago, not sure why I used 2.7 or 32bit at the time but it works OK so no point in breaking it)
  • I installed the modules found here to get scapy working
  • Installed the latest WinPcap
  • Then I installed PIP
  • Added C:\Python27 and C:\Python27\Scripts to my PATH
  • Then used PIP to install requests with the command:
    Code: Select all
    pip install requests
  • I followed the guide in the article, then hacked together a version of the script that will send a GET request to my EG server
Code: Select all
from scapy.all import *
import requests
import time

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 == '74:c2:46:f2:31:4c': # On Button 1
        print time.strftime("%Y-%m-%d %H:%M:%S") + ": ARP from " + pkt[ARP].hwsrc + ", requesting http://10.0.0.160/index.html?Dash.Button.On.1"
        r = requests.get('http://10.0.0.160/index.html?Dash.Button.On.1')
      else:
        print "ARP Probe from unknown device: " + pkt[ARP].hwsrc

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


I suspect somebody smarter than me could turn this into an EG plugin. Until then, this seems to work reliably (if a little slowly).
luma
 
Posts: 29
Joined: Tue Jan 26, 2010 12:35 am

Return to General Support

Who is online

Users browsing this forum: Bing [Bot] and 9 guests