Herbs
Posts: 1
Joined: Fri Jul 06, 2012 12:59 pm

Burglar alarm / iPhone alerts from RPi

Fri Jul 06, 2012 1:09 pm

Hello!

Here’s how I get an alert on my iPhone or iPad when my front door is opened, all from the Raspberry Pi. This is useful when I’m away as a sort of remote burglar alarm (I can then phone my neighbours to check on the house), but you could use the alerting part of this project to send whatever you like.

Here is how to do it:

1) Build a basic switch input circuit and install GPIO libraries to read it from Python

I used the excellent instructions in The MagPi magazine, Issue 2, but removed the LED and 470 Ohm resistor. I won’t recreate the instructions here - follow the guide in the magazine to setup the software and create the circuit and you should be fine.

http://www.themagpi.com/

2) Rather than a normal switch, connect a reed switch to this circuit

Reed switches contain a very thin piece of metal. When a magnet is in close proximity the switch is either open or closed. When it is moved, it flips to the opposite state (the magnet literally pulls the piece of metal to make or break contact). Mount the switch on your door frame and the magnet on the actual door right next to it. The switch will now change state when the door is opened.

3) Setup a means to receive alerts on your iPhone/iPad

Download the Prowl application:

http://itunes.apple.com/gb/app/prowl-gr ... 76271?mt=8

Now register your account, login, and set up an API key. This will be used as the ID for the application to receive messages. We will send a Prowl message from the Raspberry Pi through an API in Python and your Prowl account/application will take care of getting the actual alerts onto your iThing.

4) Setup a means to send Prowl messages from your Raspberry Pi

Install Python setup tools if you have not done so already:

Code: Select all

sudo apt-get install python-setuptools
Download Pyrowl, a Python prowl interface:

https://github.com/babs/pyrowl/

Put the files into a suitable directory and change to it. Now install Pyrowl:

Code: Select all

sudo python setup.py install
5) Write the code

Check out the test.py program that comes with Pyrowl and then write some code to send an alert. This is done by referring to the API key you set up earlier. Below is a basic test that I wrote. Possibly not the best coding, but hey it does a job of illustrating how this looks. Note you will need to supply your own API key and check the GPIO pin number being used matches where you plugged your circuit in.

You may also want to change the code to not to send an alert if one has been recently sent (e.g. someone opening and closing the door repeatedly), or otherwise limit the alerts to not annoy you too much (Prowl itself does have a timed limit but it’s quite high). However you decide to code it up, I suggest first writing a version that prints out the alerts, and only once tested do you revert this to actually using the Pyrowl API to send them.

Code: Select all

#!/bin/usr/bin/python

# Imports for Pyrowl
from pyrowl import Pyrowl
from pprint import pprint
import os

# Imports for GPIO
import time
import RPi.GPIO as GPIO

# Setup pyrowl with API key
p = None
p = Pyrowl("ENTER YOUR API KEY HERE!")

# Setup GPIO pin as input
# Check that this is the same pin you have your switch input plugged into!
GPIO.setup(11, GPIO.IN)


# Set initial state
previousstate = GPIO.input(11)

# Main loop
while True:
# Check that this is the same pin you have your switch input plugged into!
mybutton = GPIO.input(11)
if mybutton != previousstate:
if mybutton == True:
print "Door opened"
res = p.push("My Raspberry Pi", 'House Warning', 'Door opened', batch_mode=False)
else:
print "Door closed"
res = p.push("My Raspberry Pi", 'House Warning', 'Door closed', batch_mode=False)

previousstate = mybutton
# Print result if you like                
#pprint(res)
time.sleep(.2)
So, now you should be able send alerts from your RPi to your iPhone/iPad, and maybe catch burglars. :) You could always combine this with a photo emailed from a webcam, an audible warning through some mini speakers, etc. Or use it to alert you to pretty much anything.

I’d be interested to know if anyone else tries this/a variation and of course, if you have success. I didn’t have a lot of time to write this up so if you see anything that needs editing please let me know.

Enjoy!

bodowd
Posts: 1
Joined: Tue Jul 31, 2012 11:15 pm

Re: Burglar alarm / iPhone alerts from RPi

Tue Jul 31, 2012 11:27 pm

Hi, This is a great idea. I already use Prowl to alert me of things that happen at home, it would be cool to enable a RPi to do the same.

I am having some trouble getting the example working - the lack of indents is one issue. However the error I am getting suggests I am missing some part of the install -
$ ./test_script
Traceback (most recent call last):
File "./test_script", line 4, in <module>
from pyrowl import Pyrowl
ImportError: No module names pyrowl
$
Any help gratefully appreciated.
Brendan.

