1.2.0 • Published 8 years ago

philips-hue v1.2.0

Weekly downloads
10
License
MIT
Repository
github
Last release
8 years ago

Philips Hue

Node.js library for Philips Hue bridge API

Circle CI

Install

% npm i philips-hue -save

Samples

see samples directory

Usage

var Hue = require('philips-hue');
var hue = new Hue();

Get Bridge's address and Auth

hue.getBridges()
  .then(function(bridges){
    console.log(bridges);
    var bridge = bridges[0]; // use 1st bridge
    console.log("bridge: "+bridge);
    return hue.auth(bridge);
  })
  .then(function(username){
    console.log("username: "+username);

    // controll Hue lights
    hue.light(1).on();
    hue.light(2).off();
    hue.light(3).setState({hue: 50000, sat: 200, bri: 90});
  })
  .catch(function(err){
    console.error(err.stack || err);
  });

username is required for the next login.

var hue = new Hue;
hue.bridge = "192.168.0.101";  // from hue.getBridges
hue.username = "a1b2cdef3456"; // from hue.auth
hue.light(1).on();

Login

hue.login is useful wrapper of getBridges and auth. It automatically store/restore username and bridge address.

var hue = new Hue;
var configFile = process.env.HOME+'/.philips-hue.json';

hue
  .login(configFile)
  .then(function(conf){
    return hue.light(1).on();
  })
  .then(function(res){
    console.log(res);
  })
  .catch(function(err){
    console.error(err.stack || err);
  });

getLights

hue.getLights()
  .then(function(lights){
    console.log(lights);
    console.log(Object.keys(lights) + " lights found!");
  })
  .catch(function(err){
    console.error(err.stack || err);
  });

on / off

var light = hue.light(1);

light.on().then(console.log).catch(console.error);
hue.light(2).on().then(console.log).catch(console.error);

setState

var state = {bri: 200, sat: 120, hue: 50000};

hue.light(1).setState(state).then(console.log).catch(console.error);

hue.light(2).setState({effect: "colorloop"});

hue.light(3).setState({alert: "lselect"});

getInfo / setInfo

var light = hue.light(1);

light.setInfo({name: "myroom"});

light.getInfo()
  .then(function(info){
    console.log(info);
  });function(err, res){
1.2.0

8 years ago

1.1.11

9 years ago

1.1.10

9 years ago

1.1.9

9 years ago

1.1.7

9 years ago

1.1.6

9 years ago

1.1.3

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.2.0

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago