Git Product home page Git Product logo

jshue's Introduction

jsHue

A simple JavaScript library for Philips Hue.

Version 0.2.0.

Copyright (c) 2014 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 username (we omit success and error callbacks below):

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

// create user account (requires link button to be pressed)
user.create('foo application', ...);

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

user.setLightState(1, { on: true }, ...);

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

jshue's People

Contributors

blargoner avatar

Watchers

 avatar

Forkers

dahamilton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.