jermg77
Posts: 6
Joined: Tue Aug 14, 2012 4:06 pm

Re: Burglar alarm / iPhone alerts from RPi

Tue Aug 14, 2012 4:22 pm

Hello!

I'm new to all of this... (and I mean ALL) So, I will be brief... I'm looking to replicate this project, with one difference... In place of using a switch on a door, my goal is to have the burglar alarm siren be my input device (at least the siren outputs on the alarm mainboard.) Here is where I start to get hazy as my knowledge of electronics is limited. I did some research on my home alarm panel and I appear to have 2 options for sensing an alarm trip.

1: Siren outputs. This is a 4 ohm speaker output. (I measured about 1vdc coming off of it while it was ringing

2: there is an unused terminal labeled "bell" this is 13.8vdc @ 1amp when there is an alarm trip.

I'm not sure which of these would offer the least complicated solution to interface with the Rpi GPIO. Any suggestions?

Thanks in advance!! Cant wait till my Rpi arrives next week!!

-jerm!

rpsychedelic
Posts: 4
Joined: Tue Aug 14, 2012 6:15 am

Re: Burglar alarm / iPhone alerts from RPi

Tue Aug 14, 2012 6:21 pm

Thanks for sharing. This looks great.

Now the question is, what WiFi module did you use?
Can we use XBee thinguies as well on the RPi?

Mantrid
Posts: 33
Joined: Thu Jun 21, 2012 8:44 am
Location: Middlesbrough/Armagh

Re: Burglar alarm / iPhone alerts from RPi

Fri Aug 17, 2012 9:00 am

I have motion ruinning on my pi to detect motion from a webcam and upload photos/videos to an external FTP server

I have an old nokia knocking about with a usb data cable and there are linux SMS projects about, I'm thinking (when i have the time) of detecting motion, sending images and videos offsite and sending my phone an SMS to let me know about it

After a corrupt filesystem when writing a few screenshots (camera and usb stick holding main filesystem both go through usb) I've had to reflash and await a new powered hub which apparently gets more success, but if it holds well I'll add the phone on too

Has anyone went down that route? Just thinking it might be easier to set up and more adaptable to move etc than hardwiring into door sensors etc? (Also my wife won't shout at me for futering with the door)

Also I'm a linux/electronics noob so i reckon this will result in less of a disaster/half-finished project beside my old neglected guitar..

southpaw
Posts: 52
Joined: Wed Nov 30, 2011 2:23 pm

Re: Burglar alarm / iPhone alerts from RPi

Fri Aug 17, 2012 3:22 pm

I have an Android app that senses motion via the phones camera then sends a text or email to me with photo , not pi related or usable for your Nokia but if you pick up an old Android it works really well, an best of all it's free, see Google play for
Motion detector pro

caderoux
Posts: 47
Joined: Tue Jun 12, 2012 8:04 pm
Location: New Orleans

Re: Burglar alarm / iPhone alerts from RPi

Sat Aug 18, 2012 1:58 am

On a related note, I have been using Pushover to send me things on Android devices:

https://jcs.org/notaweblog/2012/03/16/o ... _pushover/
http://pushover.net

Mantrid
Posts: 33
Joined: Thu Jun 21, 2012 8:44 am
Location: Middlesbrough/Armagh

Re: Burglar alarm / iPhone alerts from RPi

Sat Aug 18, 2012 9:02 am

I was just gonna use playsms. i could just email it out since my android phone has push notifications for email... but that's not as cool ;-)

jermg77
Posts: 6
Joined: Tue Aug 14, 2012 4:06 pm

Re: Burglar alarm / iPhone alerts from RPi

Sat Aug 18, 2012 5:30 pm

bodowd wrote:Hi, This is a great idea. I already use Prowl to alert me of things that happen at home, it would be cool to enable a RPi to do the same.

I am having some trouble getting the example working - the lack of indents is one issue. However the error I am getting suggests I am missing some part of the install -
$ ./test_script
Traceback (most recent call last):
File "./test_script", line 4, in <module>
from pyrowl import Pyrowl
ImportError: No module names pyrowl
$
Any help gratefully appreciated.
Brendan.
I too am having similar issues. Any help out there?

Nathank
Posts: 2
Joined: Sat Aug 18, 2012 8:01 pm

Re: Burglar alarm / iPhone alerts from RPi

Sat Aug 18, 2012 8:06 pm

Beginner here. Can you link me to the reed switches you used? I checked my local radio shack but couldn't find any. Do they have to be rated for 3.3v or would a 12v switch work?

Also, would it be possible to get the current states of the reed switches and output them to a web interface?

Lurch
Posts: 1
Joined: Fri Aug 10, 2012 11:22 am

Re: Burglar alarm / iPhone alerts from RPi

Sun Aug 19, 2012 12:30 pm

jermg77 wrote:1: Siren outputs. This is a 4 ohm speaker output. (I measured about 1vdc coming off of it while it was ringing
This won't be any good as a general output, it will be an AC output from a speaker driver IC.
jermg77 wrote:2: there is an unused terminal labeled "bell" this is 13.8vdc @ 1amp when there is an alarm trip.
There will often be 1 or 2 outputs, either 0V on alarm activation or 12V on alarm activation. Use either of these to trigger a 12V relay to give you a set of clean contacts for interfacing external systems.

benjaminlunsky
Posts: 2
Joined: Wed Aug 01, 2012 8:02 pm

Re: Burglar alarm / iPhone alerts from RPi

Sun Aug 19, 2012 2:53 pm

Also having problem with
"ImportError: No module names pyrowl"
Anyone found a solution to this?

pynma seems to be installed when pyrowl installation is run - seems to be used for Android Notifications. Don't fully understand what's wrong here and can't seem to find much on this on the web.....

benjaminlunsky
Posts: 2
Joined: Wed Aug 01, 2012 8:02 pm

Re: Burglar alarm / iPhone alerts from RPi

Sun Aug 19, 2012 3:36 pm

ok for all those interested I finally got this working.
Seems like pynma is a branch of pyrowl, so if you navigate to (I used chromium browser on my Pi):
https://github.com/babs/pyrowl/tree/master
click on 'setup.py', it'll load in a new screen. Choose the RAW option and save as setup.py
Go back, click on pyrowl directory, click on 'pyrowl.py', choose RAW option and save as pyrowl.py
I mimicked the directory structure (with pyrowl.py in a pyrowl directory) and ran
'sudo python setup.py install'
Then run your test app in the same folder as pyrowl.py and it works!
Good luck!

jermg77
Posts: 6
Joined: Tue Aug 14, 2012 4:06 pm

Re: Burglar alarm / iPhone alerts from RPi

Sat Sep 01, 2012 4:38 pm

I'm starting to feel like my limited understanding has brought be to a dead end. I've built this circuit:

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=14615

I'm replacing the reed switch with a 13.8vdc trigger from the alarm panel. Pyrowl is working fine with test messages, but using this test script in the OP, my result is a "Door Opened" message and pyrowl iPhone notification on an infinite loop until I kill the script. No matter what the state of the alarm 13.8v trigger. (on or off)

It's probably something fairly obvious to someone who has a hand on programming of any level... But making me beat my head against the wall.

Any suggestions?

-jerm!

phunky_xyz
Posts: 2
Joined: Fri Jan 01, 2016 1:22 pm

Re: Burglar alarm / iPhone alerts from RPi

Fri Jan 01, 2016 1:31 pm

Hey guys,
happy new year :-).

Some questions regarding github and pyrowl.
The current github for pyrowl for IOS is https://github.com/babs/pyrowl/tree/master right?
How can I install this via terminal on my raspberry? "git clone https://github.com/babs/pyrowl/tree/master" does not working?

By the way, I need only one input pin to send a notification to my Iphone, I think this the right example.

Any suggestions?

DirkS
Posts: 10421
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Burglar alarm / iPhone alerts from RPi

Fri Jan 01, 2016 2:52 pm

phunky_xyz wrote:The current github for pyrowl for IOS is https://github.com/babs/pyrowl/tree/master right?
How can I install this via terminal on my raspberry? "git clone https://github.com/babs/pyrowl/tree/master" does not working??
If you have the git page opened in a browser you can see the correct URL at the top of the page ('HTTPS'). Use that for git clone.
(It's https://github.com/babs/pyrowl.git BTW)

phunky_xyz
Posts: 2
Joined: Fri Jan 01, 2016 1:22 pm

Re: Burglar alarm / iPhone alerts from RPi

Fri Jan 01, 2016 3:11 pm

Thanks for the quick answer.
This works with git clone, BUT https://github.com/babs/pyrowl.git is for android phones, if I understand the description correct....

For IOS the link is: https://github.com/babs/pyrowl/tree/master and this link I can't use with git clone.

Return to “Automation, sensing and robotics”