lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Home Alarm System Retrofit - "Part Deux"

Mon Dec 31, 2012 10:05 pm

Hello Forum,

The first part of my project was documented here: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=27788

Progress! I briefly ran out of whiskey this holiday season, and I've written a few more lines of code to implement a very basic alarm system. It's got rough edges, is missing features and functionality, but its working now.

Just to recap, I've disconnected the commercial alarm system computer board that came installed in my house when I moved in. I lifted the sensors and connected them to an RPi. I've installed Postgres to log sensor events and written a simple "event logger" (in Python using RPi.GPIO) to poll the inputs and log to the database. My current "event_logger.py" code is listed below:

Code: Select all

#!/usr/bin/env python

import psycopg2
from time import sleep
import RPi.GPIO as GPIO

db="lcard"
db_user="lcard"
db_host="localhost"
db_password='1234567890'

polling_interval = 1
tss_table = "two_state_sensors"
tss_event = "two_state_sensor_events"

class Sensor:
    pass

class Event:
    pass

def table_exists(conn, cur, table):

    try :
        cur.execute("select * from information_schema.tables where table_name=%s", (table,))
    except Exception, e:
        print "I am have failed to check for the existence of table %s." % table
        print str(e)
        exit()

    return bool(cur.rowcount)

def create_sensor_table(conn, cur, tss_table):

    sensorTableCreationCmd = """
    CREATE TABLE %s (
        name text,
        pin_index integer,
        normal_state integer,
        normal_text text,
        abnormal_text text,
        armed boolean default FALSE
    );
    """ % tss_table

    sensorTablePopulateCmd = """
    INSERT INTO %s (name, pin_index, normal_state, normal_text, abnormal_text) VALUES
    """ % tss_table

    try :
        cur.execute(sensorTableCreationCmd)
    except Exception, e:
        print "I am unable to create sensor table.", str(e)
        exit()

    for sensor_record in [ ('Front Door',       7, 0, 'closed',    'open'),
                           ('Garage Door',     11, 0, 'closed',    'open'),
                           ('Smoke Detector',  12, 1, 'quiescent', 'in alarm'),
                           ('Patio Door',      13, 0, 'closed',    'open'),
                           ('Motion Detector', 15, 0, 'quiescent', 'detecting motion') ]:
        cur.execute(sensorTablePopulateCmd + " (%s, %s, %s, %s, %s)", sensor_record)

    conn.commit()

def create_event_table(conn, cur, tss_events):

    eventTableCreationCmd = """
    CREATE TABLE %s (
        description text,
        pin_index integer,
        pin_state integer,
        time_of_occurence timestamp
    );
    """ % tss_events

    cur = conn.cursor()
    try :
        cur.execute(eventTableCreationCmd)
        conn.commit()
    except Exception, e:
        print "I am unable to create event table.", str(e)
        exit()

    conn.commit()

def init_sensors(cur, sensor_table):

    try:
        cur.execute("select * from %s;" % sensor_table )
    except Exception, e:
        print "Unable to read sensor table", str(e)
        exit()

    rows = cur.fetchall()

    sensors = []

    for r in rows:
        s = Sensor()
        (s.name, s.pin_index, s.normal_state, s.normal_text, s.abnormal_text, s.armed) = r
        s.state = s.normal_state
        s.previous_state = s.normal_state

        sensors.append(s)

    return sensors

