Harmony Hub API that use the local websocket API of the hub
This module tend to replace the old XMPP API which was removed with the firemware 4.15.206 (see more here).
It uses the local websocket API of the hub.
UPDATE 23/12/2018 Logitech reversed his decision about the XMPP API. It makes available back the API but only for developers. see more here. The local websocket API remains available.
$ npm install harmonyhub-api
Use the following helper:
$ node_modules/.bin/harmonyhub-remote-id <hub_ip_or_host>
Or juste make the following http post
Host: <hub_host_or_ip>:8088
Origin: http://sl.dhg.myharmony.com
Content-Type: application/json
Accept-Charset: utf-8
{
"id ": 1,
"cmd": "setup.account?getProvisionInfo",
"params": {}
}
Example with curl
$ curl -X POST <hub_host_or_ip>:8088 -H 'Accept: utf-8' -H 'Content-Type: application/json' -H 'Origin: http://sl.dhg.myharmony.com' -d '{"id":1,"cmd":"setup.account?getProvisionInfo","params":{}}'
const HarmonyHub = require('harmonyhub-api').HarmonyHub;
const HUB_HOST = 'X.X.X.X';
const HUB_REMOTE_ID = 'XXXXXXX';
const hub = new HarmonyHub(HUB_HOST, HUB_REMOTE_ID);
hub.connect()
.then((config) => {
console.log('Connected to the hub');
console.log('\nActivities\n==========');
config.activity.forEach(activity => {
console.log(`${activity.label} (${activity.id})`);
});
console.log('\nDevices\n========');
config.device.forEach(device => {
console.log(`${device.label} (${device.id})`);
});
});
:warning: Without activities, the connection is automatically closed after 60 seconds. You can periodically send a
ping
or catch theclose
event to open a new connection.
// Regularly ping
setInterval(() => hub.ping(), 50000);
// Or catch the close event
hub.on('close', () => hub.connect());
The list of activityId can be found in the configuration object or with hub.getActivities()
hub.startActivity('xxxxxx');
The list of commands and deviceId can be found in the configuration object of each devices. Browse the content of hub.getDevices()
.
// Simple press
hub.sendCommand('VolumeUp', '53161273');
// Hold a press for 1 second
hub.holdCommand('VolumeUp', '53161273', 1000);
hub.disconnect();
The HarmonyHub object is a EventEmitter for some events :
hub.on('error|connect|close|message', callback)
error
: On error on the websocket
connect
: On connection to the websocket of the hub
close
: On the websocket connection close
message
: On incoming message from the hub
By default, the logger is set on 'warn'. You can override with the LOG_LEVEL
environnement variable. eg:
$ LOG_LEVEL=debug node test.js
The full API documentation is available in the docs/
folder.