/pimatic-amazing-dash-button

Pimatic plugin for Amazon's dash-buttons

Primary LanguageCoffeeScriptGNU Affero General Public License v3.0AGPL-3.0

Amazing Dash-Button

pimatic-amazing-dash-button

Npm Version Build Status Dependency Status

A pimatic plugin for Amazon's dash-buttons. It is a pretty light-weight implementation which uses a ContactSensor or ButtonsDevice device abstraction for the dash-button. Auto-discovery of dash-buttons is supported.

The plugin sniffs for ARP probes which will be sent out by a dash-button when the button is pressed. The plugin is based on cap, a cross-platform libpcap binding for performing packet capturing with node.js. It can be used on *nix and Windows systems.

Contributions

If you like this plugin, please consider ★ starring the project on github. Contributions to the project are welcome. You can simply fork the project and create a pull request with your contribution to start with.

Stickers and Donations

Happy with pimatic and using it everyday? If you like to obtain one of these amazing dash-button stickers, please consider a donation to support the pimatic development and the operation of the website and user forum.

Installation

This plugin requires libpcap to capture ARP requests on the network. Moreover, it is required to have python v2.7 installed.

On Raspberry PI and comparable systems libpcap must be installed, i.e. sudo apt-get install libpcap-dev. On Windows, WinPcap must be installed. As the installation procedure uses node-gyp you will also need to have python v2.7 installed. Note, python v3 is not supported! See node-gyp installation notes for details.

Dash-Button Installation

Follow the instructions given in the Amazon Mobile App, to pair the dash-button with your WiFi network. However, don't select a product as requested in the last configuration step. Now, when the dash-button is pressed, the indicator LED of the dash-button should blink white for about three seconds. Following this, the LED will turn to solid red for a few seconds and might blink red (depending on the type of dash-button you have, apparently there are different makes). This indicates the device is not setup as there is no product setup, but this does not matter.

As an additional line of defense you may consider restricting internet access for the device as part of your router configuration.

Plugin Configuration

The "interfaceAddress" property may be omitted if your system only has a single network interface or the interface to choose is the first one on the list returned by the ifconfig command on the host. If the device discovery or the interaction with dash-button does not work as expected, provide the IP address associated with the network interface which shall be used to listen to ARP requests needs to be set.

{
      "plugin": "amazing-dash-button",
      "interfaceAddress": "192.168.1.15",
}

The plugin has the following configuration properties:

Property Default Type Description
interfaceAddress - String IP address associated with the network interface which shall be used to listen to ARP requests (optional)
ignoreMacAddresses - Array MAC addresses of candidate devices which shall be ignored. Typically, this is used to exclude other Amazon devices like Fire Tablet PCs.

Device Configuration

As of pimatic v0.9, dash-button devices can be automatically discovered. Simply open the "Devices" view of the pimatic web frontend and click on "Discover Devices". When the discovery has started, press the dash-button and the device should show up as a discovered device in pimatic after a few seconds.

You can also add the device manually by adding it to the "devices" section of the configuration or by creating the device using the device editor.

{
      "id": "AmazingDashButton1",
      "name": "AmazingDashButton1",
      "class": "AmazingDashButton",
      "macAddress": "ac:63:be:b3:be:78"
}

The device has the following configuration properties:

Property Default Type Description
macAddress - String MAC address of the device
invert false String If true, invert the contact state, i.e., contact is 'closed' if dash-button not pressed
holdTime 1500 Integer The number of milliseconds the contact shall enter the state indicating button pressed (closed if not inverted)

You can also use your dash-button device as DashButtonDevice. This device type will act like a ButtonsDevice with one button. The configuration is

 {
       "id": "DashButtonDevice1",
       "name": "DashButtonDevice1",
       "class": "DashButtonDevice",
       "macAddress": "ac:63:be:b3:be:78"
 }

The DashButtonDevice only supports the macAddress property.

When using the automatic discovery mode, just change the class to DashButtonDevice and copy the macAddress property.

Trigger Another Device

The AmazingDashButton is derived from ContactSensor and provides the following predicate: {device} is opened|closed. For example, if you wish to toggle a PowerSwitch device when the dash-button is pressed you can create a rule as follows:

when AmazingDashButton1 is closed then toggle {PowerSwitch Device}

For the DashButtonDevice the predicate is {device} is pressed, so this would lead to this rule:

when DashButtonDevice1 is pressed then toggle {PowerSwitch Device}

Trigger Action

It is also possible to trigger an AmazingDashButton device using the pimatic REST or WebSocket API as shown in the example below for a given device with id dash-1. Calling the device action will close the contact for the holdTime configured set as part of device configuration.

curl --user "username:password" /api/device/dash-1/trigger

For a DashButtonDevice this would be:

curl --user "username:password" /api/device/dash-1/buttonPressed?buttonId=dash-1

Trouble Shooting

  • "TypeError: Buffer.alloc is not a function" during installation

    Make sure, you have node version 4.5 or greater installed.

History

See Release History.

License

Copyright (c) 2016-2019, Marcus Wittig and contributors. All rights reserved.

AGPL-3.0