def init_GPIO(sensors):

    GPIO.setmode(GPIO.BOARD)

    for s in sensors:
        GPIO.setup(s.pin_index, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def log_2state_events(conn, cur, event_table, sensors):

    insert_statement = "INSERT INTO %s " % event_table
    insert_statement += "(description, pin_index, pin_state, time_of_occurence) VALUES (%s, %s, %s, 'now');"

    for s in sensors:
        if GPIO.input(s.pin_index):
            s.state = 1
        else:
            s.state = 0

        if (s.state != s.previous_state):

            e = Event()

            if (s.state == s.normal_state):
                e.description = "%s is %s." % (s.name, s.normal_text)
            else:
                e.description = "%s is %s." % (s.name, s.abnormal_text)

            try:
                cur.execute(insert_statement, (e.description, s.pin_index, s.state ))
            except Exception, e:
                print "Unable to insert into sensor table", str(e)
                exit()

            s.previous_state = s.state

    conn.commit()

if __name__ == "__main__":

    try:
      conn = psycopg2.connect(database=db, user=db_user, host=db_host, password=db_password)
    except Exception, e:
      print "I am unable to connect to the database", str(e)
      exit()

    cur = conn.cursor()

    if (not table_exists(conn, cur, tss_table)):
        create_sensor_table(conn, cur, tss_table)
    if (not table_exists(conn, cur, tss_event)):
        create_event_table(conn, cur, tss_event)
    sensors = init_sensors(cur, tss_table)
    init_GPIO(sensors)

    while (True):
        log_2state_events(conn, cur, tss_event, sensors)
        sleep(polling_interval)

    cur.close()
    conn.close()
I've also written an "alarm agent" to periodically check the database for "alarmable events". When an event is detected, on an "armed" sensor, the script sends me a text message (through an email to SMS gateway). This script has another thread which periodically checks for email in its own dedicated Gmail account. So far, it checks for emails with the text 'arm' and 'disarm' to turn the system on or off. My current "alarm_agent.py" source is below:

Code: Select all

#!/usr/bin/env python

import poplib, smtplib, email, threading
from datetime import datetime

email_user = 'AlarmSystemGmailAccount'
email_pass = 'ReallyStrongPassword'
email_alarm_target = '12345678910@SomeDomain.net'

import psycopg2
from time import sleep

db="lcard"
db_user="lcard"
db_host="localhost"
db_password='1234567890'

tss_table = "two_state_sensors"
tss_event = "two_state_sensor_events"

class AlarmNotifier(threading.Thread):

    def init(self, pi):
        self.tss_table = tss_table
        self.event_table = tss_event
    
        try:
            self.conn = psycopg2.connect(database=db, user=db_user, host=db_host, password=db_password)
        except Exception, e:
            print "I am unable to connect to the database", str(e)
            exit()
            
        self.cur = self.conn.cursor()
        
        self.last_event_time = datetime.now()
        print "%s" % self.last_event_time
                
        self.polling_interval = pi
        return
        
    def check_events(self):

        self.next_last_event_time = datetime.now()
        
        query = """SELECT description, time_of_occurence from two_state_sensors, two_state_sensor_events
           WHERE two_state_sensors.pin_index = two_state_sensor_events.pin_index
           AND two_state_sensors.armed IS TRUE
           AND two_state_sensor_events.pin_state != two_state_sensors.normal_state
           AND time_of_occurence > %s        
        """

        self.cur.execute(query, (self.last_event_time,))
        
        for e in self.cur.fetchall():
            print e
            send_email(email_user, email_pass, email_user + '@gmail.com', email_alarm_target, '', e[0])

        self.last_event_time = self.next_last_event_time
         
        return
            
    def run(self):
        while True:
            print "checking events..."
            self.check_events()
            sleep(self.polling_interval)
        return
        
class ConfigurationMonitor(threading.Thread):

    def init(self, pi):
        self.table = tss_table
        try:
            self.conn = psycopg2.connect(database=db, user=db_user, host=db_host, password=db_password)
        except Exception, e:
            print "I am unable to connect to the database", str(e)
            exit()
            
        self.cur = self.conn.cursor()        
        self.polling_interval = pi
        return

    def run(self):
        while True:
            print "checking email..."
            self.check_email()
            sleep(self.polling_interval)
        return
 
    def arm_all_sensors(self):

        update_statement = "UPDATE " + self.table + " SET armed = TRUE;"

        try:
            self.cur.execute(update_statement)
        except Exception, e:
            print "Unable to update sensor table", str(e)
            exit()

        self.conn.commit()
        
        send_email(email_user, email_pass, email_user + '@gmail.com', email_alarm_target, '',  'All sensors armed.')

        return
        
    def disarm_all_sensors(self):

        update_statement = "UPDATE " + self.table + " SET armed = FALSE;"

        try:
            self.cur.execute(update_statement)
        except Exception, e:
            print "Unable to update sensor table", str(e)
            exit()

        self.conn.commit()

        send_email(email_user, email_pass, email_user + '@gmail.com', email_alarm_target, '',  'All sensors disarmed.')

        return

        
    def check_email(self):
        M = poplib.POP3_SSL('pop.googlemail.com', '995')
        M.user(email_user)
        M.pass_(email_pass)
        numMessages = len(M.list()[1])

        for i in range(numMessages):

            mail = email.message_from_string('\n'.join(M.retr(i+1)[1]))
            #print "From: " + mail["From"]
            #print "Subject: " + mail["Subject"]
            #print "Message: " + str(mail.get_payload())
            
            if ( email_alarm_target == mail["From"] ):
                command = mail.get_payload()
                if ( command.lower() == 'arm' ):
                    self.arm_all_sensors()
                    print "All sensors armed."
                elif ( command.lower() == 'disarm' ):
                    self.disarm_all_sensors()
                    print "All sensors disarmed."
                else:
                    print "Unknown command parsed from email."
            
            M.dele(i+1)
            
        M.quit()
    
def send_email(usr, psw, fromaddr, toaddr, subject, msg):
    
    # Initialize SMTP server
    server=smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(usr,psw)
    
    # Send email
    senddate=datetime.strftime(datetime.now(), '%Y-%m-%d')
    m="Date: %s\r\nFrom: %s\r\nTo: %s\r\nSubject: %s\r\nX-Mailer: My-Mail\r\n\r\n" % (senddate, fromaddr, toaddr, subject)
        
    server.sendmail(fromaddr, toaddr, m+msg)
    server.quit()


if __name__ == '__main__':

    an = AlarmNotifier()
    an.init(10)
    an.start()
    
    cm = ConfigurationMonitor()
    cm.init(300)
    cm.start()
It needs more features, like being able to arm/disarm sensors individually. I'd like to set up some additional behaviors like perhaps auto-arming at night, or after a period of quiescence on the motion sensor. I also think maybe my smoke detector should be always armed. Lots to do...

All the sensor configuration is in a dedicated database table, so it should be super easy to expand with more sensors, or adapt to someone else's sensor configuration. If anyone else wanted to try setting up something similar and running it I'd be happy to guide you through it.

No more alarm monitoring fees. Hooray!

-lmcc

Tibedabeeto
Posts: 4
Joined: Fri Dec 28, 2012 7:57 pm
Location: Orlando, FL

Re: Home Alarm System Retrofit - "Part Deux"

Mon Dec 31, 2012 10:20 pm

This is tight! So where do I start? How to connect pi to existing system? I am new to this and pi so any detail that you can provide would be great. Thanks man

hostingnuggets
Posts: 34
Joined: Fri Dec 28, 2012 5:52 pm

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 01, 2013 2:11 pm

Hi,

What door sensor (e.g. magnetic reed switches or others) are you using? I would be interested to know the exact brand and model as I am also looking into building such a device.

Maybe a post from you with all the hardware components you are using would also interest others on the forum.

Cheers,
H.N.

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 01, 2013 8:44 pm

Tibedabeeto wrote:This is tight! So where do I start? How to connect pi to existing system? I am new to this and pi so any detail that you can provide would be great. Thanks man
I didn't actually do anything with the existing alarm control board. I just stole all its sensors and connected them to the RPi. (I've effectively discarded the original alarm control computer board.) All the sensors were labeled in my system, which made it easy.

