Follow Me Icons

 

Follow @KendrickColeman on TwitterConnect on LinkedInWatch My Videos on YouTubeFollow me on FacebookCheck Out My Projects on GitHubStay Up To Date with RSS

Search

BSA 728x90 Center Banner

Total Noob Guide To Move Your Old Wired Security System to SmartThings

This week I posted an update on twitter and facebook of my latest project where I took all the wired window and door sensors from my old security system and integrated them into SmartThings. Many people said they want to do the same thing and I know that my usual step-by-step spoon-fed tutorial was in order.

 

 

 

 When I purchased my home last year, I had a tough decision to make. We were going to do a lot of renovations and I had to decide whether to keep the existing alarm system or just rip it all out. The alarm system was installed in the early 90's and the plastic keypads and motion sensors that were installed in the walls had turned yellow from sun damage. I spent a week researching how to replace everything because it didn't make sense to rip out a perfectly good security system, but finding replacement parts proved impossible. It was an old GE Caddx Security System that is now obsolete. I ended up disconnecting the power and back up battery, removing the keypads and motion sensors, and letting the contractor cover all the holes with drywall. However, all the contact sensors within the doors and windows were still there and in-place. I should note, that my smoke alarms were never integrated into the security system so I didn't have to worry about those. I also ended up ripping out the alarm speaker/siren thinking I would never need it again. In hindsight, I should have kept it.

 

A few months went by and I got SmartThings and started getting into home automation. The first thing we have to do is lay down an initial requirement. SmartThings is the only platform that can be used for this tutorial. I really like SmartThings because it's a plug-n-play home automation set up that has a ton of integrations as well as an Open API & Developer Program that allows lots anyone to create custom apps and devices. It's pretty cheap to get started with home automation, but it can get expensive quick. I finally found myself with a few hours of spare time and decided to look into integrating the door and window sensors into SmartThings. I could have spent $25-$45 per door and window on Z-Wave Contact Sensors, but it would be ugly, expensive, and a hassle replacing batteries every year. After a few hours of research, spending a long time reading comment threads, buying equipment and waiting for delivery, I was able to have it fully integrated. It's awesome to give this old technology new life. So lets do this!

 

Materials:

 

Step 1. Examine Your Security System

Your security system may have been segmented out into zones for doors or windows to belong to a certain "zone". You can keep everything in zones if you want, but I opted to have every individual device work on its own. Of course, this is also going to depend on how many devices you have. I have 5 doors that act individually, but all my windows are wired together before they reach the panel so they all have to be on a single circuit. The example we are going to use for this tutorial will not have any motion sensors, sirens, etc. It's going to only be the contact sensors, which are very simple to use. 


One thing you may notice on the old security system is that there are resistors that limit the amount of power making a loop on each circuit. This was necessary on the old system because the sensors may have been ruined if too much current was running through them. However, it's your choice to keep or remove them with this new setup. I opted to remove them because the Arduino will be responsible for sending a low voltage signal through the digital GPIO pins and doesn't need an Ohm resistor. It will keep it cleaner.

 

Step 2. Know Your Security System

The wires going into your panel may or may not be labeled to which device they lead to. Mine were not. For me to properly wire everything, I needed to test each circuit and see what the wires were leading to. To test it, we need to load a Sketch on the Arduino. Download and Install the Arduino Software on your computer. You can also go ahead and place the SmartThings board onto the Arduino. Look at the pin numbers to make sure they line up. Pin 1 on the Shield lines up with Pin 1 on the Arduino, etc. Grab 2 jumper wires. Plug one jumper wire into IO Pin 7, and plug the other jumper wire into a GRD (ground) IO input. Next, plug the Arduino into the computer. Go to tools and set the type of Arduino to Mega.

 

Create a new Sketch by copying and pasting this code (taken from parralax.com)

const int switchPin = 7;     //     // Reed switch to digital pin 7

void setup() {
  pinMode(switchPin, INPUT);        // switchPin is an input
  digitalWrite(switchPin, HIGH);    // Activate internal pullup resistor
  Serial.begin(9600);
}

