Following this example you can understand how to convert your home's old wired alarm with a pre-recorded phone notification to a new IoT system.
The problem: I want to remove my home's landline phone. How can I continue to use my home's wired alarm and still get a notification when the alarm is triggered without the need to receive a phone call?
What you need?
- Some electrician skills, a multimeter, screwdrivers
- Internet connection
- Your smartphone
- Working Raspberry Pi
- An AWS account
- An IFTTT account
Step 1: The idea is to connect the control unit of your home alarm platform to a GPIO of your Raspberry Pi. In this way when your alarm will be triggered, the GPIO will collect a signal that can be used to notify your mobile phone.
Step 2: Now how to make your Pi notify your Android mobile? Through your IFTTT account, you can configure an applet to receive the HTTP request and send a push notification to the IFTTT app in your mobile.
Step 3: This already looks very nice, but last and not least, how to monitor that your Pi is always working correctly? Using the Amazon AWS free plan you can tell your Pi to send an alive signal that will checked from a cronned lambda expression. In case of failure a KO notification will be sent.
The first thing you need to do is open your home's alarm control unit and identify where to connect your Pi. You need to identify a pin which emits signal when your alarm detects an intrusion.
Make some tests, starting from the siren connector. Once you have identified a correct signal, connect it to the Pi and proceed with the next steps.
Below you can see my own connection as an example.
Phase 2 - Configure IFTTT Applet
Configure IFTTT to send notification to your Android/IOS mobile phone.
You have to install the IFTTT app on all the devices which you want to receive the notification. Once you have those installed, create an IFTTT account for each user.
After a successful login, you need to configure two new Applets, one for the alarm notification, and one for the software KO notification which will be sent if your Pi goes down.
To configure an applet, click on the new Applet button and choose Webhooks for the if section, and Notifications for then section. Follow the applet creation steps, and set the text of the notification you want to recive. Then pick up the generated webhook URL that you will need in Setup Pi phase.
Phase 3 - Setup AWS, DynamoDB and Lambda expression
To check the status of your new IoT alarm you need to configure two Amazon AWS services.
(Don't worry, for the purpouse of this project you don't have to pay anything. AWS Lambda and DynamoDB have free tiers under a certain range of usage).
STEP ONE: Enter in your AWS account and open DynamoDB section. You need to create a simple table with just one field. You can perform this operation using AWS console.
I've created a simple table with just two fields: one identifies the building, the other will contain the event timestamp. We'll understand later who set this data.
Example:
{
"building": "MyHome",
"lastPing": {
"ts": 1533381549565
}
}
STEP TWO: From your AWS console you also need to configure a Lambda expression. This function will check every 20 mins if your Pi has pushed into the DynamoDB database an updated timestamp.
If the value has not been updated since last check, we may assume that the Pi has lost power or connection, so we will push a notification to the configured mobile devices.
From the Lambda console click on new function, select Node.js, than click create function. You can copy the code from the provided lambda.js file or if you prefer, write your own version. After submitting your code, schedule your lambda to run on a schedule, i chose to run mine every 20mins.
Keep in mind that if you run the lambda too frequently you may need a premium plan on AWS
P.S. To make Lambda and Pi access DynamoDB you have to configure your account and roles. You can search on Amazon documentation how to do it. Enjoy!
This phase's main difficulty lays in how to detect the signal through GPIO and send it to the IFTTT back-end.
For this purpose i used a low level GPIO library, with a Node.js script.
The script is listening for events coming from pin 4, when an event is detected, it sends an HTTP request to all the addresses configured into the addresses.json
file.
To monitor your Pi, you can find instructions below at point 4. The script pushes the current timestamp into the DynamoDB table you created earlier.
How to make this work:
-
Move to the folder that contains main.js and package.json and execute
npm install
-
Setup the notification URL
- Open the
addresses.json
file - Create an object inside the array for each user you want to be notified
- Put in the url field the address of the IFTTT webhook you created, and in the name field the name of the person that will be notified (for logging purposes only)
- Save and exit
- Open the
-
Setup main script
- Copy the
main.js
file from this repository into your Pi home directory - Setup a cron expression to run the script at boot. This will help you in case of your Pi rebooting or losing power, since it will run the script automatically on reboot.
example:
@reboot sudo /home/user/.nvm/versions/node/v8.11.1/bin/node /home/user/js/main.js >> /home/user/log/alarm_js.log 2>&1
- Copy the
-
Setup keepalive script
- Copy the
lambda.js
script into your Pi home. - Open the file with a text editor
- Configure the AWS region you chose for your table, the table name and the IFTTT webhook URL.
- Save and exit
- Put also the
lambda.js
script under cron expression
- Copy the
The Pi setup is completed! Let's test it!
I used a Raspberry Pi 1 model B, but you can choose a newer one. The only thing that changes in this project is GPIO pin to use. About Pi's OS, i'm running on Raspbian that is a simple basic distro, but you may use the one you prefer.
Useful links:
To make the system more secure, I connected the Pi's power plug to the alarm's own 12V battery using a mobile phone car adapter. This is the easiest way to transform 12V into the 5V needed to power the Pi. In this way if your home loses power, your alarm will still be alive and rocking!
Keep attention that the USB charger you chose is powerful enough for your Pi. The rPI 1 needs at least 2A to work consistently (3A in case of rPI 3 or newer). If you use a tablet charger (2A or more) you should have no problems.
- FMeneguzzo to introduce me in AWS world.
IotHomeAlarm Copyright (C) 2018 Michele Sartor
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.