Harmony Hub

Continuing the discussion from Harmony Hub:

I plan to follow these directions, where does Phil’s script deviate from this plan? Need a bit more time to digest what you are all doing!

Hey @Dracoy

So my script is very similar to what these guys have done. From my understanding, here’s where it is different.

  • In the other solution,MQTT is used. As your Harmony Hub updates what activity is selected, the NodeJS library will see the change, and push an update over MQTT.
  • When you press a switch in Home Assistant, a message will be pushed via MQTT which the NodeJS library will read, and then forward the command to your Harmony Hub.

My approach removes MQTT from the picture. This has pros and cons

Pros

  • I don’t need a MQTT server running
  • I use OwnTracks, with a cloud MQTT provider. This means to turn my Harmony Hub on, a command doesn’t need to go out to the internet and back first. I also don’t need to worry about “bridging” brokers or anything like that.
  • I can use REST Switches, which are built into Home Assistant. I don’t need to use scripts to send MQTT messages.

Cons

  • For every activity I have, Home Assistant will poll my network every 30 seconds. For three activities, my Harmony Hub is pinged 6 times per minute, 24/7.
  • The way the switches work in Home Assistant sometimes isn’t smooth, or I have to press the activity multiple times before the Harmony Hub will register. Not sure if this is a problem with the Harmony API in general, or the Node JS library I’m using.

Thanks! That is an interesting perspective. If CloudMQTT is not used, in theory it should be faster since it is all local correct?

In theory, yes, but it would depend on your network. I’m using an mqtt solution and for me it’s near instantaneous.

Harmony hub came today. It’s awesome! Time to play around with it!

CloudMQTT and Harmony works like a chart. TIme to setup the CRON script

  • Did you end up using this one?

@reboot sleep 60 && sudo /home/pi/harmony-api-master/script/server

I’ll tell you one thing, for weeks you’ll still be aiming the remote at the TV or Amp even though you know damn well it’s bluetooth! BTW, if you have FireTV, it works really well as a replacement remote, truly one remote solution.

I’ve had to call an electrician for the Wink Relay; I got power to it, but it wasn’t switching the light so it may have to be rewired; it’s an old house from the forties. Kinda bummed, but I’m going to have him add an outlet and test him out since I plan on a kitchen reno and need a good electrician.[quote=“Dracoy, post:46, topic:978”]
Did you end up using this one?

@reboot sleep 60 && sudo /home/pi/harmony-api-master/script/server
[/quote]

Yeah, that worked fine for me. At some point I may move it over to a service though. So far I haven’t had any issues though.

Oh wow! You got the wink relay too. You need to let me know how it works if you set it up nicely. The intercom feature looks fun.

What does your HA switch file look like now? Curious if you did something similar with @danichispa.

That’s exactly what I did. And I use the group switch to fire lighting automations. I’ve been having a lot of fun with Alexa lately. I’ve gotten into the Alexa component and custom intents and it’s really making the echo more useful to me. I like being able to ask her whether the door in locked - which is extra useful since I finally got my Echo Dot for the bedroom (ordered it in like April or March)!

Thanks for all the advice man. This was definitely a great addition to HA! I’ll have to customize around with it more later but it all works and is tested!

It’s beautiful! Great Wednesday!

And the journey continues!

1 Like

HI, i have a problem getting harmony-api and mosquitto to work together. I have mosquitto installed with username and password. Home assistant loads the broker, also have the api webpage working at ip:8282, when i click on the switches on hass nothing happens. Logger doesn’t show any errors. I tried different settings on app.js and only one is working is the default one.