void loop() {  
  Serial.println(digitalRead(switchPin));  // Display current value
  delay(200);
}

 

Hit the upload button. Click on the magnifying glass to bring up the Serial Monitor. Set the Baud Rate to 9600. At this point, you should see "1" scrolling on the screen every 200ms.

 

Here's the fun part. Unscrew the wires going to Zone 1. With your first pair of wires, connect one to the wire coming from Pin 7 and the other coming from GRD. You will not get shocked, the voltage is going to be really really low. If successful, there will now be "0"s scrolling on the Serial Monitor. Have someone go around the house and open doors or windows until you see "1" scroll on the screen. Label the pair of wires so you know what each wire is going to. Keep doing this for every pair of wires that are coming from Door or Window contacts.

 

Step 3. Build The Arduino Code

Like I mentioned earlier, SmartThings has a Developer Friendly Open API and Daniel Orgochock created the ST_Anything Project. This is where all the magic happens. It's a project that has gained LOTS of attention. My goal of writing this blog was to create a noob-friendly version because the GitHub Project README goes deep pretty-fast and most people don't want to read 250+ comments. However, always pay close attention to the GitHub Project README as the source of truth because projects graduate and mature over time.

 

The key to learning all this was to look at the examples listed in ST_Anything_Doors and ST_Anything_Doors_Windows and adapting to make sure the code made sense between 3 different files and there weren't additional libraries and code being used that wasn't necessary. Read through all the examples in the GitHub Project to learn how to integrate more things like PIR Motion Sensors, Sirens, Smoke Alarms, Furnaces and more.

 

  1. Download the ST_Anything.zip file (linked directly from GitHub). Unzip it
  2. Locate your Arduino directory
    1. Mac: ~Documents/Arduino
    2. Windows: C:\My Documents\Arduino
  3. Copy all the folders within the ST_Anything/Arduino/libraries folder from the unzipped ST_Anything.zip file to Arduino/libraries. These libraries are necessary for the following code to work.
  4. Create a Sketches folder within your Arduino directory
  5. Create a folder inside of Sketches called ST_Anything_Doors.
  6. Create a new file called ST_Anything_Doors.ino and copy and paste the following code:
  7. Here's where you need to go through the code and edit lines 78-85, 106-111 and 131-136 to fit your use case. Use my code as a starting block. Remember in part two where Pin 7 was used for our testing? This is where you specify pins 4-5, 7-13 and A0-A7 (analog only) for each of your devices. Do not use pin 0-3 or 6 as they are reserved. Add or remove lines as necessary. The spelling and capitalization (camelCase) is crucial to keep consistent through the rest of the programs. 
  8. Click the Verify button within the Arduino program and see if it compiles. If it compiles, then click Upload.
  9. Lastly, to facilitate communication between the shield and Arduino, grab 2 jumper wires. (If you are NOT using the Mega and using an Uno or something else you had laying around, you must read the Geeky Material on the ST_Anything GitHub Project README because serial communication is necessary.)
    1. Connect Pin 2 on the SmartThings Shield to Pin 14 on the Arduino Mega
    2. Connect Pin 3 on the SmartThings Shield to Pin 15 on the Arduino Mega
  10. Click on the Serial Monitor and you should see all the devices start to show up and some debug logging happening on the screen.

 

Step 4. Hook up the Arduino to your old security system

Now it's time to connect everything together. Match the GPIO Pin to one wire from the sensor. For instance within the code, I have the Front Door matched to GPIO Pin 5. Take a jumper cable and use your scissors or box cutter to clip one male end and strip it to expose part of the wire. Take one wire from the Front Door and use a small wire nut (or if you want to go full permanent, use a soldering iron) to tie the two wires together. Take the other male end of the jumper wire and plug it into GPIO Pin 5 on the SmartThings Shield. Continue doing that with every component. 

 

