Skip to content

Instantly share code, notes, and snippets.

@rgstephens
Last active April 16, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgstephens/0a2ace7928c1aec97628f2cd1abfdea8 to your computer and use it in GitHub Desktop.
Save rgstephens/0a2ace7928c1aec97628f2cd1abfdea8 to your computer and use it in GitHub Desktop.
Amazon Dash Button Flow

This flow and the script included in this git repository supports capturing Amazon Dash button presses using the npm node-dash-button package.

dash.js

This node.js script uses the node-dash-button module to monitor for Dash button presses. When a button is pressed, it sends an MQTT message that can be captured in NodeRed via the MQTT Node.

You'll need to make two changes to the dash.js script. Change the IP address for your MQTT server, the MQTT topic being sent and change the MAC address associated with your Dash button.

dash.flow

This is a NodeRed flow that captures the button press with an MQTT node and then runs a Function Node that toggles a global variable.

You'll want to modify the MQTT node topic to match the topic that you set in dash.js and you'll want to change the name of the variable set.

[
{
"id": "7add9f95.36737",
"type": "mqtt-broker",
"z": "",
"broker": "15.1.4.50",
"port": "1883",
"clientid": "",
"usetls": false,
"verifyservercert": true,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"willTopic": "",
"willQos": "0",
"willRetain": null,
"willPayload": "",
"birthTopic": "",
"birthQos": "0",
"birthRetain": null,
"birthPayload": ""
},
{
"id": "d814ac59.51db5",
"type": "debug",
"z": "828b7952.cf43c8",
"name": "",
"active": true,
"console": "false",
"complete": "true",
"x": 585,
"y": 324,
"wires": []
},
{
"id": "31036645.e9fe8a",
"type": "mqtt in",
"z": "828b7952.cf43c8",
"name": "Peets Button",
"topic": "dashbutton/peets",
"broker": "7add9f95.36737",
"x": 124.5,
"y": 325,
"wires": [
[
"1a8e95fc.25de7a"
]
]
},
{
"id": "1a8e95fc.25de7a",
"type": "function",
"z": "828b7952.cf43c8",
"name": "Set Peets Variable",
"func": "if (!context.global.state) {\n context.global.state = { peets: false };\n if (context.global.state.peets === null) {\n context.global.state.peets = false;\n }\n}\nif (context.global.state && context.global.state.peets) {\n context.global.state.peets = !context.global.state.peets;\n} else {\n context.global.state.peets = true;\n}\n node.warn('setting state: ' + context.global.state.peets);\n var newMsg = { payload: context.global.state.peets }\n return newMsg;",
"outputs": 1,
"noerr": 0,
"x": 365.5,
"y": 383,
"wires": [
[
"d814ac59.51db5"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment