Category Archives: Home Automation

Monitor Your Elk-M1, Log to MySQL, and Daemonize it!

I received a request a couple of days ago from someone who saw my posts on the Elk–Control perl library that I took over responsibility for. I had mentioned that I logged every Elk event into a MySQL database.

I am happy to report that I have this script running as a daemon, logging every ElkM1 event into my database. And it runs for months without issue.

I will keep these instructions brief. If you have detailed questions, please ask in the comments and I’ll help the best I can.

Download

You can download all the scirpts, just click here.

Notables

  1. If you don’t know a least a little perl and some MySQL basics, you may want to look elsewhere.
  2. The script and accompanying files are designed to work in concert as a daemonized process.
  3. Everything is logged into ‘elk_monitor.log’ in the same directory (or directory of your choosing) as the script. If you have a lot of passive infra-red motion detectors, you will want to monitor the log size.

Basic File Structure

file structure

elk_monitor.pl

This is the main script, it runs in a loop checking for new messages every second. You will need edit the %zonelist, %outputs, %areas near the top. Also, you will need to set some paths, look near the top of the file.

Required: ElkM1::Control, Log4perl

elk_monitor.sh

This is the shell script that controls elk_monitor.pl as a daemon. Setting up daemons can be complex as each system is different, so google around for some help.

elkm1.sql

A MySQL script to setup the tables and fields that the elk_monitor.pl script uses. You will need to add a database named ‘elkm1’. After that you can execute this script to create everything else for you.

lib/elkm1_db.pl

The database setting and basic sql commands are abstracted into this library. This is where you will need to set MySQL’s host, name, password, etc.

lib/file_tickler.pl

I use a custom ruby script to monitor the daemon. This library just touches a file every minute to let us know the elk_monitor.pl script is still running. Why? Well, I have had the script ‘freeze’ without exiting and most monitoring applications do not detect this. Obviously, this part is optional.

Conclusion

If you get all the settings right, she should run all day/week/month for you.

I and not a perl expert. Far from it. So I’m sure everything could use some tidying. If you do, please let me know and I’ll incorporate your changes.

Posted in Home Automation, perl. Tagged with , , .

Elk M1 Security System Control with Perl Script

I have an Elk M1 security system that I like to monitor and record all the activity. It’s useful to know what doors are open and how long they have been open. For several years in the past I have use Homeseer to do the monitoring where I wrote VBScript files to push the activity and changes to my MySQL server. Honestly, I have never likes Homseer, it’s flaky and I prefer that I don’t depend on WinXP either.

About a year ago, James Russo released a script on Cocoontech to monitor and control your Elk M1 from a perl script. You can read the forum post for more details. Thanks to James and other Cocoontech members, it works fairly well.

But there have been no updates or bug fixes in over a year. Not wanting to relive my perl days (sorry, I never really liked perl), I decided to revive the project and give it a new home. I asked James for permission to take over the project and he gracefully agreed.

ElkM1::Control New Home on Github

Go check it out! ElkM1::Control on github.

Why github? First, I have stopped using SVN. And sourceforge, ElkM1::Control’s original home, doesn’t support git. Second, github makes it too easy to fork a project and make changes yourself, then push them back up so that I can integrate those changes. You really should try git if you haven’t before. And you don’t need git to download ElkM1::Control and install it.

Updates and Bug Fixes!

You read that right, I have made a few bug fixes and added a couple of new features. I have been running ElkM1::Control on my Ubuntu Hardy server for about a month with no problems. I have also run and do some debugging on OS X (10.5.x).

I also changed the version numbering system to the more common major.minor.release notation. We are not at version 0.1.0.

Quick Installation Instructions

  1. Goto the project home page and click the download button. Select the ZIP version (for some reason the TAR doesn’t work sometimes).
  2. Follow the README file, don’t forget the PREREQUISITES section. For those who don’t rtfm…
  3. From your favorite shell, you may need to add sudo in front of each: ‘perl Makefile.PL’
  4. ‘make’
  5. ‘make test’
  6. Then to install: ‘make install’

Next, you’ll need a little script to get going. There are several scripts posted on Cocoontech, but this one should get you started:

[source lang=’php’]
# Example 2: Display all M1 messages
use ElkM1::Control;
    my $elk = ElkM1::Control->new(host => ‘192.168.0.251’, port => 2101);
    while (1) {  # Loop forever
        while (my $msg = $elk->readMessage) { # Read the M1’s messages
                print $msg->toString;  # Print the messages
        }
    }
[/source]

Posted in Home Automation, perl. Tagged with , , .

Disappointed with SmartHome Quality

My home it pretty well automated. By that, I mean that our security system, an Elk M1-gold, can control the house lighting, thermostats, and drip irrigation system. Lights come on and turn off automatically as necessary. The ELK uses a expander device which connects to an INSTEON controller. The INSTEON controller has the ability to turn on/off/dim any light in our house that has an INSTEON switch. When it works, it’s great. When it doesn’t work, it really sucks.

So then, why doesn’t it work? Well, it seems that the Smarthome engineers forgot to spec quality components as the failure rate of most of the INSTEON and ICON (a cheaper version of the INSTEON switches) is over 50%. That’s right, more than half of INSTEON switches have failed, they either do not turn off, or they will not turn on. Nice.

Continue reading

Posted in Home Automation. Tagged with , .