9

(Elliott) #1

Upgrade your humble letterbox with push notifications


TUTORIAL


script adds a brand new row to the bottom each time
the letterbox is opened.

IF THIS, THEN THAT...
To monitor the Google spreadsheet, and send push
notifications to your phone, you will use a free service
called If This Then That (IFTTT), at ifttt.com.
Sign up for IFTTT if you don’t already have an
account. Click on New Applet, then click on the big
‘+this’ to add your ‘this...’ scenario/trigger, which will
be that new row getting added to your spreadsheet.
Under services, search for Google Sheets and then
select ‘New row added to spreadsheet’ as the trigger.
After authorising access to your Google Drive, paste
the full URL of your Google Sheet into the box and
click Create Trigger. Now that the trigger is set up,
you need to add the action. Click on the ‘+that’ and
search for the ‘Notifications’ action service. Under

‘Choose action’ select ‘Send a notification from the
IFTTT app’.
The action fields allow you to customise the
message that’s sent to your phone with each push
notification. The message needs to say something
like this, using the values which have been added to
the spreadsheet:
‘The post arrived on {{ColumnA}} at {{ColumnB}}!’
Click ‘Create action’, then review and ‘Finish’.
In order to receive the push notification, you must
have the IFTTT app installed on your phone, so open
up the Google Play Store, install the IFTTT app, and
log in with same account that you used to create
the applet.
You can test it out by manually adding a new row
to the spreadsheet; wait around a minute and a push
notification should pop up on your phone. Now that’s
working, it’s time to make that happen automatically
each time the letterbox opens.

FOLLOWING THE SCRIPT
The project uses a Python script which detects the
letterbox activations and then uses the Google Sheets
API to add a row to the spreadsheet. It needs to be
authorised to edit the spreadsheet in your Google
account, and to do this you first need to create an app
on the Google Cloud Platform at hsmag.cc/QypiUm.
Create a new app and give it a name. Next, you
need to enable both the Sheets and Drive APIs for your
app: from your app’s dashboard, click APIs & Services
in the left menu bar, and then select Library. Search
first for Drive and then enable it – and then do the
same thing for Sheets.

IF THIS THEN THAT


If This, Then That (IFTTT) is a free online platform
which allows you to join together your various apps
and IoT devices. It can talk to lots of online services
and smart devices as both trigger and action, and,
as the name suggests, it allows you to specify that ‘if
this happens, then do that’. Have a play and let your
imagination run wild at ifttt.com.

Right
Once you’ve created
your Google app,
enable both the Drive
and Sheets APIs,
so that the app can
access your Drive and
work on Sheets
Below
The two wires to and
from the magnetic
sensor switch are
connected between a
numbered GPIO port
and ground. As it’s not
a polarised switch, the
order doesn’t matter

The action fields allow you to customise
the message that’s sent to your phone with
each push notification



If you have any other
‘smart’ devices in
your house, you
could easily expand
this project to talk
to those too. For
example, you might
want to turn on a
smart WiFi light
bulb for a couple
of minutes a few
seconds after the
post arrives, to
make your house
look occupied while
you’re away.

QUICK TIP

Free download pdf