Linux Home
Automation

(Last updated: Feb. 10, 2009)
Google
 

Elk M1 page

A work in progress (working code should be available by the end of december)...

This page is to provide for support of the Elk M1 through the use of Perl. I've taken James A. Russo's ElkM1::Control Perl module (not available on CPAN, yet ;-) ), here's a local copy) and added support for use of the serial port as well as the Ethernet module (ELK-M1XEP). Just grab this Perl module code. Here's an example:


    use lib '/home/njc/dev/v2-104/lib';

    #use strict;
    use warnings;
    use Carp;

    use ElkM1::Control::Serial;

    my $elk = ElkM1::Control::Serial->new( 'port'   => '/dev/ttyM1',
                                           'speed'  => 115200);

    # Main loop, read any message.
    my $msg;
    $| = 1;

    while (1) {
        # This portion differs from James Russo's code.
        # I had some trouble with NULL $msg (perhaps it was undefined?)
        $msg = $elk->readMessage();

        if(!defined($msg)) {
            sleep 1;
        } else {
            #while (defined($msg = $elk->readMessage)) {
            if (ref($msg) eq 'ElkM1::Control::ZoneChangeUpdate') {
                print "zone ".$msg->getZone." is now ".getState;

                # If zone 1 is violated, activate task 1
                # and do something else.
                if ($msg->getZone == 1 and $msg->isViolated) {
                    $elk->activateTask(task => 1);
                    # ... something else ...
                }
            } else {
                print $msg->toString . "\n";
            }
        }
    }

This code is very similar to the code that James include with his package. You'll need to grab the Serial.pm module and drop it into the ElkM1 directory that you untar'd from James' package. James' package untars into ElkM1-Control-0.02/ . I renamed it ElkM1 (that's important). Note that in the example above I included the line use lib '/home/njc/dev/v2-104/lib';, in that directory is my ElkM1 subdirectory and in there is where I put my Serial.pm file . The use lib line allows Perl to know where to look for the modules. This adds to the existing Perl library path. The reason for all this mess is that I'm trying to experiment with the code and I don't want it installed in the normal Perl paths (where I wouldn't need to include the use lib '...'; line).

Note that in the example above there are a few sections that differ from James example. I had a lot of trouble with NULL $msg being returned (maybe undefined?) so I need to alter the code in the manner above. Also, I've created an ELKM1 support web page to support my additions to the code and perhaps extend the original code. At this time it's not a very useful page but I'll add to it as I get things properly working. Much of my code will be added to Misterhouse but not James original module, so the page will also reflect that. At the moment I'm trying to clean up my HA server so I can run two copies of Misterhouse. One that runs the home the other that run my development environment. It's difficult to do since I have so many things running there.

Links