Amazon Dash + Home Assistant + RouterBoard 750UP

Hi All! I don’t know how common RouterBoard users are amongst the Home Assistant community, but I thought I’d share how I got the Amazon Dash buttons to work without running additional code (well, sorta) on my Pi.

Dash Basics
The Amazon Dash button is a cheap ($5 or less) way to get a WiFi enabled button. Amazon has rigged it up so that when you hit the button, they’ll ship you stuff. But, a quick Google shows that you can make a button press do whatever you want.

There’s two basic techniques out there to achieve this: 1) Run a program as root which sniffs all your network traffic, waiting for an APR who-has packet from your Dash; or 2) Setup a hook on your DHCP daemon to fetch a URL when your Dash asks for an IP. I’ve chosen to go for (2), as I try to avoid long running commands as root when I can.

RouterBoard Limitations
RouterBoard can’t HTTP POST. Why is this a problem? Well, I’ve got a script defined in Home Assistant for what I want when the button is pressed, but the only way I know how to trigger it from the RouterBoard is through an HTTP POST. Ugh, RouterBoard! Oh well, I’ll just add a new component to Home Assistant that converts GETs to POSTs.

Rough outline

  • Add a new rule to the RouterBoard to drop all traffic in the FORWARD chain from a new IP address list called steriledash (this way it won’t phone home, or worse, get a firmware update unexpectedly)

  • Add the following code to the DHCP server “Lease Script”, being sure to replace the MAC address with your dash’s MAC and with your HASS IP and the correct script name:

  • Create a new component in /srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/ (or wherever your HASS lives), with the contents:
  • Add the component to configuration.yaml so that it gets loaded and restart home-assistant.

Where to go from here? Well, I’ve got a few ideas, but I don’t know if any of them are worth it to the HASS community:

  1. Convert ros_hack into a more generic arbitrary python (or maybe even execute external command? Sounds pretty risky to me) script. Maybe make the configuration.yaml options a list of dicts ( package, function, path )?
  2. Look into modifying HTTP API to support GET args for situations like these
  3. Document the use of hass.wsgi.register_wsgi_app. I’m not sure where this would live.
1 Like