[HowTo] Amazon Dash / scene activation

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Post Reply
Posts: 29
Joined: 14 Apr 2015 02:52

[HowTo] Amazon Dash / scene activation

Post by jhmartin »

I have a MikroTik RouterBOARD 750GL as my router and a Pi running the Razberry. I have a Amazon Dash that I've co-opted to trigger a light scene.

A similar configuration will work with any router that lets you set a destination NAT.

First I configured a static IP for my Dash based on its MAC address (its not printed on the device or available online as far as I can tell, so I had to look for the most recent lease / it registered as 'WICED DHCP Client'). I configured it w/Amazon normally.

Then I add a destination-nat to force all outgoing tcp connections to hit my razberry:

Code: Select all

/ip firewall nat
add action=dst-nat chain=dstnat protocol=tcp src-address= to-addresses= to-ports=8081
where is my razberry.

I then run a ruby daemon that listens for connections and triggers a scene whenever the connection occurs; first logging in then triggering the scene.

Code: Select all

require 'socket'
require 'net/http'

server = TCPServer.new 8081

loop do
  client = server.accept    # Wait for a client to connect
  req = Net::HTTP::Post.new(uri)
  req.body = '{"form":true,"login":"admin","password":"YOURPASSWORD","keepme":false,"default_ui":1}'

  res = Net::HTTP.start(uri.hostname, uri.port) do |http|
  cookie = res.response['set-cookie'].split('; ')[0]

  urls = %w(/ZAutomation/api/v1/devices/ZWayVDev_zway_10-0-37/command/off)

  urls.each do |url|
    uri = URI("{url}")
    req = Net::HTTP::Get.new(uri)
    req['Cookie'] = cookie
    res = Net::HTTP.start(uri.hostname, uri.port) {|http|

Posts: 1
Joined: 10 May 2016 17:34

Re: [HowTo] Amazon Dash / scene activation

Post by manonstreet »

I tried to do something similar with my TomatoUSB router and a python script.

I am able to successfully set the static DHCP address for the dash button, and DNAT the request (which attempts to communicate to parker-gateway-na.amazon.com); however the setup does not work.

After a DNS lookup to the hardcoded DNS servers in the Dash ( and, the Dash sends a SYN packet to what it thinks is the amazon domain, but the DNAT rewrites it to actually be an IP on my network running my python code. That code will respond with a SYNACK, which goes back to the button. But the source IP won't match what it is expecting. It sent a packet to one destination but gets a response from another, so the Dash will discard the packet.

How is your code actually functioning? Does the Ruby code (server.accept) get called with just a SYN packet? I would think it would require a 3-way handshake before that fires. As far as I can tell, the only way to get the handshake established is to SNAT the return traffic back to to the button. My issue is that my Dash and my python code are on the same subnet, therefore the router never has an opportunity to SNAT the traffic since it goes direct via layer 2.

Post Reply