HomeSeerToy in C#
homeseer .net c#

HomeSeerToy in C#

I felt the need to control my lights with the media-player remote-control I had available. I assumed it would be easy to quickly build a C# console application which I could easily start from within EventGhost.

The application was finished rather fast, EventGhost was quickly configured, yet the result was not behaving fast enough to my taste. EventGhost needed to start the external console application, which connects to HomeSeer and triggers an event. The delay was too annoying. I decided to make a bit harder: let’s build a plugin for EventGhost, which connects to HomeSeer. Some of the C# quotes however, I decided to share:

Requisites:

References to Scheduler.dll and HomeSeer2.dll should reveal the necessary classes and namespaces to control HomeSeer.

private static HomeSeer2.application hsapp = new HomeSeer2.application();
private static Scheduler.hsapplication hs = new Scheduler.hsapplication();

Connect to HomeSeer, I assume the port is actually optional:

hsapp.SetHost(args[0] + ":" + args[1]);
hsapp.Connect(args[2],  args[3]);
hs = hsapp.GetHSRef();

Detailed device information is available via the device code as parameter.

int deviceRef = hs.GetDeviceRef(args[4]);
DeviceClass device = hs.GetDeviceByRef(deviceRef);

Console.WriteLine("Sending command " + args[5] + " to device " + device.Name);

Sending a command isn’t hard either. I did notice the command parameter to be case sensitive: “On” seem to work, “on” did not.

if (hs.IsOn(args[4]))
{
     Console.WriteLine("Device is currently On, switching Off");
     hs.ExecX10(args[4], "Off", 0, 0, false);
}
else
{
     Console.WriteLine("Device is currently Off, switching On");
     hs.ExecX10(args[4], "On", 0, 0, false);
}

References: