Stream Deck: Integrating Harmony Hub

Stream Deck: Integrating Harmony Hub

The latest batch file "integration" I've gotten up and running for the Elgato Stream Deck is my Logitech Harmony Hub. The Harmony Hub allows for Home Entertainment (TV / Home Audio / Media Player) automation. While most Harmony remotes are fancy, touchscreen learning IR remotes, the Harmony Hub is a network device that centralizes home entertainment and wraps it in a nice API for us to interface with. As with my previous Philips Hue integration, I'm using batch files running node.js scripts to achieve control of the Harmony Hub.

Step 1.) Install Node.js

First things first, if you haven't already installed node.js, download the latest "recommended for most users" release of node.js here: https://nodejs.org/ and follow their instructions to install.

Step 2.) Install Git for Windows

Some of the harmonyhub client packages will try to use git to download components, so you will need to have git available on your system. If you have not already installed Git, you can download and install Git for Windows from: https://git-for-windows.github.io/

Step 3.) Install npm packages & harmonyHubCli

Now you'll need to install some node packages and scripts to provide our interface to the Harmony Hub. The code we are installing is from these 4 git repositories:

To install these packages enter the following commands via the command line to download and install packages using npm.

  • npm install harmonyhubjs-client --save
  • npm install harmonyhubjs-discover --save
  • npm install harmony-hub-util --save

The last script we'll need is the command line interface wrapper, which you'll need to download manually and store somewhere. I saved it to a "harmony" folder under the scripts folder where I've been storing my batch files for the Stream Deck. Download the CLI wrapper from https://github.com/sushilks/harmonyHubCLI/raw/master/harmonyHubCli.js.

Step 4.) Testing it out and Identifying Commands

To test that harmonyHubCli is ready to run, open a command window from the folder you stored harmonyHubCli.js in and enter: node harmonyHubCli.js -r activities. The script will search for Harmony Hubs on your network and return the IP and then a list of actions available via that Harmony Hub. For future commands we'll use the IP returned here directly so that this search step doesn't have to repeat.
To list individual devices on associated with your Harmony Hub, enter: node harmonyHubCli.js -l YOUR_HARMONY_HUB_IP_HERE -r devices
Example of List of devices To list commands we can send to any given device, enter: node harmonyHubCli.js -l YOUR_HARMONY_HUB_IP_HERE -d "YOUR_DEVICE_NAME_HERE" -r commands
Example of List of commands To send one of these commands to the device, enter: node harmonyHubCli.js -l YOUR_HARMONY_HUB_IP_HERE -d "YOUR_DEVICE_NAME_HERE" -c "YOUR_COMMAND_NAME_HERE"
Example of Sending a Command to a Device

You can also trigger commands against activities and chain together multiple commands at once. Full details about what harmonyHubCli can do are at: https://github.com/sushilks/harmonyHubCLI.

Step 5.) Batch Files and Buttons

Now that we have Harmony interacting properly with the command line, we can wrap up some simple commands in batch files and tie them to "Open" buttons on the Stream Deck. First we'll create a plain text file called MuteTv.bat in the same directory where we stored harmonyHubCli.js. Editing this file, we'll use the IP and an appropriate device name from our testing in Step 4 to craft a mute button. My hub IP is 192.168.1.160, my device name is Sharp TV and my command name is Mute, so my batch file command will be: node C:\nircmd\scripts\harmony\harmonyHubCli.js -l 192.168.1.160 -d "Sharp TV" -c "Mute". I've also fully qualified the path to harmonyHubCli.js, because we will invoke via nircmd to suppress the command window, the path will get obfuscated and needs to be fully qualified here.

Lastly, from the Stream Deck software, create a new "Open" type button form the "System" button category and point the App / File field at your batch file. You'll need to make sure you have nircmd (http://www.nirsoft.net/utils/nircmd.html) and prepend your call to your batch file with nircmd exec hide to prevent the command window from showing (as of Stream Deck 1.1.2). For more details see my previous Stream Deck integration. On my system, my finished button command looks like C:\nircmd\nircmd.exe exec hide C:\nircmd\scripts\harmony\MuteTv.bat. Your mute button should now be working properly. You can mine out other devices or activities you want to control and wire them up similarly.

Related Article