Sending Harmony device commands from SmartThings using a separate Linux bridge device (technical)


(zraken) #1

I have my ST set up to control a Harmony Hub, also have Alexa hooked up to ST. What I want to accomplish is to control my TV with voice (via Alexa). I kind of have this working but it’s not perfect. Here’s my setup:
A virtual switch on ST called “TV Power”.
Two Activities on Harmony XXX & YYY to turn TV On and Off respectively.
One instance of ST Logitech Harmony Trigger App set to start Activity XXX on Harmony when “TV Power” is turned on.
Another instance of ST Logitech Harmony Trigger App set to start Activity YYY on Harmony when “TV Power” is turned off.
Now when I say “Alexa turn on TV Power” the TV comes on, the problem is that Harmony remembers state and only triggers an activity if it is not already in that state. So, if I happened to have turned on the TV manually and then say “Alexa turn off tv power” it won’t work because Harmony thinks the TV is already Off and so it does not need to start the YYY activity. Ideally I want to just send the “TV Off” discrete command from Harmony but the ST Logitech Trigger app only supports starting activities or a full power off.
Has anyone figured out a work around for this issue?

Harmony - Single Commands
Harmony - Single Commands
Harmony Elite Hub Power Off button and SmartThings
Setup SmartThings and Harmony Play/Pause/Stop Buttons For Lights using EventGhost on a Windows
(Joel Clark) #2

Definitely will be watching this thread. I got my Harmony Hub setup yesterday and linked to ST via SmartApp. Going to setup the virtual switches today so Alexa can control. Just clumsy needing all the activities to control on and off. Hopefully we will see further development of the SmartApp to build in these functions.


The power switch synchronization issue and three alternative solutions are discussed at length in the following project thread.

Although that particular project used IFTTT recipes instead of the smart things/harmony direct integration (because that integration was still in beta at the time), it’s still the same solution. It’s just that instead of using IFTTT recipes to send the activity command, you’ll be using the “harmony trigger” smartapp.

But the logic flow is all the same.

(zraken) #4

Even with all the jumping through hoops, the issue with “remembering states” keeps cropping up. In my case I also use a handheld remote which makes matters worse and throws off harmony’s activity states. Ultimately I just integrated smartthings with the logitech hub using HarmonyHubCLI. So, here’s my setup that is working great:

  1. Created a special momentary push button device type that will call a parent app’s push method when the button is pushed.
  2. Created an App on ST that will create child momentary push buttons. The device/commands to be issued to the harmony hub is encoded in the device-id of the buttons. The push method on this app will send the device/commands to a bridge app running on a linux machine.
  3. I modified the HarmonyHubCLI code to get its commands from a TCP port effectively bridging the ST App to harmony hub.
  4. Alexa is also set up to invoke the buttons.

Now when I say “Alexa turn on NBC TV”, HarmonyHubCLI will issue the PowerOn and chanel numbers to the TV. If I had changed the channel using the handheld remote and then speak the same voice command it will execute the command sequence again regardless of the Activity state (typically harmony will ignore if you are trying to enter the same activity).
Finally, to allow for Powering off the TV by saying “Alexa turn off television” I created a Push to Off momentary push button that is tied to sending a PowerOff command to the TV.
This was quite a bit of work but the final results are good without needing to use harmony activities.


You’ve done exactly what I’m trying to figure out! Everyone else seems to be using activity-based integrations, but I just want to have conditions issue commands to certain devices. Can you share your updated HarmonyHubCLI code?

Also, how did you have your ST app call the commands to a local address?



You may already know this, but this approach requires setting up your own separate server. That server is what will run the Node.JS libraries that are necessary to support the Command Level Interface (CLI) that is being discussed in this thread.

The SmartThings hub itself does not give us any way of loading our own libraries into it. We have to do everything through the smartthings account. We can add code in the form of device types or smartapps through the IDE. But that’s it.

So to use this direct integration, which is very cool, you need to have a separate machine set up to run that code and communicate with harmony. This is what @zraken is referring to with regard to a Linux bridge.

If you have the technical skills and interest in doing that, just follow the GitHub link up thread and you will eventually get to the libraries that you need along with the python Scripts.

But there isn’t any way to do this with only a SmartThings implementation.

Just adding this here for clarity, you may already know all of this, but I know people at many different technical skill levels are interested in echo/harmony interaction and may come across this thread and not be quite sure what we’re discussing. :sunglasses:

(zraken) #7

@JDRoberts thanks for adding the clarification. @mrgino I will upload my (rather hacky) changes to HarmonyHubLCI when I get home tonight.
If you don’t already have a machine running 24x7 that you can use for running the bridge, you can get a RaspberryPi set up to run the bridge code.
As for ST app communicating with local addresses, it all works on the LAN so there’s no issue with needing any port forwarding (if that’s what you were asking).


Thanks guys for the clarifications! I definitely did not know any of that :slight_smile: I am running a home media server that I could also host this on, so it’s worth a shot.

Just curious, why is ST able to call Harmony activities without an external server, but not Harmony devices? Is it just that Logitech hasn’t exposed the necessary libraries/api’s/etc to us?


Basically yes. The official ST/LAN integration is really very similar to harmony’s IFTTT channel.

(zraken) #10

Modified harmonyHubCLI.js, this is the entire file.
Modified executeActivityCommand function in file node_modules/harmony-hub-util/harmonyHubUtils.js. Replace just the function (this change allows for multiple commands to be sent in at a time for one device).
Couple more things, there’s an issue with the XMPP package just follow directions posted at github for fixing that. Also, fill in the correct IP addresses in the modified harmonyHubCLI.js.
The messages from ST APP should be of the format: Device:Command1,Command2 etc. for example: TV:PowerOn,InputHDMI1,VolumeUp
Of course you need to first dump the valid values from harmony for all of the device and command strings. Hope that helps (did I mention that this was all hacked without any consideration towards writing clean code:)

(Steve Bryan) #11

Thanks for all the info. I have installed harmonyhubcli on my RPi 3 which is working great from the command line. I’ve since applied the modified js files so my RPi is listening.
Is there a ST app that I can use to send the commands to the listening port on the RPi?

(J) #12

The HTTP Button Creator might be what you’re looking for.

(Steve Bryan) #13

Thanks crm114, that did the trick. To get it working I reverted the JS files back, installed Apache and written a CGI scripts to run the Harmony command. There is a good 5 - 6 second delay but I doubt that can be improved considering. It works, that’s the main thing. I’m using it to control my Satellite TV box to pause TV if the door bell rings.

Thanks again.

(J) #14

I’m sorry to hear about the delay. I’m getting near instant (< 1s) responses on my setup.


Im attempting to integrate keyboard shortcuts to control my entertainment center’s volume.

Ive installed the CLI and written two very simple batch scripts, one for the VolumeUp command and one for VolumeDown.

echo off
cd \SmartThings\A\node_modules\harmonyHubCLI
node harmonyHubCLI.js -l -d Amplifier -c VolumeUp

They both function perfectly if run nativly.

However when I attempt to assign the batch file as the program to launch for my macro keyboard (Black widow chroma) through raser synapse program, I get the message ’ node’ is not recognized as an internal or external command.

Any idea why when launched through the macro keyboard node is not recognized? Could it have something to do with the system variable?


Solution was to setup the keyboard macro software to run as admin