X10 Home Security DIY - Arm / Disarm
Most home security systems come with an entry panel that is used to Arm or Disarm the system upon entry or exit. Some come with key tags (or apps on your phone) that will arm or disarm the function automatically - we'll take a look at that option in a later post. For now, let's look at implementing a simple arm and disarm function using a keycode.
There are several methods that can be used to implement this function on a web server:
- Using a global environment variable - purists would no doubt prefer this method, as it demonstrates their advanced coding skills and understanding of Linux environments.
- Using a file. That is, you store the ARM/DISARM status in a file accessible from the server. I prefer this method - it is similar to how passwords are stored, and the file can be encrypted and protected more easily.
We may also need to implement an arm delay - to allow for someone hitting the ARM button in the control panel just before opening the door and exiting the building. Or maybe we just delay the disarm write until the very next window/door sensor event has completed.
Implementation
We modify the X10arm.pl script called from the control panel (when the ARM button is pressed) to open the X10.log file and write the status "X10 Alarm System is ARMED" into the file. Similarly, we modify the X10disarm.pl script to write the status "X10 Alarm System is DISARMED" into the log file.
Now, when a trigger event happens (window/door sensor, motion sensor), we condition the notification response based on the X10 Alarm status (which we read from the X10.log file) in the bashX10.sh script. If the system is ARMED, we send out all kinds of notifications; if the system is DISARMED, we limit the notifications (to flashing the lights, or popping up a desktop notification on my desktop, for example).
We further modify the X10disarm button to call a separate HTML file first - here is where we implement the keycode. Instead of calling X10disarm.pl from the control panel HTML, we call security.htm instead - and this file contains a simple form to produce a keycode panel, as shown below:
Again, we use some nice styling to produce hover effects and shading (thankyou w3schools for the styling library), store the entered codes into a Javascript variable, and when the Submit button is pressed, we compare the submitted code to the stored and encrypted passcode, and then set the X10.log status to "X10 Alarm System is DISARMED" if the code matches. We can even allow three attempts or some such method to prevent unauthorized access, but I wouldn't recommend relying on this method alone - after all, notifications would already have been sent out by the motion sensor or window/door sensor logic if someone unauthorized entered your building.
Browser hackers will also note that the user could always right-click and select "inspect code" in Google Chrome in order to examine the html file and variables (which is another reason to put the keycode in a separate file), so we don't want to disallow all notifications.
A note on External Security of the Control Panel
If you expose your control panel to the internet (by providing a port forward through your router to the Abyss server port that services it) then you will need to implement at least SSL (https:) security. Me, I prefer not to run the risk at all - the control panel and the entire server are only visible if you are connected to my LAN, and then again only if you are a recognized IP stored in the reservations list on my router. It is simple enough to get a message or status out of my LAN (e.g. to IFTTT); it is very difficult indeed to get in.