Pushbullet is an awesomely simple app. It can show android notifications on your computer, move pictures, files, and links between devices, open tabs on your computer from your phone, and integrate with IFTTT. Most importantly, it gives you an easy way to send notifications from your Pi with some dead simple scripting.
As you can imagine, this opens up a whole world of applications for your home automation system. This week, I thought I’d do a quick and dirty tutorial on how to get your Raspberry Pi to send you event notifications. Currently I use this method to let me now if my garage door is open.
Install and sign up for the Pushbullet app. This is a free application available on both Android and iOS. In fact, install it on all the phones and tablets that you would like to receive your notifications. Easy enough, now on to step two.
To send the notifications from your Raspberry Pi, we’ll use a simple bash script. Open a new file and name it pushbullet.sh. Paste the following text into the file:
#!/bin/bash API="YOURKEY" MSG="$1" curl -u $API: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="$MSG"
Get your access token from the PushBullet website. It is listed under your account settings. Replace YOURKEY with your key.
Save and close your file. Now copy that file to /usr/bin and change permissions on it to allow execution.
raspberrypi# cp pushbullet.sh /usr/bin raspberrypi# chmod 755 /usr/bin/pushbullet.sh
In order to send a notification to your phone, you type:
raspberripi# pushbullet.sh "This is my Notification. I can send myself anything here."
Let’s say you want an alert sent to your phone when somebody opens your garage door (See the garage door article) you can add this to your garage door application:
from flask import Flask from flask import render_template from flask import request import wiringpi import time import time, os @app.route('/openDoor') def this_is(): os.system('/usr/local/bin/gpio export 25 out') io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS) io.pinMode(25,io.OUTPUT) # Setup pin 22 (GPIO25)pre try: io.digitalWrite(25,io.HIGH) # engage the relay except: print "An error has occurred while engaging the relay" time.sleep(2) try: io.digitalWrite(25,io.LOW) # disengage the relay #****** Here is the line we add ******* os.system('/usr/bin/pushbullet.sh "Someone has opened or closed your garage door."') return "Success"
There you go! I’m sure you can think of a million ways to make this useful, especially as a home automation notification system. PushBullet’s usefulness does not end there though, I encourage you to read more about it in this LifeHacker article.