If you're in a similar situation, just take the wire from one door sensor and disconnect it from your current alarm system. It should have two wires. Assuming your RPi is installed and networked close to where the old system is installed, connect one door sensor wire to ground, and another to an RPi digital IO pin.

If that doesn't make sense, I can back up the bus a little further.

-lmcc

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 01, 2013 9:27 pm

hostingnuggets wrote:Hi,

What door sensor (e.g. magnetic reed switches or others) are you using? I would be interested to know the exact brand and model as I am also looking into building such a device.

Maybe a post from you with all the hardware components you are using would also interest others on the forum.

Cheers,
H.N.
I don't actually know what sensors I have installed. (They came with the house.) They are magnetic reed switches. I don't think it really matters. Here's the neat thing - the other two sensor types in my system behave the same way. Both my motion detector, and smoke alarm behave as contacts opening or closing on events too. The only difference is they are powered by a 12V line whereas the door sensors are passive. (Also the logic on my smoke detector is reversed.)

Someone from the peanut gallery is sure to chime in shortly with a comment about input protection. I am not using any (yet). I've connected my sensors directly to the digital IO pins (and ground). I'm using the RPi's internal pullups to bias the lines. If I were being a good boy I'd put a resistor in-line with the sensors, and zener diode and capacitor across the sensor leads. I should probably use an external pull-up to bias the lines. Maybe I'll put something together when I wire in the horn, since that will likely require external circuitry (a transistor) to switch and power it.

I've gotten a little off topic, but my short answer is it probably doesn't matter much. Pick some reed sensors which are attractive to you due to price, mounting options, color or whatever, and they will probably work. If you like, post a link to switches you're considering and I'll be happy to share my opinion of them. My only caveat is I am not an alarm technician by trade. (I have formal training in electronics and work as a software plumber for local power utility.)

