Skip to content
javascript library for philips hue
JavaScript
Latest commit fd76302 Oct 14, 2015 @blargoner version 0.3.0
Failed to load latest commit information.
src version 0.3.0 Oct 14, 2015
LICENSE docs Jan 4, 2014
README.md version 0.3.0 Oct 15, 2015

README.md

jsHue

A simple JavaScript library for Philips Hue.

Version 0.3.0.

Copyright (c) 2015 John Peloquin. All rights reserved.

Introduction

jsHue is a simple JavaScript wrapper library for the Philips Hue API with a sane object interface and without unnecessary dependencies. It is primarily intended for use in modern web browsers supporting XHR and JSON, but with injection of suitable dependencies it could also be used in other environments like Node.js.

The following Hue APIs are supported:

  • Bridge discovery
  • Lights
  • Groups
  • Schedules
  • Scenes
  • Sensors
  • Rules
  • Configuration
  • Info

Getting Started

To get started, instantiate jsHue:

var hue = jsHue();

Then you can discover local bridges:

hue.discover(
    function(bridges) {
        if(bridges.length === 0) {
            console.log('No bridges found. :(');
        }
        else {
            bridges.forEach(function(b) {
                console.log('Bridge found at IP address %s.', b.internalipaddress);
            });
        }
    },
    function(error) {
        console.error(error.message);
    }
);

jsHue performs requests asynchronously and provides a callback interface. The failure callback is called if the XHR request fails, or if there is an error with the JSON serialization or deserialization. All API success and error results are returned in the success callback data. (This is because some API calls may return aggregated API success and error results.)

Once you have a local bridge IP address, you can create a user on the bridge with a bridge-generated username (we omit error callbacks below):

var bridge = hue.bridge('192.168.1.2');

// create user account (requires link button to be pressed)
bridge.createUser('foo application', function(data) {
    // extract bridge-generated username from returned data
    var username = data[0].success.username;

    console.log('New username:', username);

    // instantiate user object with username
    var user = bridge.user(username);
});

Once authenticated, you can do anything with the API, like turn on a light:

user.setLightState(1, { on: true }, function(data) { /* ... */ });

For more details, see the source code. jsHue's object interface maps directy to the API, so it is very straightforward to use.

Something went wrong with that request. Please try again.