Skip to main content

스포츠천국스포츠천국.net은 안전하고 다양한 정보, 게임, 매력적인 프로모션을 제공하는 신뢰할 수 있는 플랫폼입니다.

Home Security Alarm Notification

I had security system wired to RJ-11 modem port on switch that would call a specific number if alarm was triggered. I wanted to get rid of IPS provided switch and instead plug SFP and fiber optics directly into my router. But then I couldn’t be notified of alarm because my router doesn’t have RJ-11 port for isdn and alarm system doesn’t support VOIP. So I decided to make notification system using Raspberry Pi.

First, I had to figure out how to tell raspberry whether alarm is on or off. That was quite easy. I measured the voltage on siren connectors that was 0V in the normal state, and about 12V when alarm was on. Perfect. Then I connected relay on the same connector. Now when alarm is on, both sirens and relay receive 12V.

Relay connected to siren output
Relay connected to siren output

I made a simple circuit, similar to one used for push button for Raspberry Pi, but used relay instead of a button. Now when alarm switches on, relay does to and raspberry can read that through gpio. All we need now is software.

Raspberry pi 2
Raspberry pi 2
Circuit diagram
Circuit diagram

I already had installed wiringPi for accessing gpio pins:

git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
cd wiringPi
./build

I wrote a simple python script that checks gpio state every second. If there is a change in gpio read value, it checks its state again because I experienced false reads about twice a week due to unknown reasons. Then it runs sh script, which is used for pushing notification.

import time
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

int = 0
lastState = 1
while True:
    if lastState == 1 and GPIO.input(4) == 0:
        #alarm was off and now it's on - send sms / push notification
        time.sleep(1.2)
        if GPIO.input(4) == 0:
            print 'Sending notification'
            os.system('sh /home/user/alarm/push.sh')


    if lastState == 0 and GPIO.input(4) == 0:
        #alarm is on
        print 'Alarm is still on'

    if lastState == 1 and GPIO.input(4) == 1:
        #alarm is off

    if lastState == 0 and GPIO.input(4) == 1:
        #alarm was on and now it's off
        print 'Alarm is now off'
        lastState = 1
    
    lastState = GPIO.input(4)
    time.sleep(1)

I used pushbullet for pushing notification to my phone. They provide API for pushing notification via curl. I could also use SMS service provider to send SMS to my phone instead of pushbullet through API, but since I have data plan for my phone, I don’t need it.
Here is the shell script

#!/bin/bash

API="pushbullet api id"
MSG="Alarm is turned on!"

curl -u $API: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alarm" -d body="$MSG"

I run some tests to see if everything is working like it should, then I added cronjob for executing python script at reboot and set notifications for other family members.

pushbullet
pushbullet

2 thoughts to “Home Security Alarm Notification”

Leave a Reply

Your email address will not be published. Required fields are marked *