Also, If some or all of this is confusing or makes no sense, let me know. Like I said in a previous post I can back the bus up a little further if it means picking up another passenger.

Happy new year.

-lmcc

hostingnuggets
Posts: 34
Joined: Fri Dec 28, 2012 5:52 pm

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 01, 2013 11:05 pm

Thanks for the details, I really like your project!

Like suggested I had a look at some reed sensors on farnell.com and found the following one:

http://uk.farnell.com/assemtech/mmpsa-2 ... 20Products

which I could mount on the wall where the door opens and its assoicated magnet:

http://uk.farnell.com/assemtech/mmpsm/m ... dp/1173768

which I would mount on the door itself.

What do you think about this sensor? Would it be a good match for the Pi?

Happy new year to you too :)
H.N.

Tibedabeeto
Posts: 4
Joined: Fri Dec 28, 2012 7:57 pm
Location: Orlando, FL

Re: Home Alarm System Retrofit - "Part Deux"

Thu Jan 03, 2013 2:29 pm

Thanks, will let you know if I have any other questions as I try to make this work.

-- Edit:

Actually, is it possible to post a pic of your current pi setup connected to the existing wires? Just so I have a visual of what is going on.
lmcc wrote:
Tibedabeeto wrote:This is tight! So where do I start? How to connect pi to existing system? I am new to this and pi so any detail that you can provide would be great. Thanks man
I didn't actually do anything with the existing alarm control board. I just stole all its sensors and connected them to the RPi. (I've effectively discarded the original alarm control computer board.) All the sensors were labeled in my system, which made it easy.

If you're in a similar situation, just take the wire from one door sensor and disconnect it from your current alarm system. It should have two wires. Assuming your RPi is installed and networked close to where the old system is installed, connect one door sensor wire to ground, and another to an RPi digital IO pin.

If that doesn't make sense, I can back up the bus a little further.

-lmcc

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Fri Jan 04, 2013 1:36 pm

They would probably work fine, but some of the other stuff I've seen looks nicer. The ones in my house are recessed into the door frames and the edges of the doors.

http://www.homesecuritystore.com/c-219- ... tacts.aspx
hostingnuggets wrote:Thanks for the details, I really like your project!

Like suggested I had a look at some reed sensors on farnell.com and found the following one:

http://uk.farnell.com/assemtech/mmpsa-2 ... 20Products

which I could mount on the wall where the door opens and its assoicated magnet:

http://uk.farnell.com/assemtech/mmpsm/m ... dp/1173768

which I would mount on the door itself.

What do you think about this sensor? Would it be a good match for the Pi?

Happy new year to you too :)
H.N.

damauk
Posts: 3
Joined: Tue Oct 30, 2012 8:05 pm

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 08, 2013 12:31 am

This is a very neat set-up you have put together. I am an electrician and we have installed/programmed a number of security/home automation systems. I would defiantly recommend implementing at-least four "arming" states for your system (this is common in high-end commercial systems in our area). (I would offer some code but I am a little lacking in the programming department.)

The first state is "OFF" this is pretty self-explanatory, all functions of the security system (not smoke detectors though) are disabled.

The second state is "AWAY" this would mean any device would trigger an event. (Motion, Smoke, Door, Window, Etc.) You would use this primarily if you were on vacation or didn't have pets. There would be a trigger delay before the system would go into alarm.

The third state is "HOME" this would arm your perimeter zones. (Doors, windows) You would typically use this when you were home for the day, or early evening but aren't necessarily expecting someone to be coming home. There would be a trigger delay before the system would go off.

The final state is "NIGHT" this is the setting that you use when you are heading to bed. This condition would immediately trigger an alarm if any of the perimeter zones were triggered. I don't recommend the use of internal motion detectors in this condition as it is too easy to get up and wander around your house and trigger your alarm.

I believe that the different arming states could be handled in the "alarm agent" by changing which zones are polled and how often they are polled. I don't know for sure what the best route to implement this would be but it would be a useful feature, however it would require some sort of digital readout or indicator LEDs.

