Audio/visual implementation and/or iRule replacement, using openHAB

With the discontinuation of iRule Builder (end of 2020) I’ve been looking for a solution to replace all my television and home theater iRule screens that I’ve built over the years for my iPad.

At first I used openHAB to build an interface on my mobile device to control my audio/visual (A/V) equipment as I was already using openHAB with the GlobalCache binding and the Google Assistant integration. (e.g., “Hey Google, turn on my Home Theater”) But compared to iRule, the ability to create visually appealing screens with the appropriate control symbols was difficult (if not impossible) with openHAB.

Recently I solved this problem by reversing my thinking. I abandoned the idea of installing the solution on a mobile device and instead purchased a highly customizable remote control (Logitech Harmony Elite and hub) that could integrate with openHAB. My reasoning was as follows:

  • Logitech maintains a library of I/R commands for over 270,000 devices, including A/V equipment, lights, locks, thermostats, sensors, etc. And if the device is not in their library the Harmony remote can learn the I/R codes from the device’s native remote control. There is also support for some RF devices.
  • The Harmony hub retains all the device definitions and applicable I/R codes for my setup, eliminating the requirement to map these codes in openHAB.
  • As with iRule, within the Harmony hub you can create the equivalent of macros with power on/off rules for each device, startup and shutdown sequences with time delays, change button assignments, create custom activities that can be launched from the remote’s touchscreen, etc.
  • A remote control is a familiar object that is easy to operate and is not intimidating to less “techie” family members.
  • The openHAB HarmonyHub binding by Dan Cunningham integrates the Harmony remote control with openHAB.

My solution:

  • Configure the Harmony remote and hub to control all my A/V devices.
  • Create “Activities” in the Harmony remote. (e.g., “Watch TV”, “Watch Apple TV”, “Play CD”, etc.)
  • Configure 2-way communication between openHAB and the Harmony remote, as follows:
    1. openHAB --> Harmony: openHAB executes a Harmony activity or set of Harmony I/R commands on Harmony configured A/V devices.
    2. Harmony – >openHAB: Harmony remote executes rules in openHAB.
    3. GoogleAssistant --> openHAB --> Harmony: for example, “Hey Google, turn on television” executes “Watch TV” through openHAB on the Harmony remote.

openHAB configuration using PaperUI:

  • Install the HarmonyHub binding.
  • Configure my “Harmony hub” thing, for example:
  • Configure my “AppleTV” device thing, for example:
  • Create an items file with a channel to the hub, channels to the devices and a switch to be used by a rule that can be activated by Google Assistant:

Example items file:

String LogiActivity_FR            "Activity"   (gMain) { channel="harmonyhub:hub:FamilyroomHub:currentActivity" }
String LogiSendCommand_FR_Apple   "Apple Button Press" (gMain) { channel="harmonyhub:device:FamilyroomHub:58284365:buttonPress" }

/* Rule switch item - Familyroom AV */
Switch Rule_FamRoom_AV   "Television"	["Lighting"]

Create a rule which can be executed by Google Assistant --> openHAB or by an openHAB sitemap to activate my “Watch TV” activity on my Harmony hub:

