Tuesday, September 20, 2016

Alarm monitoring without the central station

My county’s police force is tired of responding to false alarms. They now require a $50 per year registration fee and will fine the homeowner $100 for each false alarm. How they determine a false alarm is highly dubious. Imagine a burglar attempts to gain entry though a door or window in your backyard but gets scared away from your alarm’s siren. The cops get called to the home by the central monitoring agency, but there’s no demonstrable evidence of a break-in like broken glass or a damaged door jam. “It must have been a false alarm,” the police will surmise. Ding! Pay $100. Actual break-in attempts are rare, so I can no longer allow my alarm monitoring service to automatically dispatch the police. What’s the point of even having central monitoring if I’m too afraid to have the police sent to my home? Quite frankly, the monitoring service is an anachronism. Most people carry cell phones pretty much anywhere they go. A simple text message or e-mail sent from the alarm system would obviate the need for central monitoring altogether. Alas, my alarm system is an older model that does not have that capability. Fortunately, I’ve come up with an inexpensive way to add it.

I have a background in electronics and computer programming, but like any good engineer, I don’t want to reinvent the wheel. If an off-the-shelf solution already exists, I’ll buy it and install it. I checked with alarm suppliers and they don’t have any kind of add-on device that sends SMS messages or e-mails for legacy systems. I investigated using an Arduino or Raspberry Pi with a WiFi or GSM module as the basis for a custom-built solution. It’s certainly doable, but it’s not very user friendly. If I need to make changes later, it will involve disconnecting the unit from the alarm system and plugging it into a computer to reprogram. The cost for all that hardware would be over $80 and that’s not counting relay circuits and other miscellaneous parts. I realized that there’s an another commonly available device whose hardware is more powerful and robust, costs less and is much easier to program: a refurbished Android OS phone. I paid $20 for a cheap LG phone for my son to make calls over WiFi for free a while back. It’s got GSM, WiFi, Bluetooth, and a touch screen interface. It runs faster than an Arduino and can be programed using free apps from the Google Play Store. Even someone without any programming experience can do it!

The biggest issue was to figure out a way to interface the cell phone to the alarm system. The siren terminals output 12VDC when the alarm is triggered. I can attach a relay circuit to that, but how to interface it to the cell phone? I could buy an IOIO board from SparkFun and connect it to the phone via USB. It’s not too expensive at $40, but it’s overkill for what’s needed. I remembered that wired headphones sometimes have buttons on them to control the media player. There’s only four electrical connections: left speaker, right speaker, microphone, and common, so where are the data lines? It turns out that commands are sent to the phone by shorting the microphone circuit. A small duration button press tells the media player to toggle between play and pause. A longer duration press can be used for other features. Adding predetermined values of resistance between the microphone connection and ground can trigger additional features like changing tracks or volume. However, we only need one trigger and shorting the microphone input will be the easiest to accomplish. A simple relay circuit connected to the audio jack of the cell phone gives us all the external control input needed.

Cell phones use a 3.5mm 4 conductor jack. This allows for stereo speakers (headphones) as well as a microphone. We could buy a 4 conductor extension cable and hack that up to wire the microphone to ground when the alarm is triggered. A spare 4 conductor 3.5mm wire originally used for video output from an old portable DVD player can be hacked for this project, too. (The red RCA plug is usually the one mapped to the microphone.) The instructions below use a headset adapter that splits out the mono microphone and stereo audio into separate jacks. A mono 3.5mm cable to bare wires is used to connect from the splitter and the output of our relay. It doesn’t matter which method you choose. Pick the easiest and cheapest.

The alarm system will trigger the siren and apply a constant 12 volts for the duration of the event. We don’t want the relay to remain on during for the entire time. Instead, we want a single short pulse sent to switch the relay on and off for approximately a second when the siren is activated. (I should note that this would still work if the relay was left in the on position for the duration of the siren’s activation since the cell phone media button feature works on the initial button press and not its release. However, this type of relay circuit does not cost significantly more than a simple one so the proper input duration can be provided.) This type of electronic circuit is called a monostable multivibrator. I’ve built them in the past using a 555 timer, but assembled power circuit boards are readily available from China for dirt cheap. I found one that does exactly what we need and can be configured by switching a few jumpers around.

Relay timer circuit.

Amazon sells both the older and newer design. The biggest difference is the reset button on the newer version. It’s not needed for our application, but it was only $2 more, so I sprung for it. The older version of the relay timer can also be found from other sellers on Amazon (and eBay) for less, but they usually ship the board from China. Search for “FC-32 timer” to find it. One big word of warning about this relay timer circuit:

Siren Ensure jumper S5 is NOT connected! Enabling this jumper may damage your phone, relay, and alarm system! Siren

The S5 jumper will tie the input common to the output common. This is a big no-no for this application since we want the alarm siren and cell phone audio jack to be electrically isolated from each other.

