Harmony Hub

any updates on this?

1 Like

@emil-e any updates on your progress? I’m finding harmony-api by Maddox is a little to daunting for me. I think I could figure out the MQTT part, but I still can’t figure out how to install it in the first place. I managed to get the scripts over and executed bootstrap, but it requires forever and the command “sudo npm install forever -g” suggested by the script doesn’t work in Raspian. And pip can’t find forever to install it.

Still no progress on getting the harmony API to work. With some help I got it installed but can’t get it to start… :disappointed_relieved:

Finally got it running; turns out I needed to update my npm install, which I did by running the following command, twice:

sudo npm install npm -g

then I reinstalled the harmony-api using the command:

sudo script/bootstrap

I could instantly tell this was going to work as the installer looked completely different. It requires npm 3.0.0 or greater, BTW. Finally I can see it running and I can get to the API web page! Now I just have to get it to start on reboot, by doing the following… Open the crontab:

sudo crontab -e

and get the Pi to wait 60 seconds, then start the server by adding this line at the bottom:

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

So I ended up answering most of my own questions, but I thought I’d document them here to help someone else that may be having trouble getting it to work. :sweat_smile:

2 Likes

Cheers for this. Finally got me over the hump and now I have it running on my Ubuntu nas server.
You can get this running as a service using forever
sudo npm install -g forever
then
sudo npm install -g forever-service
once that is installed cd into the harmony api directory that contains the app.js file and run
sudo forever-service install harmony
you can then interact with harmony like any other service
sudo start harmony
forever looks after the init.d scripts and making sure it run when the machine is rebooted etc.

1 Like

Thanks for the pointers; my main problem now is getting it to communicate with MQTT. I use CloudMQTT and harmony-api currently doesn’t support username/pw/port so I’m not sure what to do next. I’ve asked if you can run two MQTT instances in HA with the idea of running the embedded MQTT just for harmony but I haven’t gotten any response from the forum or reddit on it.

I suppose I could use http communication but not sure how to use that in my automations to do things like turn on a light scene when a harmony activity fires…

I have fallen at this hurdle too. I have a local mqtt broker running on port 1883 with no auth and cant seem to get harmony-api to talk to it. No errors are reported but nothing is getting published onto the topics i’m watching and the switches I have configured in HA do nothing :anguished:

Actually just got this working and talking to HA. All you have to do is edit the app.js file and the line that has mqtt.connect & change it to
mqtt.connect(config.mqtt_host, {username: 'username', password: 'password', port: 1883})

I’m using mosquito on my local box and it is using protocol 3.1. mqtt on npm uses v4 so just add the following to your connection
var mqttClient = mqtt.connect('mqtt://127.0.0.1',{protocolId: 'MQIsdp', protocolVersion: 3 });
that issue is detailed here
Once i did that it all started working perfectly

1 Like

Well it appears we’ve helped each other through this because I just went to my CloudMQTT dashboard and saw my Harmony state messages!!! :tada:

It’s funny, because I tried to do the same using the code from the one pull request here and just added another variable for the port but I coudln’t make it work. Your solution is so straightforward and worked for me as soon as I restarted.

I’m so happy we could help each other out to get this running and hopefully we’ll help a lot of users get to this point by what we discovered and documented. Thanks again for your assistance!!

Could any of you kindly post a slightly more detailed post on the actual steps you took to get the Harmony Hub, MQTT and HA working together?

Downloaded the harmony-api and copied it to home/pi/harmony-api-master - Thanks to @maddox for the great interface!

@mrtrimble gave me the following commands to install apt-get working and install nodejs npm

    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get install nodejs npm

I used that to install forever, which was one of the requirements

    sudo npm install forever -g

Updated npm, because the version installed wasn’t the 3.0.0 or greater, which is why my script/bootstrap wasn’t installing the api correctly.

    sudo npm install npm -g

Ran the installer script/bootstrap according to the directions in the readme
Altered the config file with my broker information and then started the server with script/server
Confirmed it worked and then edited my crontab file as I mentioned above to run on reboot
Finally, altered the code as suggested by @beanian to allow me to use CloudMQTT

That’s not counting curses, many cigarettes, a few cups of coffee and feelings of inadequacy. But hopefully this will save you some of that.

EDIT: Gee it seems a lot easier when I look at it now, but it wasn’t. Thanks to those listed for their help!

4 Likes

Thanks for this! I’m going to give it a shot. The idea behind this knowledge share is that it will be easier for future generations to built upon.

100% agree, and you’ll see that if you read my other posts. I was actually planning on documenting this but your request pushed me to get it done sooner. Thanks! Hopefully I didn’t leave anything out, but let me know if you have any issues and I’ll do my best to help.

I got this sort-of working. Harmony API is running (apparently) but I can’t see it posting updates to my MQTT broker which is running on the same box. Its configured as the default config.json of the api as:

{
“mqtt_host”: “127.0.0.1”
}

However, subscribing to the harmony-api topic in MQTT returns no status updates.

Are you using the HA embedded broker with the default configuration and port?

I had this exact same issue. Are you using mosquito as your broker?
If so you need to change the app.js file to include the following
var mqttClient = mqtt.connect('mqtt://127.0.0.1',{protocolId: 'MQIsdp', protocolVersion: 3 });

I’m using MQTT. I tried adding the line: [quote=“beanian, post:30, topic:978”]
var mqttClient = mqtt.connect(‘mqtt://127.0.0.1’,{protocolId: ‘MQIsdp’, protocolVersion: 3 });
[/quote] to my app.js with no luck.

MQTT is the protocol. Which broker are you using? Mosquito? The HA embedded broker? Some other mqtt broker?

Oh sorry, Mosquito.

Thanks; did you change the default port on your Mosquito setup? Are you using a username and password? Maybe you need to set it up like the example @beanian gave me; that got me connected to CloudMQTT.

Harmony Hub