The best thing about having sensors on your doors, windows, etc. is that you can eventually tie them into a basic home automation system as well. So that you could create an event that when your system is armed and you open your door after dark the entryway light comes on automatically. You can also do smarter things like when your system is armed in "AWAY" you can have your lights turn on and off at different times of the evening to give your home that lived in appearance when you're on vacation. You can also do simple things like making your system poll all sensors to ensure that you remembered to close the garage door, kitchen window or what have you before you can arm your alarm so you don't leave your garage door open all night, of course all of these other conditions require a system with more than just a simple keypad or RFID card and may need a second Raspberry Pi to control the automation and interactions with the user.

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Tue Jan 08, 2013 4:06 pm

Thank you for your thoughtful reply, damauk.

I've been running this current configuration for a few days now and its clear the next improvement I need is a kind of sensor grouping like you're describing. I had initially thought I would give each sensor a group index (by adding a field/collumn to my sensor table). I could the round our my control command set with commands like "arm 1" and "disarm 3".

Having though about your post I think I'll add a text field instead and call it a sensor group label. My command set could then have things like "arm perimeter" or "disarm smoke".

There's still a lot of "holes" in this system set up. I think generally a bad idea to be arming and disarming this system using an email interface since nothing is encrypted. My only authentication right now is based on the source email address. It still better than what I had before (a dead alarm system), but I'm staring to think the emails should be for notification only.

I think this also needs need a web interface for administration, and at least an arming button by my front door. I've got a keypad and display at my front door leftover from the old system. Maybe I should be trying to interface to that next...

-lmcc

cisoftware
Posts: 1
Joined: Wed Jan 16, 2013 12:54 pm

Re: Home Alarm System Retrofit - "Part Deux"

Wed Jan 16, 2013 1:02 pm

Hi Guys,

It's my first time here. I have started looking into RPi stuff few weeks ago and so far I am happy with pbx and xvmc.
Not sure if you've looked into the sensors from Ubiquiti? They have quite few useful bits in their mFi range - pir, door sensors and temp/humidity.
I have ordered samples and hope to be able to play with them next week. ( I am moving at the moment)

Bart

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Thu Jan 17, 2013 3:14 pm

cisoftware wrote:Hi Guys,

It's my first time here. I have started looking into RPi stuff few weeks ago and so far I am happy with pbx and xvmc.
Not sure if you've looked into the sensors from Ubiquiti? They have quite few useful bits in their mFi range - pir, door sensors and temp/humidity.
I have ordered samples and hope to be able to play with them next week. ( I am moving at the moment)

Bart
I had not seen these before. Are they expensive? Do they publish an API we can work against?

-lmcc

damauk
Posts: 3
Joined: Tue Oct 30, 2012 8:05 pm

Re: Home Alarm System Retrofit - "Part Deux"

Thu Jan 17, 2013 4:17 pm

