X10 Integration

From SecuriWiki
Revision as of 18:20, 6 April 2015 by matt (Talk | contribs)

Jump to: navigation, search

There is unofficial support for integration with X10 using the mochad package.

Usual disclaimer, use at your own risk. This has been tested on 3 devices so far to my knowledge, and I am not responsible if it breaks yours.

This has been most recently tested to work with firmware R070. When upgrading, you may have to reinstall (following all below instructions, your mochad.conf should be unaffected by the upgrade).

Installation

You may install it manually by compiling from source, copying over the binaries, etc, or you can use opkg. Links are posted at the end for the manual method, I will simply state the opkg method here.

You can probably do most if not all of this from the OpenWRT web interface, but the method I am describing here requires ssh access and basic shell knowledge.

You may use my host as the package repo for opkg (just please don't hose it ^_^): http://remote.thejanky.org/mirrors/almondplus/packages/ To use this, edit /etc/opkg.conf in your favorite editor and replace the first url, as that one doesn't point anywhere. If you want to use the other unofficial repo, you can switch it back after you do this installation.

Then install some dependencies and mochad.

opkg update
opkg install libusb-1.0 usbutils
opkg install mochad

The above installation should do everything for you now. If for some reason it didn't, refer to #Old Installation.

If you are utilizing the X10 mapping or LimitlessLED mapping, you will need to configure your map (and LLED hub information) in /etc/mochad.conf. If you are just using it for tcp connections/push notifications, you should be all set!

Using Mochad

To interact with mochad directly, you send commands via TCP on port 1099. The commands are of the form:

SYSTEM DEVICE COMMAND [PARAMETERS]

Systems

  • AP - Almond Plus controlled devices
  • RF - X10 RF module
  • PL - X10 Powerline module
  • LL - LimitlessLED module

Devices

All devices for each system should be supported.

  • AP - Device id (numerical, 1, 2 ...)
  • X10 RF/PL - X10 Device specification, House Code & Unit Code (e.g. A4, C6)
  • LL - LimitlessLED group number (1-3)

Commands

To see your current device list with device IDs, look at /DeviceList.xml on your A+.

Example Commands

# Turn A+ device 1 on
echo "AP 1 on" | nc localhost 1099
# Turn A+ device 2 off
echo "AP 2 off" | nc localhost 1099
# Get switch status of A+ device 1 (ugly, I know)
echo "AP 1 get_val 1" | nc localhost 1099

Controlling Almond+ using X10 RF Controllers

If you want to be able to control LimitlessLED or Almond+ devices using X10 RF Controllers, you will need to modify the /etc/mochad.conf. This file specifies mappings from X10 device codes to Almond+ device and LLED group IDs.

To see your current device list with device IDs, look at /DeviceList.xml on your A+.

HTTP Interface

I wrote a tiny perl script to interface with mochad, in case you prefer that to TCP (and since all dependencies already exist on the Almond+). This is now automatically installed by the package, but I am leaving the code here as an example/reference.

#!/usr/bin/perl -w
use warnings;
use strict;
use IO::Socket::INET;
use CGI;

my $q = CGI->new();
print $q->header();

if (! $q->param()) {
  exit();
}

my $sock = IO::Socket::INET->new(
        PeerHost => '127.0.0.1',
        PeerPort => '1099',
        Proto    => 'tcp'
        );
die "Cannot connect to the server $!\n" unless $sock;

my $req = $q->param('q') . "\n";
my $size = $sock->send($req);
shutdown($sock, 1);

my $resp = "";
$sock->recv($resp, 1024);
print "$resp\n";

$sock->close();
chmod +x /www/cgi-bin/mochad.pl

Then you can send any command as an HTTP GET request to the parameter "q":

http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP 1 on

or if you can't do spaces (%20 = space):

http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP%201%20on

Upgrading

When upgrading the Almond+, you may have to follow the installation instructions again.

Uninstalling

You should be able to uninstall with opkg. You may have to delete the conf file manually (/etc/mochad.conf).

References

Related forum topics: http://forum.securifi.com/index.php/topic,1913.0.html http://forum.securifi.com/index.php/topic,615.msg7006.html#msg7006

Original Mochad project: http://sourceforge.net/projects/mochad/

My fork: https://sourceforge.net/u/armattillo/mochad/ci/master/tree/


Old Installation

You may use my host as the package repo for opkg (just please don't hose it ^_^): http://remote.thejanky.org/mirrors/almondplus/packages/ To use this, edit /etc/opkg.conf in your favorite editor and replace the first url, as that one doesn't point anywhere. If you want to use the other unofficial repo, you can switch it back after you do this installation.

Then install some dependencies and mochad.

opkg update
opkg install libusb-1.0 usbutils
opkg install mochad

Udev does not currently have an init script, so we have to make one and start it:

cat <<EOF >/etc/init.d/udev
#!/bin/sh /etc/rc.common
START=38

start() {
    /sbin/udevd --daemon
    /sbin/udevadm trigger
    /sbin/udevadm settle
}
EOF
chmod +x /etc/init.d/udev
/etc/init.d/udev enable
/etc/init.d/udev start

Finally, enable and start mochad:

/etc/init.d/mochad enable
/etc/init.d/mochad start