FluentDwelling

Have you ever wanted to control your lights and appliances from a computer program? While technology like X10, and more recently Insteon, have given us the hardware we’ve needed to accomplish that, we found the programming interfaces lacking. That’s why we developed FluentDwelling.

What is FluentDwelling?

FluentDwelling is a free and open source .NET class library for controlling Insteon-compatible home automation devices using the SmartHome 2413S serial-to-Insteon or 2413U USB-to-Insteon bridges. The fluent API is designed to be particularly easy to use:

var powerlineModem = new Plm("COM4");

DeviceBase device;
if(powerlineModem.Network
    .TryConnectToDevice("55.55.55", out device))
{
    // support auto-discovery of device type:
    if(device is LightingControl)
    {
        var lightingControl = device as LightingControl;
        lightingControl.TurnOn();
    }
    else if(device is IrrigationControl)
    {
        var irrigationControl = device as IrrigationControl;
        irrigationControl.TurnOnSprinklerValve(3);
    }
}

It’s even backwards compatible with the older X10 technology:

// turn on the X10 device at address A2:
powerlineModem.Network.X10
    .House("A")
    .Unit(2)
    .Command(X10Command.On);

Requirements

(We’re already assuming you’re a .NET programmer.) To use FluentDwelling, you need to have a 2413U (USB) or 2413S (serial) device:

The USB model is cheaper, more easily available, and more convenient. However, the USB device is actually a serial device with a USB to serial chip built-in. In order to use the USB version with FluentDwelling, you have to install the FTDI chip virtual com port (VCP) driver. (Instructions for doing this should be included with the 2413U). When it installs, it will create a new “virtual” serial port on your computer. Make a note of what that is, because you need to connect to the device using this address in your program.

The 2413U or S device allows your PC to send and receive Insteon messages using the Insteon protocol (as well as legacy X10 messages). It’s a “dual band” device so it sends these messages both over the power-line to other devices that are connected to your electrical system, as well as wirelessly.

Device Discovery

Normally, you “link” all of your Insteon-compatible devices to a controller. In this case, the controller is the 2413. You do this by plugging both devices into their outlets, holding down the button on the side of the 2413, waiting for it to beep, then holding down the button on the side of the device you want to control. It should also beep. Once you’ve done this, they are “paired”, and the 2413 keeps a list of all the paired devices in a database, which you can access with FluentDwelling:

var database = powerlineModem.GetAllLinkDatabase();
foreach (var record in database.Records)
{
    // You can attempt to connect to each device
    // to figure out what it is:
    DeviceBase device;
    if(powerlineModem.Network
        .TryConnectToDevice(record.DeviceId, out device))
    {
        // It responded.  You can get identification info like this:
        string category = device.DeviceCategory;
        string subcategory = device.DeviceSubcategory;
        // ...and use the concrete object type to determine capabilities:
        if(device is DimmableLightingControl)
        {
            // command it to turn on slowly to light level 50%:
            ((DimmableLightingControl)device).RampOn(128);
        }
    }
    else
    {
        // couldn't connect - device may have been removed?
    }
}

Receiving Messages

The 2413 can also notify you of incoming events. In order for this to work, you need to call the .Receive() method at regular intervals. The best way to do this, if you’re using WPF, is with a DispatcherTimer:

// Setup a timer on the GUI thread to call the Receive loop
var timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 100); // milliseconds
timer.Tick += new EventHandler((s, args) =>
    {
        powerlineModem.Receive();
    });
timer.Start();

If you’re using WinForms, you should use a regular Windows Forms timer instead of DispatcherTimer. Now you can receive events:

powerlineModem.SetButton.Tapped += new EventHandler((s, e) =>
    {
        MessageBox.Show("PLM SET Button Tapped.");
    });

powerlineModem.SetButton.PressedAndHeld += new EventHandler((s, e) =>
    {
        MessageBox.Show("PLM SET Button Pressed and Held.");
    });

powerlineModem.Network.StandardMessageReceived 
    += new StandardMessageReceivedHandler((s, e) =>
    {
        MessageBox.Show("Received Command: " + e.Description 
            + ", from " + e.PeerId.ToString());
    });

powerlineModem.Network.X10.CommandReceived 
    += new X10CommandReceivedHandler((s, e) =>
    {
        MessageBox.Show("X10 Command Received: House Code " + e.HouseCode 
            + ", Command: " + e.Command.ToString());
    });

Controllable Devices

There are many Insteon-compatible devices. Right now, FluentDwelling supports all Lighting Devices (switched and dimmable), Irrigation Controls, Window Coverings, Pool and Spa Controls, and Sensor/Actuator devices.

Free

FluentDwelling is free, both free-as-in-speech and free-as-in-beer. The entire library (including unit tests and a small demo application) has been open-sourced and is available under the GPLv3 license. You can get the latest source code from our SVN repository or download the latest version (with source) as a zip file.

Testimonials

“The best open-source .NET Insteon Library available is FluentDwelling.”Robert Venables

Version History

FluentDwelling version 2013.07.09 – added 4 methods to SensorsActuators class so that it works with the I/O Linc 2450, thanks to Hugh Williams for the code

FluentDwelling version 2012.10.22 – added overloads for SendStandardCommandToAddress that return the raw response from the device

FluentDwelling version 2011.09.17 – added ability to receive messages from controllers

FluentDwelling version 2011.04.16 – initial release

Support

Please see our FluentDwelling Support Page.