rule "Start Family Room A/V" 
	Item Rule_FamRoom_AV received command
	if(receivedCommand==ON) { 
        logInfo("Harmony", "rule Start Family Room A/V - ON")
	    sendCommand(LogiActivity_FR, "Watch TV")

If desired, create two rules to trigger when an activity “starts” and “completes” on my Harmony remote (these rules will also trigger when openHAB initiates this command on the Harmony hub):

rule "Starting TV"
    Channel "harmonyhub:hub:FamilyroomHub:activityStarting" triggered Watch_TV
    logInfo("Harmony", "Familyroom TV is starting...")

rule "TV started"
    Channel "harmonyhub:hub:FamilyroomHub:activityStarted" triggered Watch_TV
    logInfo("Harmony", "Familyroom TV has started")

Create a sitemap to send commands to the Harmony hub:

sitemap Logitech_Family label="Main Menu" {
        Frame  {
                Switch item=LogiActivity_FR mappings=["PowerOff"="Off", "Watch TV"="TV", "Watch WDTV"="WDTV", "Watch Apple TV"="Apple TV"]
                /* Switch to activate 4 activities defined in the Harmony hub */

                Switch item=LogiSendCommand_FR_Apple mappings=["DirectionLeft"="Left","DirectionRight"="Right","DirectionUp"="Up","DirectionDown"="Down"]
                /*  Switch to test sending directional commands to my Apple TV device*/

                Switch item=Rule_FamRoom_AV label="Turn on Familyroom AV"
                /* Switch to execute the "Start Family Room A/V" rule */

openHAB Notes:

  • Install the Harmony binding in PaperUI.
  • Once your Harmony hub is set up it will auto-discover and show in your PaperUI inbox. Add it as a new “thing”. (e.g., harmonyhub:hub:FamilyroomHub)
  • Any devices connected to your Harmony hub will also auto-discover in your PaperUI inbox and you can add these as “things”. (e.g. harmonyhub:device:FamilyroomHub:58284365) In paperUI/configuration/things/ turn the thing’s buttonPress channel on.
  • Configure your items, rules and sitemap files as shown in the examples above.
  • To determine the syntax for the “activities” and the device I/R commands type: in your browser and search on “harmony” to find all the entries for your hub(s) (e.g., “PowerOff” or “Watch TV”) and device(s) (e.g., “DirectionLeft” or “DirectionRight”) as used in my rules example above. Note that as you add device “things” in PaperUI channel-types will be updated, but as you add additional activities they will not. However, you can remove the hub thing in PaperUI and re-add it, and the activities will now be refreshed in the channel-types file. (It is not actually necessary to do this if you know the syntax as the binding appears to pass the command through regardless and doesn’t check the validity in the channel-types file.)
  • Activities such as “Watch TV” become “Watch_TV” in a channel, as shown in the rules example above.
  • Activities defined in the Harmony hub can be executed by openHAB through the Harmony hub and vice versa openHAB can “see” activities that were executed by the Harmony remote.
  • Device I/R commands can be executed by openHAB through the Harmony hub but openHAB cannot “see” device IR commands executed by the Harmony remote.

Harmony Notes:

  • The Harmony documentation is poor, and to make things worse there are three methods to configure the hub and remote: on the remote, through the Harmony mobile app downloaded onto your IOS or Android device, and through the Harmony program downloaded to your desktop computer. Unfortunately some configuration procedures are not possible (or very difficult to find) in differing two out of the three methods. Consequently you often need to Google-search things you are trying to achieve. Therefore, pay particular attention to which method the solution applies to. Ultimately you will likely be using all three methods to achieve your desired results. Here’s a summary from Harmony that somewhat clarifies the situation:

  • It wasn’t obvious to me that Harmony treats the configurations of a device and of an activity separately. So for example if you change the function of a menu button in the television device, you likely need to also change this function in the “Watch TV” activity. Harmony has configured it this way because when you are in device mode every button on the keypad is associated with the selected device, but when you are in activity mode different buttons are associated with different devices (e.g., sound related buttons are associated to your amplifier, play/rewind/stop buttons are associated with your media player, source buttons are associated with your television, etc.)
  • Harmony allows you to configure whether the IR signal comes from the remote itself, the hub, mini-blasters or any combination of the three (mobile app/Harmony setup/edit devices/remote & hub/IR assignments). You can also special order from Logitech a wiring harness that plugs into one of the two jacks in the hub, with 4 stick-on IR emitters. (i.e., a maximum of two harnesses / 8 emitters per hub).
  • You can run macros to execute a series of commands (mobile app/Harmony setup/add-edit devices & activities/activities/choose activity/edit start - or end - sequence).
  • You can assign device short-press and long-press button commands to non-assigned buttons druing an activity (mobile app/Harmony setup/add-edit devices&activities/activities/choose activity/customize remote).
  • You can change already defined short-press and long-press button commands (mobile app/Harmony setup/add-edit devices&activities/remote & hub/Harmony Elite/activity - or device - control buttons/). Remember you likely need to change the button in both the device configuration and any activities that use this device.
  • You can change power on/off settings for each device (mobile app/Harmony setup/add-edit devices&activities/devices/power settings). If devices are turning off when you switch from one activity to another, change the power setting for that device to “Keep device always on but switch off when off button is pressed”.
  • You can change the order the activities show in the remote’s screen while in activity mode (mobile app/edit-reset/reorder activities) and the order the devices show in the remote’s screen while in device mode (mobile app/edit-reset/reorder devices)

As mentioned above, openHAB cannot detect when a device button is pressed. It can only detect when an activity on the remote’s screen is selected. One solution to this dilemma is to create an activity that triggers the require function. In my case I have an RF controlled TV lift cabinet that raises and lowers the TV. This cannot be controlled by Harmony. In my “easy” solution, I created several Harmony activities “Raise TV” and “Lower TV” and these trigger openHAB rules to perform those functions using a GlobalCache relay hardware device. If you have such a requirement and are happy with this solution then you can stop reading now. If you have this requirement and are interested in my second (albeit elaborate!) solution, keep reading.

Lutron Integration with Harmony, using openHAB:

The Harmony hub supports integration with some “Home Control” devices such as Philips Hue, Honeywell, Ecobee, Insteon, Lutron, etc. Home Control devices can be assigned to the bottom left and right two buttons on the remote, as well as in some cases the up/down rocker switch. Rather than using the “easy” solution as described in the above paragraph, I wanted to use the bottom two left buttons on the remote to trigger the TV cabinet to move up and down. There are no doubt multiple ways of doing this, but I used openHAB’s Lutron Smart Bridge Pro binding, as developed by Allan Tong.

My solution:

  • Configure the Harmony remote to turn on and off a lamp device, as configured in the Lutron bridge.
  • Configure a dimmer “thing” in openHAB using the Lutron binding to register the state of the lamp device. (i.e., 0 to 100)
  • When the dimmer == 0 (OFF) then have openHAB lower the TV cabinet and when the dimmer >= 1 (ON) raise the TV cabinet to the preset height.

openHAB configuration using PaperUI:

  • Install the Lutron binding.
  • There is no auto-discover for this binding, so create a things file with a bridge thing and a dimmer thing.
  • Create an items file with a dimmer switch.
  • Create a rules file that monitors changes in the dimmer switch and executes commands to raise and lower the TV cabinet.

Example things file:

/* username and password defaults are "lutron" and "integration" */

lutron:ipbridge:SmartBridgePro "Lutron SmartBridgePro" [ ipAddress="", user="lutron", password="integration" ]

lutron:dimmer:LutronID3 "TV Cabinet Down" (lutron:ipbridge:SmartBridgePro) [ integrationId=3 ]
lutron:dimmer:LutronID4 "TV Cabinet Up" (lutron:ipbridge:SmartBridgePro) [ integrationId=4 ]

Example items file:

Dimmer TVCabDown   { channel="lutron:dimmer:LutronID3:lightlevel" }
Dimmer TVCabUp     { channel="lutron:dimmer:LutronID4:lightlevel" }

Example rules file:

rule "TV CabDown - changed"
	Item TVCabDown changed
    logInfo("Lutron", "TV Cabinet Down changed to:  " + TVCabDown.state)
    if (TVCabDown.state > 0.5) {      /* ON command = 1 to 100 */
        logInfo("CMC_Lutron", "TV Cabinet - Down")
    	/* execute down commands */
     postUpdate(TVCabDown, 0.5)   /* set to 0.5 to ensure a repetitive press of down is seen as a change and is executed each time */

Lutron notes:

  • Be sure to buy a Lutron Caseta SmartBridge Pro (emphasis on “Pro”) as only this Lutron bridge is accessible using Telnet and this is how the openHAB binding communicates with the Lutron bridge.
  • You will need to beg, borrow or purchase one or more Lutron Caseta devices (e.g., lamp dimmer or dimmer switch) to enroll in the bridge. After this is enrolled you don’t actually need the device as we’re only using it virtually. (There doesn’t seem to be a way to create a device using only Telnet commands.) The Harmony remote will turn the Lutron “virtual” switch on/off, Lutron will report to openHAB the status of this virtual switch and using a rule, openHAB will execute commands. Note it’s easier to use a lamp dimmer as you only need to plug it into an electrical outlet, versus a dimmer switch that needs to be hardwired as a replacement to an existing wall switch and then removed after enrollment in the bridge.
  • On the Lutron app (IOS or Android) select “settings/advanced/integration/telnet support” and turn Telnet support ON.
  • Select “settings/advanced/integration/send integration report” and page down to the bottom to find the ID number(s) of the device(s) you wish to monitor. The ID number(s) are required for the integrationID parameter in the dimmer thing configuration, as shown in the example above.

Harmony notes:

  • Add the Lutron Caseta SmartBridge Pro to the Harmony hub (mobile app/Harmony setup/add-edit devices & activities/devices/add device/home control). The setup routine will required you to login to the Lutron bridge using your personal Lutron app id and password, which will grant the Harmony app access to the Lutron bridge. The app will auto-find any devices currently connected to the Lutron bridge.
  • You can assign the Lutron device(s) to any of the four home control buttons at the bottom of the Harmony remote as short-press and long-press actions (mobile app/Harmony setup/add-edit devices & activities/remote&hub/Harmony elite/home control buttons/). FYI, Harmony hard codes the short-press as ON and the long-press as OFF. (i.e., you can’t define the long-press as one device and the short-press as a different device.)

Happy remote controlling !!


I’m just curious which OH UIs you tried to use and if you have any suggestions for improvements. I can’t promise that anything will change but we can’t do anything with just this statement.

Thanks for posting the tutorial!

For example, how would I create this iRule screen in openHAB:

I don’t deserve anything there that HABPanal can’t do.

Keep in mind that OH is designed for the general home automation, not audio/video automation. And it’s designed for automation, not remote control.

You have probably found the optimum solution for your needs, but HABPanal would have probably gotten you where you needed to go.