We cannot forget to close the circuit with the ground. Take one jumper wire and all the second wires from every component and tie them together using a large wire nut. Take the other male end and plug it into one of the three GRD GPIO Pins.

 

Use your old Apple iPhone/iPad charger and the Printer USB cable to power up the Arduino

 

Step 5. Pair your SmartThings Shield to SmartThings

If you know your way around SmartThings, this step is easy. Start searching for new devices within the SmartThings App and then hit the Switch button that is physically on the SmartThings Shield. It will show up as Arduino Things. Click Done.

 

Step 6. Create a New Custom Device Type/Handler

  1. Go to the portal for the backend of your hub and login then go to My Device Types (https://graph.api.smartthings.com/ide/devices)
  2. Click on the green button +Create New Device Handler
  3. Click on the "code" tab, Copy and paste the following code
  4. As you may have guessed, you need to change the code to match each unique component from Step 3. I don't know if it's critical or not, but keep the spelling exactly the same between all files for the devices such as "frontDoor". Examine lines 29-34 and 49-73. The only thing that needs to be edited is the device name itself. No other code needs to be manipulated within "standardTile("frontDoor", "device.frontDoor",".
  5. On line 75, within "main()" specify whichever sensor you want displayed on the "Things" screen
  6. On line 76, make sure that every device is separated by commas. These will be visible when you click on the Arduino ThingShield.
  7. Click on Save and Publish -> For Me.
  8. Go to My Devices (https://graph.api.smartthings.com/device/list), Click on your Arduino ThingShield, scroll to the bottom and click Edit, change the "Type*" to ST_Anything_Doors that we created. It will be near the bottom of the list since it's a custom added device type
  9. Click Update
  10. At this point, kill the SmartThings app on your phone or logout and log back in. Click on the Arduino ThingShield and you should see all your devices. Go around and test the sensors. Open and close some doors and you should see the device change state.

 

Step 7. Create a New SmartApp for the "Multiplexer"

Having everything inside the Arduino SmartShield Thing is nice, but if you have contact sensors, motion sensors and more, how do you act on each piece individually or categorize it? A "multiplexer" will allow us to to display each device as a single "thing" within SmartThings.

  1. Within the backend of your hub go to My SmartApps (https://graph.api.smartthings.com/ide/apps)
  2. Click on the green button +New SmartApp
  3. Click on the "code" tab, Copy and paste the following code:
  4. It's the last time we have to edit the code. Lines 36-46, add or edit and make sure the device spelling matches accordingly
  5. Lines 65-81, each of your devices needs their own Open and Close subscribe methods
  6. Lines 84-185, each device needs functions for Open and Close events. 
  7. Click on Save and Publish -> For Me.
  8. We, still aren't done yet. We need to create "virtual" devices. Go to My Device Types (https://graph.api.smartthings.com/ide/devices)
  9. Click on the green button +Create New Device Handler
  10. Click on the "code" tab, Copy and paste the following code:
  11. Now we have to create "virtual" devices for EACH of our "things". In my case, I needed to create 6. Go to My Devices (https://graph.api.smartthings.com/device/list)
  12. Click on +New Device
  13. Give it a unique name that you want to see within SmartThings App like "Door - Front". Give it a random Device ID like 0123 (no two devices can have the same ID). Set the "Type*" to "Virtual Contact Sensor". Set "Location" and "Hub" to your local hub and click on Create. Do this for each device! If you have 13 devices, then make 13.
  14. From the SmartThings App, go to Marketplace -> SmartApps -> My Apps -> ST_Anything_Doors
  15. Match up each input with each Virtual Device Sensor that was created. Click Done
  16. Now you will see each device show up as a "Thing" within the SmartThings App. Most of these will show up as "open" because they need to be reset. Go open and close all your doors and windows to reset the sensors. Now they should show up correctly within the App.

 

 

You done. pretty awesome, right!? Now each sensor can be added to the Smart Home Monitor or you can take a look at using Smart Alarm which is nice because it has delays built-in.

 

Related Items

Related Tags