Skip to content
Michael Hallock edited this page Jul 29, 2016 · 2 revisions

To use this library, add a reference to it and follow the examples set below. There is also a test application in the repository that can be referenced for the basics.

Always Dispose() the client, or use it in a "using" statement as below. You can subscribe to any of the following events.

  • ConfigUpdated - Published when the internal Config is updated
  • CurrentActivityUpdated - Published when the current Activity is updated
  • Error - Published on certain errors
  • MessageReceived - General debugging event published when a message is received from the Harmony Hub
  • MessageSent - General debugging event published when a message is sent to the Harmony Hub

The following is just an example. The actual names of your devices, control groups, functions, etc. will differ, and the only way to really find the right names is to examine the Config object you get from the Harmony Hub.

using (var client = new HarmonyHub.Client(ip, username, password))
{
    // Setup event handlers
    client.MessageSent += (o, e) => { Console.WriteLine(e.Message); };
    client.MessageReceived += (o, e) => { Console.WriteLine(e.Message); };
    client.ConfigUpdated += (o, e) => {
        /* 
         * Once the config has been loaded from the Harmony, it contains all of the available "activities",
         * "devices", and "sequences" that can be used through this library. Devices are nice enough to 
         * expose "controlGroups", like "Volume" or "Power", which expose "functions" like "VolumeUp", "VolumeDown", etc.
         * You can think of these "functions" as the buttons on your remote, which you "press" by sending a command.
         *
         * These "functions" will contains an "action" string which is a JSON object that is word-for-word sent to the
         * Harmony as the command to "press" it.
         *
         * Obviously, this can be simplified, an is just an example of how to walk the Config tree.
         */
        var pvr = client.Config.Device.FirstOrDefault(x => x.Label == "Pace DVR");
        var channelControlGroup = pvr.ControlGroup.FirstOrDefault(x => x.Name == "Channel");
        var channelUpFunction = channelControlGroup.Function.FirstOrDefault(x => x.Name == "ChannelUp");
        var channelUpAction = channelUpFunction.Action

        // The actual command is sent to 
        client.SendCommand(channelUpAction);
    };

    client.Connect();

    /*
     * Requests that the Harmony Hub send its current configuration. There is no guarentee that when this call returns,
     * the Config object will be available / updated. In fact, its more of a guarentee that it WON'T be available immediately.
     * Subscribe to the ConfigUpdated event, as above.
     */
    client.RequestConfig();

    /*
     * Requests that the Harmony Hub send the current active Activity. This is basically the only real "state" that the
     * Harmony Hub has. This call is dependent on the Config object being populated, as the Harmony Hub only sends back 
     * an ID that needs to be looked up in the Config to get the actual Name of the activity, etc.
     *
     * As such, given the above warning about the config object not being populated immediately after the RequestConfig() call,
     * if you actually try this example it will fail. This call is more appropriate (a) in a ConfigUpdated event handler, 
     * (b) Made from a caller that already has verified that the Config object is present.
     */
    client.RequestCurrentActivity();
}

Open questions

  • Need to figure out what messages from the Hub look like when they are triggered by other means
Clone this wiki locally