npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

harmonyhubws

v1.0.6

Published

Simple API for Logitech Harmony Hub using local Websocket Connection

Downloads

255

Readme

HarmonyHubWS

NPM version Downloads Build Status Build status

A node module for Logitech Harmony Hub.

Uses a simple watchdog to reconnect on connection losses.

Installation

npm install harmonyhubws --production

Usage Example

with Hub IP 192.168.0.50:

const util = require('util');
const HarmonyHubWS = require('harmonyhubws');
const IP = '192.168.0.50';

let harmonyHubWS = new HarmonyHubWS(IP);
harmonyHubWS.on('online', () => {
    console.log('connected to hub', IP);
    //request config
    harmonyHubWS.requestConfig();
});

harmonyHubWS.on('config', (config) => {
    //be careful, config could be very big!
    console.log('config', util.inspect(config,false, null, true));
    //request hub state
    harmonyHubWS.requestState();

    //if there is a device press first button of device
    if (config.device.length) {
        let device = config.device[0];
        if (device.controlGroup.length && device.controlGroup[0].function.length) {
            console.log('pressing key', device.label, device.controlGroup[0].function[0].label);
            harmonyHubWS.requestKeyPress(device.controlGroup[0].function[0].action);
        }
    }

    //if there is an activity start it
    if (config.activity.length) {
        let activity = config.activity[0];
        console.log('starting activity', activity.label);
        harmonyHubWS.requestActivityChange(activity.id);
    }
});

harmonyHubWS.on('state', (activityId, activityStatus) => {
    console.log('state', activityId, activityStatus);
    //if an activity is started turn it off and close client
    if (activityStatus === 2) {
        console.log('activity started, turn off', activityId);
        harmonyHubWS.requestActivityChange('-1');
        harmonyHubWS.close();
    }
});

harmonyHubWS.on('offline', () => {
    console.log('lost connection to hub', IP);
});

new HarmonyHubWS(ip, watchdog)

Returns the state object of the robot. Also updates all robot properties.

  • ip: string - IP of your Harmony Hub
  • [watchdog]: boolean - defaults to true
  • example:
const HarmonyHubWS = require('harmonyhubws');
const IP = '192.168.0.50';

//start client without automatic connection handling
let harmonyHubWS = new HarmonyHubWS(IP, false);

Functions

requestConfig()

Asks Hub to send Config. To retrieve config use event config.

requestState()

Asks Hub to send current state. To retrieve current state use event state.

requestActivityChange(activityId)

Asks Hub to start activity with ID activityId. Results in multiple state events, activityState will be 2 when the activity is completely started.

  • activityId: number|string - ID of the activity you want to start, use '-1' (string!) to turn off any activity. To retrieve activity IDs see requestConfig.

requestKeyPress(action, hold = 'press', delay = 100)

Asks Hub to press a device key.

  • action: string - whole action string (deviceId, keyId, type) as retrieved from config.
  • [hold]: string 'press' or 'hold' - defaults to press, hold is a long press for ~250ms, if you want to hold longer you need to request hold repeatedly.
  • [delay]: number defaults to 100, how long the key is held

or

requestKeyPress(deviceId, keyId, type = 'IRCommand', hold = 'press', delay = 100)

  • deviceId: string - ID of the device you want to control. To retrieve device IDs see requestConfig.
  • keyId: string - ID (name) of the key you want to press. To retrieve key Ids see requestConfig.
  • [type]: number - defaults to IRCommand. To retrieve key types see requestConfig.
  • [hold]: string 'press' or 'hold' - defaults to press, hold is a long press for ~250ms, if you want to hold longer you need to request hold repeatedly.
  • [delay]: number defaults to 100, how long the key is held

Events

.on('online', () => {})

Fired when connection to hub is established.

.on('offline', () => {})

Fired when connection to hub is lost.

.on('state', (activityId, activityState) => {})

Fired when hub sends its current state.

  • activityId: number|string - ID of current activity, '-1' for powerOff.
  • activityState: number - state of current activity, where
    • 0: off
    • 1: starting (hub blocked until activityState is 2)
    • 2: started
    • 3: stopping (hub blocked until activityState is 0)

.on('config', (config) => {})

Fired when hub sends its configuration (devices, activities).

  • config: object - Hubs configuration. For details see example.

Changelog

1.0.6

  • (hufftheweevil) fix requestKeyPress improper handling when alternate format used

1.0.5

  • (foxriver76) make code working for Harmony Hub v4.15.250

1.0.0

  • (Pmant) initial commit