Hi All, Need some help with this one. Followed the directions via @rpitera and @beanian and I seem to have the API running (I am seeing the scrolling list of “updating activities & updating state” on the command terminal I ran sudo script/server on. However, like some other people I am not seeing any communication between the Harmony & the MQTT (Mosquitto). I know that I am missing something, so I hope someone can help/answer my questions.

  1. What is the webpage IP for the Harmony API? I never saw any reference to what the address is in the README and I have tried the several different address, including the IP of the Harmony Hub:8282

  2. I edited the app.js file per @beanian, below is exactly what it currently looks like:

var mqttClient = mqtt.connect('mqtt://127.0.0.1',{protocolId: 'MQIsdp', protocolVersion: 3 }); var TOPIC_NAMESPACE = "harmony-api"
I also have the config.json file as the default with the 127.0.0.1. Is that correct, or am I supposed to insert my own MQTT broker address (i.e. 192...)

Thank you advance, as this is my last big hurdle to getting HA to meet all my needs (at the moment haha)!

Although I’m using REST switches for mine, I’m pretty sure you need to change the mqtt.connect to use the IP address of your Broker, unless you’re running your MQTT broker on the same machine.

@philhawthorne I am running my broker on the same machine, however I did try and change the 127.0.0.1 to the ip on my broker (192...), but it still doesn’t seem to be working.

I did manage to find the webpage for the Harmony API via the html file under harmony-api/public. A new question is that when I try either of the “Info” requests, I am met with an error message saying the directories do not exist. Similarly, I am unable to even click on either of the “Control” options. I went searching for the logs file, but I was unable to even find a logs file, as I have no Production directory as mentioned on the git page.

Any ideas on what could be wrong? The install seemed to go off without a hitch (although I did get an warning about updating minimatch to 3.0.2 or higher). And the server seems to be running, so I am not sure what I am missing. Thanks!

hmm I’m not sure. Sounds like something isn’t right.

You mentioned before that you can see things coming through on the terminal. I’m wondering if you’re running in development mode and not production.

Harmony API logs all of its requests. In production, it logs to a file at log/logs.log.
In development mode, it just logs to stdout.

To look at any errors, you might need to take a look at the terminal as you make the requests to see if any errors are reported there.

Hmm no errors on the terminal. It is continually responding with “Updating State” and “Updating Activities”. How can I tell if I am in Production mode or Development mode, as both are started via sudo script/server?

The only difference between the two is that dev mode is when you are running it in a terminal session that you have open at the time. Once you close the terminal, the server stops.

With “production” mode, you’ve started it via a service or cron job at boot time. You don’t see the live updates in your terminal screen and if you close your terminal session the server still runs.

Do you see any communication on your MQTT side? I don’t use Mosquito or the embedded MQTT so I’m not sure how you’d view this, but in my install using CloudMQTT I go to the Websockets UI and I can see state messages being published. This is the first thing I would check out. If you’re not seeing state messages, then it’s not communicating and won’t do anything.

Thanks @rpitera, that is helpful information on the difference between Production & Development. It would seem that I have been running in Development mode then, as I haven’t done cron or run Forever as a service yet. Although, I wouldn’t think that that should be affecting the communication between the API and MQTT.

It is very possible that I am troubleshooting this wrong, but the way I am testing it is to subscribe to either the activities or state topic in another command terminal, separate from the command terminal running the server. When I subscribe, I receive both CONNACK & SUBACK, so I believe that I am set up properly on that end. However, I never see any activity/state messages on the Subscription terminal (only the ping requests). I have tried changing both States/Activities via the Harmony app to see if it updates, but I never see any messages.

Currently, my config.json looks like the following:

{ "mqtt_host": "http://192.***.*.**" }

and my app.js like the following:

var mqttClient = mqtt.connect(config.mqtt_host, {username: 'username', password: 'password', port: 1883}); var TOPIC_NAMESPACE = "harmony-api"

I am running Mosquitto on my RPi3 (same machine as HA & the Harmony API) with no username & pw.

I know I am missing something, just don’t know what. Thanks for your help and sorry for the long post!

No apologies necessary! I think that is the problem then - if you’re not seeing any state messages when your server is running, then it isn’t connected to the MQTT server. As soon as I started my testing in dev mode, I could see state messages immediately on the CloudMQTT WebsocketsUI panel. Again, I am not using Mosquitto, but maybe you need to run it with a username and password set up for the harmony and allow it the proper access. I had to set up a harmony user on CloudMQTT and allow it read and write as well as set a multi level wildcard ACL.

Thanks @rpitera, when you edited the app.js file, what code did you place in the var mqttClient?

Also, am I correct in understanding the Harmony-API usage, in that if I update the State or Activity in the actual Harmony app, that the Harmony-API would then update the status via MQTT? Meaning, if I power on my TV via the Harmony app, then I should see an update message on the command terminal with the MQTT subscription.