It looks like the Ubiquiti mFi is somewhat inexpensive, however you need to have an "mPort" for every three devices. It looks like the power plugs are in the $40.00 - $100.00 range and the sensors are $30-$50 for motion and about $10.00 for door sensors. (Here is where I found pricing http://www.doubleradius.com/Products/mFi/ ) So that would be like $210.00 plus getting the software working for a system with 2 door sensors, 2 motions detectors and plug strip.

I think it is a decent product, however there are older cheaper technologies that should be easier to make work with the raspi, like X10 or UPB for home automation and simply security systems (http://www.x10.com/minisites/x10securit ... index.html#)

I the route that you are currently taking meets a need that it is currently filled (as far as I know) and that is for an infinitely configurable security system that replaces conventional security installations, and in particular systems that have already been installed.

Blazzik
Posts: 1
Joined: Sat Feb 23, 2013 2:42 am

Re: Home Alarm System Retrofit - "Part Deux"

Sat Feb 23, 2013 2:46 am

Have you progressed with this any?

I just started my home AlarmPi project and I purchased a piFace with my Pi. I figured it would be a good start. I've managed to get the 3 door position sensors hooked up and working, and I can see the status of them on the piFace emulator. What would be my first steps to installing postgres and having your code work with it? Do you know what changes I would need to make in case of the piFace? I did see a wiringPi library for it...

Thanks in advance for any help you can give me!

Gadjetnut
Posts: 18
Joined: Fri Apr 05, 2013 9:13 pm

Re: Home Alarm System Retrofit - "Part Deux"

Fri Apr 05, 2013 10:48 pm

If you are building an alarm system, please check out this website:

http://www.projects.privateeyepi.com/home

They have full instructions on how to create an alarm system with email alerts, web based dashboard to view and control you alarm. No fees.

http://www.privateeyepi.com/image/dashboard.jpg

lmcc
Posts: 25
Joined: Wed Jul 25, 2012 11:25 pm
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Sat Apr 06, 2013 11:49 am

Gadjetnut wrote:If you are building an alarm system, please check out this website:

http://www.projects.privateeyepi.com/home

They have full instructions on how to create an alarm system with email alerts, web based dashboard to view and control you alarm. No fees.

http://www.privateeyepi.com/image/dashboard.jpg
I suggest you make your entire system software available. I think people will need to host and run it by themselves, for themselves, without using your site as a portal. I would be surprised if anyone is wiling to hand over care and control of their home alarm systems to you so readily.

Will you post you source code here? How about on Github?

-lmcc

matter
Posts: 1
Joined: Sat Apr 20, 2013 12:41 am
Location: Winnipeg, Canada

Re: Home Alarm System Retrofit - "Part Deux"

Thu Apr 25, 2013 11:12 pm

I'm taking a similar approach using RPi + python + postgres.

So far I've wired up a few door switches and have it logging, but I'm not sure how to connect the motion sensors yet. As installed, the sensors are powered at 13.8V and return 6.7V when motion detected. I have zero hardware background, so I'm not sure how to drop down to 3.3v. Zener diode / voltage divider / or some other combination? I'd really like to see what an ideal design would use.

Please let us know if you get your keypad and siren working.

phluxual
Posts: 1
Joined: Sun Feb 17, 2013 5:17 am

Re: Home Alarm System Retrofit - "Part Deux"

Fri Apr 26, 2013 5:20 am

matter wrote:not sure how to connect the motion sensors yet. As installed, the sensors are powered at 13.8V and return 6.7V when motion detected. I have zero hardware background, so I'm not sure how to drop down to 3.3v. Zener diode / voltage divider / or some other combination? I'd really like to see what an ideal design would use.

Please let us know if you get your keypad and siren working.
Motions are powered by 12v, your original panel shouldn't output more than high 12s to it. (13.8v seems very high, what kind of alarm system did you have?). Some motions have multiple terminals for different connection types, but typically they are normally closed devices, meaning when they are not sensing anything, the zone remains closed, when it senses motion it opens it. All you need to do is feed it into the RPi and check to see if it's shorted or not. I'm pretty sure you're going to want to regulate, though, or it will damage your board I would imagine.

jussi
Posts: 1
Joined: Sat May 18, 2013 12:32 pm

Re: Home Alarm System Retrofit - "Part Deux"

Sat May 18, 2013 12:45 pm

Hello

I just had to post and tell that this seems like an awesome piece of code.

With my little knowledge of coding and electronics I was able to pull out a home alarm system to be controlled over email. So far I have only tested it with motion detector and gertboard push buttons but everything seems to be working great.

Only trouble was setting up gmail. "email_alarm_target" was a bit tricky and payload was not readable by python. I changed payload part to read the header instead. Maybe issue with different python version or something.

To newbies like me a set up tutorial could be written to explain how to set up postgres and explain how to test email commands.

Thank you very much for sharing.

pikku-jussi

dauhee
Posts: 59
Joined: Fri Sep 07, 2012 1:50 pm

Re: Home Alarm System Retrofit - "Part Deux"

Wed Jun 05, 2013 8:04 pm

hardwiring is good. sensors that use RF433 can be jammed by intruders. The average criminal is getting more sophisticated. Even reed sensors are easily fooled with a strong magnet. Recessed reed sensors are much better because it becomes harder to circumvent. Window vibration is another bit of protection. PIR sensors are great but can get false alarms if pets are in the house.

A lot of security companies are going down the external video route - they monitor premises and trigger a call centre on movement when armed - operators can then shout at intruders and call police. This is supposed to be 99% effective and stops them from even getting a foot inside.

I'm paranoid about power being cut or wireless jammed. I'm working on a solution whereby nodes ping each other via wifi - if a ping is lost, the alarm is triggered in case there is wifi jamming - these nodes are basically a RPi in each room where window/doors are hardwired back to an RPi - this then polls back to the server RPi which does the coordination.

I used a lipo rider pro board from seeedstudio as a poor mans UPS in case the power is cut.

It also uses a gsm modem to send text/phone alerts in case the the broadband connection is down/cut. - there is a wonderful GSMmodem project in python to do this

There is also turning on/off of devices via Bye Bye Standby/Home Easy/Klik an Klaut - rcswitch library performs this functionality. I'm thinking of changing this for Zwave or Insteon due to them being older devices and less secure/reliable.

I had hoped to use the new camera module for the RPi but unfortunately there is an IR filter so no nightvision :( Instead I'm planning on hooking up a webcam and using the "motion" library which looks extremely promising.

Lot of work done. A lot lot more to do. Am learning a lot from interesting threads like this and the community of knowledgeable people out there.

RexRoper
Posts: 70
Joined: Wed Oct 31, 2012 4:45 pm
Location: South Florida
Contact: Website

Re: Home Alarm System Retrofit - "Part Deux"

Thu Jun 06, 2013 12:52 am

Your project very interesting and sounds like a great method for learning sensors, GPIO, and programming. Do you have any recommendations for beginners on how you put it all together?

Any insight is greatly appreciated. :)

htbwmedia
Posts: 22
Joined: Wed Jun 05, 2013 2:39 am
Location: Canada
Contact: Website

Re: Home Alarm System Retrofit - "Part Deux"

Thu Jun 06, 2013 3:05 am

Being in the industry http://www.keepsafesystems.ca and http://www.alarmparts.ca I have knowledge on the hardware end as well as easy access to information from manufacturers. My knowledge on pi though,.... Not so good yet.
So here is my 2 cents worth. Why muck about with inputs and adding input boards when most alarm panels have rs232 ports designed for either automation or printer output.
You can use a contact input on the pi to arm the system on older versions via the key switch zone programming or newer ones will allow you to send commands directly to the panel to accomplish this.

Soooo.... Since you have all this pi programming knowledge, check out my start up community on automation and security with the pi at http://www.LoxOne.ca yup, I'm a Canuck living in bc and I'm really eager to make this work and I am looking for others who want to contribute to an open source project :)

Cheers

Heinz

Oh ya, just a pointer on detectors. All motion detectors, except addressable combus versions and wireless (ackpthhhh) have a normally closed relay, opens on motion. Some Ulc versions have an additional N/O terminal.
Glassbreak detectors are the same as are floor flex sensors (available via Alarmparts.ca) water sensors etc.
Smoke detectors are Normally Open. There are two wire and 4 wire versions. 4 wire is easier to deal with when connecting to an RPi Heat detectors are non powered mechanical sensors as are door / window contacts. Heat detectors, like all fire sensors, are Normally Open whereas contacts are generally Normally Closed (Normally open are available)
Cast your vote if you feel Eben Upton and the Raspberry Pi Foundation deserve a Nobel Prize for their work in creating an affordable education tool

http://www.loxone.org/eben%20upton%20raspberry%20pi%20nobel%20prize%20nomination%20vote

jasonhobbs
Posts: 1
Joined: Tue Dec 17, 2013 1:29 am

Re: Home Alarm System Retrofit - "Part Deux"

Tue Dec 17, 2013 1:44 am

This all seems like a lot of trouble, especially to someone with 10yrs of everyday experience in low voltage electrical, especially dealing with instrusion alarms. Why not just use relays to control a commercial panel such as a vista20p with all wireless zones? I'm doing it with four 3v relays and three 12v relays. I personally don't have a need to know exactly what zone is in alarm as motions are a waste and come with extra false alarm tendencies. I have all perimiter openings contacted and glass breaks in each room.

The four 3v relays will be on the outputs from the pi obviously.
Arm Away
Arm Stay - Instant
Disarm
And the last to open the garage door via the web.

The three 12v relays are used for:
One on the bell out put to let me know the system is in alarm.

The other two come off the vista20p's onboard relay triggers for the keyswitch conditions - Keyswitch Red or Green. This provides notification of when anyone arms or disarms the system.


I'm sure this could be even more complex with the use of a 4208 or 4229 if someone had one to use instead of using onboard relay triggers..

htbwmedia
Posts: 22
Joined: Wed Jun 05, 2013 2:39 am
Location: Canada
Contact: Website

Re: Home Alarm System Retrofit - "Part Deux"

Tue Dec 17, 2013 8:01 pm

Ah, another low voltage guy :)
I love the relay concept and use it all the time for internal control and activation of pretty much anything electronic. The thing is, home automation and this project is about more than simply controlling the panel with an app and getting email notification. That is already common place in the alarm industry with a $100 module and a $10 app. Unless of course you are one of the unfortunate souls with a DSC (dealers second choice, now owned by Tyco which you can see as a toy company who will try to Take Your Company Over) or the equally aweful piece of crap Honeywell/Ademco with their ancient pcb and uber slow combus (which they only recently began to acknowledge)

I know I'm biased towards paradox, after all the head honcho, shmuel, has always been very approachable, there are also several other manufacturors who make awesome panels with various levels of relay functionality. Apex out of one of the Carolina's was one of them, but Honeywell bought them out and butchered them for their parts. Apparently it was too expensive to make a fully functional automation panel in the USA. Sad really.

Now onto what else can be done. With individual zone or zone group notification you can activate low voltage led lighting (just tear apart those stupid line voltage led bulbs and yank out the power supply which is prone to burning out, recycle the aluminum heat sink (don't need it at 12vdc.org) and you now have a bright azzed 12 VDC light source controllable with a simple relay. Thinner guage wire needed as well so for those building, you can save money on that new galvanic oxidation prone crap copper steel alloy china is churning out like bad diarrhea. Ever wonder why yellow wire insulation now turns black once power is run through it!? Copper and steel separate. But I could go on for hours about crap made in China.

Other things you can do is trigger music, maybe flag a room in a vacation home as occupied so the heat does not run unnecisarrily if that family member isn't there.

No more cold feet while taking a dump at 3 am or staggering for a light switch. Hell, you can even flush a toilet if you want.

As for motion detectors and false tendencies. Ya they can be a pain, but when properly installed considering all sources of random IR.... See the false alarms article at http://www.keepsafesystems.ca
There are many other activity/ occupancy detection methods including resistive piezo floor flex / stress sensors. Awesome little devices available at www.alarmparts.ca use those to detect when you walk in and out of a room or when you sit down for a comfortable poop. Why walk up stairs in the dark or pee on the toilet seat when your home is automated. The possibilities are endless.
In the more complex environments, you can also use "smart" IP camera's such as the Linux based, made in Germany, Mobotix IP "kamerrra" :) also available at www.keepsafesystems.ca for those in Canada (Mobotix AMP - highest level of integrator for Mobotix, also the Best pricing available) or www.alarmparts.ca again. I may be on abit of a rant on the Mobotix product line as I recently had a chat with Dr. Hinkel, the inventor of the Mobotix 360 degree camera. Amazing man, as a hobby he runs a farm on some of the land he owns in south central Germany. Very down to earth intelligent guy with some amazing ideas and a stickler for detail. Like all krau... I mean us Germans :)
With the Mobotix you can do trip lines, direction of motion, object counting and more. For more info on Mobotix, check out www.mobotixtech.com.

I could go on for hours on the advantage of single device per zone and the options within home automation but I'm sure that would bore most of you. If the topic doesn't bore the crap out of you (in which case do not worry about cold feet while purging :) ) drop me a quick note at my project page at www.LoxOne.org (apparently some Austrians are now ticked off at me, lots of lawyers have visited my site trying to take the project down... Sad really) oh well, as long as everyone knows it is a big coincidence and LoxOne has nothing to do with a particular Austrian manufacturer.

Has anyone tried utilyte fitPC? Alarmparts.ca distributes that. The guys at pi have sadly turned us down :( pi is an awesome product though and far more affordable than many others. Plus, not made in China :) sadly not Germany, but not China which is what matters most in quality control.
Cheers

H
An alarm guy by trade In Muddy Vancouver Canada
Oh ya, if you want to make your own plastic type boxes for the pi, keep an eye out on another hobby project of mine, www.miraclePutty.com I love the stuff (95% natural non petroleum) 2 part epoxy. :)
Yup, in an inventor attention wh0r3 with too much to say
Merry Christmas, y'all.
Cast your vote if you feel Eben Upton and the Raspberry Pi Foundation deserve a Nobel Prize for their work in creating an affordable education tool

http://www.loxone.org/eben%20upton%20raspberry%20pi%20nobel%20prize%20nomination%20vote

jrlambs
Posts: 2
Joined: Tue Feb 04, 2014 2:48 am

Re: Home Alarm System Retrofit - "Part Deux"

Tue Feb 04, 2014 2:52 am

I've been working on something like this also.. I've wired up the 4 door sensors just fine, but I also have 2 motion sensors.. each have 4 wires.. Red and Black (For Power) and a yellow and green (marked "N.C." and "Common". The power wires I'll probably have to get from an external power source.. probably the original alarm panel.. but I'm not positive how to wire up the other 2 wires.. everything I've seen shows how to hook up a 1 wire device.. I don't know what to do with the second wire :)

any help/suggestions?

Return to “Automation, sensing and robotics”