Alarm systems may provide 12VDC constant power for external devices. We can add a wired car charger with a MicroUSB jack to supply power to the cell phone. This is completely optional and would only be necessary if the cell phone’s charger couldn’t be plugged into a nearby outlet.

It would be a good idea to disable any power saving features for the dedicated cell phone even when on battery power. Automate can disable the power save feature for you and can even keep the phone “awake” if necessary. I believe any power saving features that could cause issues were introduced in Lollipop. My spare phone had KitKat installed.

Sending SMS messages without cell service can only be done through e-mail. I tried using Google Voice with Hangouts as my SMS client, but SMS messages cant be sent through Hangouts using Automate. It’s also currently not possible to use the Google Voice app with Automate either.

I added a separate fiber in Automate to send an email alert when the phone is on battery power and when AC power is restored. I won’t be providing instructions on how to do this. I’ll leave it as an exercise for the reader.

I programmed the messages to contain the phone numbers to the non-emergency police hotline and my neighbors. My personal cell phone will alert me with a siren sound and display an eye-catching image. I accomplished this by customizing the phone book contact for the cell phone number and/or GMail account used for the alarm system. Some stock messaging apps do not allow for custom contact notification sounds. I had to install Handcent Next SMS on my Samsung device to get that feature.

UPDATE 2017-11-25: I swapped out the old cellphone that I was using for my alarm monitoring. The Android OS was so old that I had to hack it to prevent the Google Play Store from updating. The ancient version of the app worked, but would crash sometimes during updates and reset the phone. WiFi would be lost until I manually rebooted it. My son’s old cellphone was a perfect replacement specs-wise, but I couldn’t get it to work in the system. An old pair of earbuds with a media button triggered the automated messaging script, but it wouldn’t work when I plugged it into the system. It took me a while to figure out the cause: The new phone dynamically configures itself for a variety of audio devices when a plug is inserted. A three conductor plug with 20-32 ohms across each conductor is a stereo headset. A three or four conductor plug with 20-32 ohms across one or two conductors and 1,000-2,000 ohms across the other means it’s a mono or stereo headset with a microphone. The phone will interpret an open circuit (infinite resistance) as there being no microphone and will not accept media button inputs. The solution was to put a 2.2K ohm resistor across the terminals to mimic the impedance of a microphone connection. I have included the new part in directions below.

Parts


Directions


Create the Automate Flow

  1. Connect your cell phone to your WiFi network, if applicable. Create a new Google account for this phone. I suggest creating the account on a desktop/laptop computer rather than the phone if the Android OS on the device is old.
  2. Install Automate on the cell phone from the Google Play store.
  3. Create a new flow as pictured here:


    This flow sends an e-mail using the GMail account. You can send SMS messages through e-mail, too, or send them directly if you have cell service. Feel free to expand on the flow to include other forms of communication. Remember to loop back to the beginning like shown above.
  4. If you have a wired headset designed for a cell phone with a button, plug it into the cell phone and test the program. Make sure all of the communications are sent by the cell phone and received on all the other devices.
  5. Configure personal cell phones receiving the SMS messages from the dedicated one connected to the alarm system to use a custom ringtone/notification and contact picture.
  6. Optional: Install a remote control app like TeamViewer Host or TeamViewer QuickSupport to remotely control the phone from a computer. It will make further enhancements and fixes easier.

Hardware Assembly

  1. Set the jumpers for the relay timer as follows: S1=0, S2=1, S4=OFF, S5=OFF, S6=ON, S7=OFF. This will configure it to turn the relay on when 12VDC is applied to VCC and GND for a short amount of time and ensure the input is isolated from the relay outputs.
  2. Connect the 3.5mm mono plug bare wires to the normally open (NO) terminals of the relay. Insert the 2.2K ohm resistor across these terminals, too. You may want to trim the leads of the resistor. Use a very small flathead screwdriver to tighten.
  3. Plug the other end of 3.5mm mono plug into the microphone connection of the splitter. Plug the splitter into the cell phone.
  4. Use the speaker wire to connect the alarm siren terminals to the input of the relay timer. Be sure to use the correct polarity.
  5. Trigger the alarm system to test if the relay timing is correct. Use the very small flathead screwdriver to adjust the potentiometer on the relay timer to ensure the duration of time the relay is closed will trigger the fiber in Automate properly.

Future enhancements


I thought about adding a feature where the cell phone would make a voice call to me and play a prerecorded message. However, it’s impossible (as far as I know) to play an audio file to a recipient during a phone call. The workaround would be to create a loopback plug. I haven’t actually tested this idea, but it’s what I would attempt. Another way to provide this feature would be to use a third party service to handle automated voice calls. The costs are surprisingly low and the companies usually provide an API to interface your product with their service.

Automate can obtain data like local weather and rainfall. I’m thinking about using a relay controlled by DTMF tones connected to the headphone jack to act as a rain sensor for my sprinkler system. This is why I chose to specify the headset adapter in the parts list above. This project uses the microphone port as a control input and that project will use the headphone jack as an output.

No comments:

Post a Comment