Skip to content

Controlling Harmony Hub using Python scripting

Joe Keenan edited this page Jan 29, 2021 · 2 revisions

Scripting the Harmony Hub plugin is a little complicated, because the arguments to the action methods all depend on the actual devices you have the hub configured to control. I'll give an example based on a user's configuration that was sent to me.

There's a menu command to print the "Formatted Hub Config" to the log. You need that to get the actual names of the commands to send. Execute that menu command, then look in the log output for the device you want to control. Here's an example:

 Device: Fireplace, id: 73501101, type: ClimateControl, Manufacturer: Classic Flame, Model: 26II042FGL
     Control Group Home:
         Function PowerToggle: label = 'Power Toggle', action: {"command":"PowerToggle","type":"IRCommand","deviceId":"73501101"}
     Control Group Miscellaneous:
         Function Flame: label = 'Flame', action: {"command":"Flame","type":"IRCommand","deviceId":"73501101"}
         Function FlameIntensity: label = 'FlameIntensity', action: {"command":"FlameIntensity","type":"IRCommand","deviceId":"73501101"}
         Function FlameSpeed: label = 'FlameSpeed', action: {"command":"FlameSpeed","type":"IRCommand","deviceId":"73501101"}
         Function Heater: label = 'Heater', action: {"command":"Heater","type":"IRCommand","deviceId":"73501101"}
         Function Light: label = 'Light', action: {"command":"Light","type":"IRCommand","deviceId":"73501101"}
         Function TempDown: label = 'TempDown', action: {"command":"TempDown","type":"IRCommand","deviceId":"73501101"}
         Function TempUp: label = 'TempUp', action: {"command":"TempUp","type":"IRCommand","deviceId":"73501101"}
         Function Timer: label = 'Timer', action: {"command":"Timer","type":"IRCommand","deviceId":"73501101"}`

You'll need the 'id' from the Device line, then the control group name ('Home') and the Function name ('PowerToggle').

The action for the plugin is defined in Actions.xml like this:

     <Action id="sendDeviceCommand" deviceFilter="self.harmonyHub">
         <Name>Send Device Specific Command</Name>
         <CallbackMethod>sendDeviceCommand</CallbackMethod>
         <ConfigUI>
             <Field id="device" type="menu">
                 <Label>Device:</Label>
                 <List class="self" filter="" method="deviceListGenerator"/>
                 <CallbackMethod>menuChanged</CallbackMethod>
             </Field>
             <Field id="group" type="menu">
                 <Label>Command Group:</Label>
                 <List class="self" filter="" method="commandGroupListGenerator" dynamicReload="true"/>
                 <CallbackMethod>menuChanged</CallbackMethod>
             </Field>
             <Field id="command" type="menu">
                 <Label>Command:</Label>
                 <List class="self" filter="" method="commandListGenerator"  dynamicReload="true"/>
             </Field>
         </ConfigUI>
     </Action>

The important bits are the various 'id' fields in the ConfigUI section ('device', 'group', and 'command'), and the CallbackMethod ('sendDeviceCommand'). You plug those into this Python code:

props = {   
    'device': '73501101', 
    'group': 'Home', 
    'command': 'PowerToggle'
}

harmonyPlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.harmonyhub")
if harmonyPlugin.isEnabled():
    harmonyPlugin.executeAction("sendDeviceCommand", deviceId=12345678, props=props)
Clone this wiki locally