Introduction: Amazon Dash Button Silent Doorbell

Constantly looking out the window so that you can intercept visitors before they ring the doorbell? Tired of the dogs and baby going crazy anytime it rings? Don't want to spend a fortune on a "smart" solution?

Making a silent doorbell is as easy as hacking a $5 Amazon Dash Button! The only other thing you need is a computer that's always at home - like, say, that Raspberry Pi you've got sitting around. Get text notifications anytime someone pushes your new doorbell and keep the whole house happy. (It's even cooler to get notifications if you have a smartwatch!)

For this project you'll need:

Step 1: Setting Up Your Dash Button

Getting your Dash button ready for hacking is pretty straightforward - you just need to go through the entire Amazon setup process minus selecting a product.

This setup requires the Amazon app, which is available for iOS and Android. Once logged in to Amazon inside of the app, go to Your Account -> Dash Buttons & Devices -> Set up a new device. Select "Dash Button" and follow the instructions until you are prompted to select a product.

Close the app. Don't cancel setup; don't hit the x - just close the app. If you accidentally selected a product or are repurposing an old Dash button, just remove the device through the Amazon app and follow these steps again.

If you're looking to change how your button looks, peeling off the label sticker is easy.

Step 2: Install Node JS on Your Device

To find (and subsequently use) your Dash button's hardware address, we need to use Node JS. This can be installed on any computer - Mac, Linux (Raspberry Pi), or Windows.

Our final project hinges on having a computer that's connected to the same network as our button that is running an uninterrupted Node script, so keep that in mind when choosing your device. An at-home desktop or Raspberry Pi would be perfect.

I choose to use a Pi 3, but a Pi Zero with a WiFi dongle would work too!

To install Node JS on your computer, follow the appropriate instructions:

Alex Horton wrote a fantastic module just for what we're trying to do called node-dash-button. We need to install it, along with the node package manager (npm) and libpcap. Enter these commands in the command line:

sudo apt-get install npm
sudo apt-get install libpcap-dev
npm install node-dash-button

Step 3: Find the Button's Address

We've found a simple way to find your dash button address.

First, hold down the button on your dash button for about 5 seconds until the LED begins to slowly strobe blue. On your phone, open your wifi settings and find the 'Amazon Configure Me' wifi. Once connected to this, open your web browser and go to 'http://192.168.0.1'.

The address that we're looking for is MAC address and will look like "ab:64:be:8b:ce:82".

Step 4: Testing Your Button

You can confirm that you found the correct address by writing a simple script to print a message every time the button is pressed.

Create a new script inside of the node-dash-button directory.

sudo nano button_test.js 

And copy-paste the following into the file:

var dash_button = require('node-dash-button'),
    dash = dash_button('xx:xx:xx:xx:xx:xx'), //REPLACE WITH YOUR ADDRESS
    exec = require('child_process').exec;

dash.on('detected', function() {
    console.log('Button pushed!');
}); 

Replace the x's on the second line with your newly found button address. Save the file with Ctl-x, y.

Start the script and press your button.

sudo node button_test.js 

You should see "Button pushed!" print out. Now that we can detect button presses, we can trigger actions based on them!

Step 5: Setup Initial State Account

Now that we can trigger a command line message when we press the Dash button, we can trigger all sorts of other things! In this case I'm going to trigger a text message - we don't want whoever's at the door to be waiting until we check our email.

There are a couple of ways to trigger a text notification - services like Twilio or PushBullet. One of the easiest ways I found was through Initial State. It required minimal extra coding and provided me with a dashboard view of when my button had been pressed.

Go to https://iot.app.initialstate.com and create a new account.

You need to install the Initial State SDK for NodeJS onto your desktop/laptop/Raspberry Pi. At a command prompt (don’t forget to SSH into your Pi first), run the following command:

cd /home/pi/node_modules/node-dash-button
sudo npm install initial-state

To test the streamer, create a test file:

nano stream_test.js

And copy-paste the following (also found here):

var IS = require('initial-state');
var bucket = IS.bucket('NodeJS_SDK_Example', 'YOUR_ACCESS_KEY_GOES_HERE');

// Push event to initial state
bucket.push('Demo State', 'active');

setTimeout(function () {

    // Push another event
    bucket.push('Demo State', 'inactive');

}, 1000);

Save the script with Ctl-x, y.

Before we can run this script, however, we need to add a unique Access Key to the second line.

On line 2, you will see a line that starts with var bucket = IS.bucket(.... This lines creates a new data bucket named “NodeJS_SDK_Example” and is associated with your account. This association happens because of the second parameter on that same line. Your Initial State account access key is a long series of letters and numbers. If you go to your Initial State account in your web browser, click on your username in the top right, then go to “my settings”, you will find your access key there.

Run the test script to make sure we can create a data stream to your Initial State account. Run the following:

node stream_test.js

Go back to your Initial State account in your web browser. A new data bucket called “NodeJS_SDK_Example” should have shown up on the left in your log shelf (you may have to refresh the page). Click on this bucket to view the test data.

Now you're ready to send your button presses to Initial State!

Step 6: Final Code

We've already installed the Initial State Node SDK, so all we need to do is add it to our code!

Here is a modified version of the button_test.js script we used earlier:

var dash_button = require('node-dash-button'),
    dash = dash_button('xx:xx:xx:xx:xx:xx'), //REPLACE WITH YOUR ADDRESS
    exec = require('child_process').exec;

var IS = require('initial-state');
var bucket = IS.bucket('Doorbell', 'YOUR_ACCESS_KEY');

dash.on('detected', function() {
    console.log('Button pushed!');
    bucket.push('Front Door','Someone is Here!');
}); 

Copy-paste this script into a new file (still inside of the node-dash-button directory):

sudo nano doorbell.js 

You'll notice that on lines 5 and 6 we include the Initial State module and provide our bucket parameters. You need to put your unique Access Key from before on line 6.

Line 10 is where we actually send data to Initial State. In this case, I've named my bucket "Doorbell" and am streaming "Someone is Here!" at my front door. If you have multiple Dash buttons, you can send them all to the bucket "Doorbell" but name them according to their location (i.e. "Garage Door", "Bedroom", etc.).

Save the script with Ctl-x, y.

To test your script, run:

sudo node doorbell.js. 

When you press your button, you should be able to go to your Initial State page and see a new bucket named "Doorbell" in the sidebar. Now let's add a Trigger!

Step 7: Setting a SMS Trigger

"Triggers" are Initial State's version of notifications and they're super easy to add. Just click "Settings" underneath the Doorbell bucket, and then click on the "Triggers" tab.

You can select the signal you want to trigger off of from the dropdown list. Our bucket only has one - "Front Door" - so select that. Then pick the "match" option and add the message you stream when your button is pressed - in this case "Someone is Here!"

Finally, add your phone number to receive SMS messages. You will need to enter a verification code sent to your phone the first time you use that number.

Make sure that you press the "+" sign next to your phone number or the trigger won't be created.

Click "Done" at the bottom of the Triggers tab to save your trigger.

Now you're ready to receive text alerts! Press your button (while the doorbell.js script is running). You should get a text in 8 seconds or less!

Your silent doorbell is ready to go! If you want to make sure that your script restarts on a power outage, keep reading. I'll also go over adding emojis to your bucket and signal names.

Step 8: Personalizing Your Dashboard

If you want to fancy up your Initial State dashboard, adding emojis or changing names entirely is super simple.

To change the name of a tile, simply right-click on the tile and select "edit tile". Inside of the Title box that comes up you can put the shortcut for any emoji. Clicking "x" at the top of the configure window will save your changes.

You can also do this to the name of your bucket by clicking on "Settings" underneath the bucket name and then editing the Name field.

You can add a background image to your dashboard to give your data more personality and context.

Step 9: Starting the Script From Boot

The script that you have running on your home computer or Pi is the key to our silent doorbell. If something happens like a power outage, we want to make sure that our script gets back up and running.

On a Mac We're going to use a service called crontab and the nano text editor:

env EDITOR=nano crontab -e 

Inside of the file, add:

@reboot nohup sudo node /Users/UserName/node_modules/node-dash-button/doorbell.js &

Be sure to replace "UserName" with your own. If you named your script something else or put it in a different directory, replace /Users/UserName/node_modules/node-dash-button/doorbell.js with the correct path. The path in my example is the main user directory followed by the node_modules/node-dash-button directory. You can easily copy a file's pathname by following these instructions.

Save the file with Ctl-x, y. You can test if it works by rebooting your computer.

On a Windows Follow the instructions here to start your node script on reboot. Be sure to specify the script's entire path.

On a Raspberry Pi/Linux Machine Running a script from boot on the Pi is pretty straightforward. We're going to use a service called crontab:

sudo crontab -e 

Pick your favorite text editor (I like nano) and at the bottom of the file (under all of the comments), add:

@reboot nohup sudo node /home/pi/node_modules/node-dash-button/doorbell.js &

If you named your script something else or put it in a different directory, replace /home/pi/node_modules/node-dash-button/doorbell.js with the correct path. The path in my example is the main Pi directory followed by the node_modules/node-dash-button directory.

Save the file! You need to reboot for it to take effect, but if you also want to reboot if the internet connection goes down, we are going to add another task to our crontab in this next step.

To handle network drops, I decided to just implement a way for the Pi to detect a network connection and reboot if it's not there.

First we need to create a script to check the WiFi and then trigger shutdown:

cd
sudo nano /usr/local/bin/checkwifi.sh 

Place the following inside of the file, being sure to replace the IP address with the IP address of your router:

ping -c4 IP_ADDRESS > /dev/null

if [ $? != 0 ]
then sudo /sbin/shutdown -r now fi

The ping checks for a connection. If it returns with a non-zero exit code, the script sends the shutdown command. Save and exit out of the script. Now make sure its permissions are in order:

sudo chmod 775 /usr/local/bin/checkwifi.sh 

Just like our doorbell.js script, we are going to add this script to crontab:

sudo crontab -e 

Place

*/5 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1

underneath the line we added earlier. This will run our checkwifi script every 5 minutes. Now exit crontab and reboot the Pi:

sudo reboot 

Everything should be setup and working! You can also setup a way to monitor running processes on a Pi by following this tutorial.

Step 10: Conclusion

You now have a silent doorbell to keep those Amazon delivery guys from waking you up! Let me know if you have any questions or come up with any unique modifications.