Amazon Dash Button as openHAB Trigger

Unfortunately, like I said above, the Dash script isn’t fully working. I’ve made some updates for things I know were wrong but I’ve not managed to test them fully. I’ve locked down my network and I can’t seem to be able to sniff the ARP packets anymore to do the tests and I’ve not had time to go back and test this.

That being said, the error is caused because the sniffing script is receiving a non-ARP packet You can try changing the code as follows and see if that makes a difference.

Try adding in a check to make sure that the packet is an ARP before trying to get at the data:

#!/usr/bin/python

from scapy.all import *

def arp_display(pkt):
  if ARP in 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=30)

This check is already in place in the dash.py code, it is only missing in the getMac.py script.

From default.ini:

[Sensor5]
Class: dash.dash
Connection: MQTT
; One Address/Destination pair per button, start with 1, increment numbers
; Mac address
Address1: 12:34:56:78:90:12
Destination1: actuators/bounty
Address2: 21:09:87:65:43:21
Destination2: actuators/tide
; -1 means this sensor doesn't need to use the main polling thread, it polls on
; its own
Poll: -1

The MAC addresses are listed as Address1, Address2, etc. Each button has its own unique MAC which you put into this parameter. Coupled with each AddressX parameter there is a DesinationX. If you are using the MQTT connection, this is the topic that the word “Pressed” will be published to when that Dash button’s ARP packet has been detected. If you are using REST, this is the Item name of the Item that represents that particular Dash button in openHAB and to which the word “Pressed” will be pushed when the button’s ARP packet is detected.

So in the example in default.ini, there are two Dash buttons.

Address1: 12:34:56:78:90:12 ; MAC address of the Bounty button as determined via getMac.py or some other means
Destination1: actuators/bounty ; MQTT topic that corresponds with the Bounty button
Address2: 21:09:87:65:43:21 ; MAC address of the Tide button
Destination2: actuators/tide ; MQTT topic that corresponds with the Tide button

Hopefully, as you can see now, the mapping takes place in the .ini file. openHAB never needs to know anything about the MAC address. It just needs to know about the MQTT topic.

Let me know if you get this to work. I’ll update the repo with the change to the getMac.py script to avoid that error now but I’d love to know whether or not it works so I can update the description.

OK, I made some updates to getMac.py and dash.py.

It looks like it is working now, at least it did for me one time. :slight_smile:

Pull from the repo again and let me know if it works for you.

Ok i tried it now some hours, could get it work. Your updates seem to work, getMac delivered an mac i added to the default.ini and the install was ok. I install mosquitto and added the bindings to openhab. I added the items, the rule and updated it with my names. But i can not get the dash button work. I have no idea how to test if there are commands received or something. The rules has not been triggered.

Can someone maybe make a short step by step guide? Or give me some tips how to test if all is working?

Thanks Matt, worked for me on my RPi3 in only a few minutes - and I am a Windows guy :wink:

  1. Follow the instructions from Amazon to set up the Dash button but stop before selecting a product.

  2. Install sensor reporter following the install.sh script in the config folder.

  3. Run getMac.py in the config folder and press the button. You should see an address printed. If your network has lots of ARP traffic you may need to check your router to eliminate the addresses coming from your other devices.

  4. Create a sensorReporter.ini file with a section for the dash, connection (MQTT or REST), and logger. Use the default.iini as a template. The MAC goes in the Address1 field and if using MQTT the topic to publish to guess in Destination1. If using REST the name of the Item goes in Destination1.

  5. Create an Item to represent the Dash button in OH. If using the MQTT, configure the Item to use the MQTT binding for incoming messages in the topic configured in the initial file (Destination1). When the Dash button’s ARP packet is detected sensorReporter will publish “Pressed” to that destination so configure your Item’s transform accordingly.

  6. Testing (in order):

  • Test Dash detection is working: when you ours the button you should see two lines printed to sensorReporter’s log/syslog (depending on how you have logging configured). One says the button press was detected and the other says it is publishing to the destination.
  • Test MQTT: use a command line MQTT client (e.g. mqtt_sub) to subscribe to the Destination1 topic and verify that “Pressed” is being published to the topic when the Dash button is pressed.
  • Test openHAB: Watch openhab.log and verify there are no errors. Watch events.log and verify that your Item is being updated when you press the button. If everything else works up to this point you either have a configuration error in openHAB, your Item, binding config, transform, it rule trigger.
1 Like

Thanks very much,I will test that in the next days.

So, couldn’t wait so I tried direct, no success. I get an error no section logging but I have this section.

The section must match exactly, including case.

[Logging]
File = /var/log/sensorReporter.log
MaxSize = 67108864
NumFiles = 10
Syslog = YES

The above is copied from one of my working logging sections.

I don’t know how finicky Python’s config parsing library is so make sure you do not have any leading spaces or tabs.

Maybe i have an old version? In default.ini it is written like this

[Logging]
File: /var/log/mqttReporter.log
MaxSize: 67108864
NumFiles: 10

Oops! I forgot to check that update in. It is checked in now. But the error should have been complaining about a missing Syslog in the Logging section, not a missing Logging section over all.

I used Networkhealth, that works very well and it’s easy to configure.
I made a youtube video to explain it in detail:

There is no workaround, hacks or skripts. Just a binding and a little change in the openhab.cfg, that’s it! :grin:

And here the german version:

1 Like

Thanks for that! Did you set the Dash button to a fixed IP address in your router?

Is there a way to archieve this, without increasing the nh-check interval?
I have a lot of nh-items, I do not want to enlarge the traffic for this binding.
My Dash Button setup:
I set a static IP on my Windows DHCP Server (could be done on a router, of course) and disabled Internet connectivity at my Fritz!Box (otherwise the amazon app notified me -> dash button not configured)

My FritzBox sets up automaticly fixed IP’s!

You have to increasing the nh-check interval!

BUT GOOD NEWS, you can deactivate amazon app notifications for the Dash Button.

In OpenHAB2 i can set the interval manually :slight_smile:

Hi everyone,
I’m new to OpenHab, and I’m trying to figure out if it will suit my needs. Support for Amazon Dash buttons is fairly integral to my plans.

I currently run scripts which listen for the Dash buttons to log onto the network and execute commands (turn Hue lights on/off), and I’m looking for something a little more user friendly and easier to make changes to. I’m hoping OpenHab can be that.

I have two questions:

  1. Is it easy to set up a dash button and assign it a function in OpenHab?
  2. Is it possible to implement something similar to this Homebridge plugin, which uses wifi frames instead of ARP? https://github.com/jourdant/homebridge-amazondash-ng

Thanks for any insight/help you can provide.


Francis

Looking at one-year-old original post from @rlkoshak I see, that Apple made a good progress since then - in iOS10 you just swipe lock screen up - and here you are with all your Homekit buttons. Or just say - “Siri, open the garage door”. So the number of steps was greatly reduced since then. And you still need only your iPhone.
Rich, did you try Apple/Siri/Homekit solution for your garage door, or it doesn’t work, or you still think, that Dash is better?

I don’t personally use Apple products so I have no idea. I do something similar (have for years) on my Android using Tasker. Even a Siri solution would not meet the WAF (she does use Apple products) so I’ve not pursued any Homekit integration. And I try to avoid any solution that is locked into any one ecosystem as much as possible (i.e. I won’t bother implementing a primary control that works on iPhone but doesn’t work on Android and vise versa or only works on Windows but won’t on Linux or OSX).

For awhile I had some Zwave Minimotes, one in each car, which worked great as garage openers. The Dash buttons never really worked well from the driveway even when I could get them to work and the latency between button press and door opening was too long even when it worked. In my opinion, Dash buttons are great for controlling things where the latency isn’t noticeable such as data logging, HVAC, etc. but not a good choice for controlling things where latency is noticeable like turning on lights or opening the garage doors.

Eventually I ended up just replacing the garage door opener with a newer, safer, and quieter one (one that has the sensors to stop its closing if there is something in the way) with remotes that actually work. My wife just uses the button that came with the opener and I still use my Android/Tasker setup which I know violates my rule from above but I think of this as a secondary control, not the primary control.

I developed an Amazon Dash button binding for openHAB 2: http://docs.openhab.org/addons/bindings/amazondashbutton/readme.html

2 Likes

Thankyou for your binding, I am a beginner on openHAB2 (2.0.0 online SNAPSHOT build560 ubuntu14.04. I have the dash button reporting to the openhab log, but cannot get the dash button to trigger a rule.

Please could your wiki code include sample Item and rule definitions to perform a simple task?

I am trying to get the dash button to run a php Script. If I press the dash button, or press a virtual button on the GUI it should run a script.
I have the button added as a Thing:
console shows:
amazondashbutton:dashbutton:ac-63-be-xx-xx-xx (Type=Thing, Status=ONLINE, Label=Dash Button 1, Bridge=null)
The log shows the following upon pressing the Dash Button
[marthome.event.ChannelTriggeredEvent] - amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press triggered

I have tried:

  1. create a Switch Item, and link it to the channel
    Switch RunCode1 "Run Code Dash Button" { channel = "amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press" }
    then create a rule:
    rule "RunCode 1 button pressed"
    when
    Item RunCode1 received command
    then
    executeCommandLine (“php /opt/openhab2/scripts/myscript.php”)
    end
    then a sitemap switch, just so I can press it on the GUI to trigger the same
    Switch item=RunCode1 label="Run Code" mappings=[ON="On"]

I think my problem is that the button triggers an event in a channel but I can’t work out how to interact with that via rules,
Thankyou for any advice for a beginner.