peter-murray / node-hue-api Goto Github PK
View Code? Open in Web Editor NEWNode.js Library for interacting with the Philips Hue Bridge and Lights
License: Apache License 2.0
Node.js Library for interacting with the Philips Hue Bridge and Lights
License: Apache License 2.0
As of version 1.11, the scenes are now stored inside the bridge, so there are a number of new API endpoints to support this.
The local time parameter is deprecated and has been superseded in recent API versions
The readme says:
The "Lightset 0" Group is a special instance and will always exist and have the id of "0" as specified in the Hue Api documentation. Due to this internal group being maintained by the bridge internally, it will not return an array of light ids like any of the other types of Groups.
However, on my hue bridge, when I issue a GET
request for /api/newdeveloper/groups/0 in CLIP, the result does include the list of lights:
{
"name": "Lightset 0",
"lights": [
"1",
"2",
"3"
],
"type": "LightGroup",
"action": {
"on": false,
"bri": 150,
"hue": 2049,
"sat": 0,
"effect": "none",
"xy": [
0.3804,
0.3768
],
"ct": 248,
"colormode": "xy"
}
}
Add support for the new bri_inc
, sat_inc
, hue_inc
, xy_inc
and ct_inc
values for the light state.
Hi Peter,
First of all, awesome API! Great job! ๐
Alright, so I recently started making a Hue CLI using your API and got some unexpected behaviour when using one state object for multiple lamps. I fixed this by creating a new state for each lamp. Have a look at the commit message below, any idea why this is happening?
Fixes unexpected behaviour issue when changing multiple lamps
We were using one state object to change multiple lamps. This turned out to give unexpected behaviour.
When for example doing something like './hue all --rgba=255,0.0' one lamp would turn red and the other
one would turn blue. They did however get the same state object with the same color x,y values.
This version creates a new state object for each lamp which seems to work as you'd expect.
Currently I find myself scrolling quite a bit, and I have no idea what I'm going to find. The readme content could be a bit better organized, but adding a ToC is a start :)
Hi
Thanks for the great work
I have a problem
If i run bridge-connect i get an Chai error
Module.js 340 throw error
Cannot find module 'chai'
At function module _resolvefilename (module.js 338:15)
At function module _load (module.js 280:15)
Etc.
Hope you can give a hint
Thanks
pieter
The removal of the api.connect method should be noted in the breaking changes of the readme.
I noticed the following:
krtek:~ steven$ hue lights 1,2,3,4 -99
light 1 brightness 104 -> 5
light 2 brightness 104 -> 5
light 3 brightness 104 -> 5
light 4 brightness 104 -> 5
krtek:~ steven$ hue lights 1,2,3,4 00FF99
light 1 success
light 2 success
light 3 success
light 4 success
krtek:~ steven$ hue lights 1,2,3,4 -99
light 1 brightness 254 -> 155
light 2 brightness 254 -> 155
light 3 brightness 254 -> 155
light 4 brightness 254 -> 155
Notice how after changing the color then the brightness they we're back at 254.
Update the README to include examples on how to set configuration values, including the timezone.
Hello,
Every now and then I get this error:
Api Error: parameter, xy, is not modifiable. Device is set to off.
I'm not sure what is causing it, as it seems to be random. One thought is I'm calling the API too quickly, but if I do the calls quickly on purpose it doesn't always crash.
When I run this code:
var hue = require("node-hue-api"),
timeout = 200;
var displayBridges = function(bridge) {
console.log("Hue Bridges Found: " + JSON.stringify(bridge));
};
hue.nupnpSearch().then(displayBridges).done();
hue.upnpSearch(timeout).then(displayBridges).done();
I get the following errors for the nupnpSearch
:
XMLHttpRequest cannot load https://www.meethue.com/api/nupnp. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:3000' is therefore not allowed access.
Uncaught TypeError: Cannot convert undefined or null to object
Uncaught Error: Network error
and these for the upnpSearch
:
Uncaught TypeError: dgram.createSocket is not a function
But when I go to https://www.meethue.com/api/nupnp in my browser I get a JSON object containing an id
and an internalipaddress
, which seems right as http://192.168.2.2/
shows a Philips Hue page on my network...
I'm using this in an Angular project (although it results in the same errors when I completely remove Angular) in combination with Browserify on a XAMPP stack.
Any ideas on what's causing these erros and how to get either (or both, preferably) of these working on my end?
Version information
node-hue-api
: 1.0.5
Hue Bridge: latest I guess, I can't update it
The readme and comments in the code refer to "luminaries" but the correct term is "luminaires". The actual code seems to have this correct, it's just a documentation/comment problem.
Hi Peter - I see you've started implementing this, but there's a chunk commented out.
If you can quickly help me understand:
...I'll see if I can get it finished off this weekend, and can send you a PR?
I'm running into an issue when using node-hue-api
from within Electron. It seems that every function I run (e.g. api.config()
, or api.registerUser()
) returns the following error:
Uncaught TypeError: self.req.abort is not a function
The error is thrown from node_modules/request/request.js:1340
and I'm not running into this issue when going to the project in Chrome via Browsersync.
I'm running the latest version of node-hue-api
(1.2.1), and I'm using Electron v0.35.4
.
Any ideas on what's causing this and how to fix it?
Hello,
Made the mistake of upgrading my bridge yesterday without checking if it had breaking issues. Here's the error that's being thrown from my code - which had been working fine for months. I do have the latest node-hug-api installed.
Sorry for the weak issue title. I don't know how else to describe the error.
C:\jobs\node_modules\node-hue-api\node_modules\q\q.js:126
throw e;
^
Api Error: Internal error, 404
at checkForError (C:\jobs\node_modules\node-hue-api\hue-api\httpPromise.js:9
3:15)
at C:\jobs\node_modules\node-hue-api\hue-api\httpPromise.js:140:26
at _fulfilled (C:\jobs\node_modules\node-hue-api\node_modules\request-util\node_modules\q\q.js:787:54)
at self.promiseDispatch.done (C:\jobs\node_modules\node-hue-api\node_modules
\request-util\node_modules\q\q.js:816:30)
at Promise.promise.promiseDispatch (C:\jobs\node_modules\node-hue-api\node_modules\request-util\node_modules\q\q.js:749:13)
at C:\jobs\node_modules\node-hue-api\node_modules\request-util\node_modules\q\q.js:557:44
at flush (C:\jobs\node_modules\node-hue-api\node_modules\request-util\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:419:13)
And here's the method that produces the error:
function BlinkNotificationLights() {
api.getGroup(1, function(err, result) {
if (err) throw err;
var lightList = result.lights;
var lightStatus = [];
lightList.forEach(function(lx) {
api.lightStatus(lx, function(err, result) {
lightStatus[lx] = result.state;
});
});
for (var lightloop = 2000; lightloop < 9000; lightloop+=2000 ) {
setTimeout(function() {
api.setGroupLightState(1, lsNotify, function(err, lights) { });
}, lightloop - 2000);
setTimeout(function() {
api.setGroupLightState(1, lsNotify2, function(err, lights) { });
}, lightloop);
}
setTimeout(function() {
lightList.forEach(function(lx) {
api.setLightState(lx, lightStatus[lx], function(err, lights) {
if (err) throw err;
});
})
}, 10500);
});
}
The copyright year at the bottom of the readme is still "2013". That should probably be updated to be "2013-2015". Same anywhere else you might list the copyright date.
using api v1.0.2, if I use api.setLightState(1, lightState.create().alert());
or return api.setGroupLightState(0, lightState.create().alert());
nothing happens.
Edit: However lightState.create().longAlert()
does work!
Thanks for sharing such a great project! It seems to be very well written and well documented.
However I'm having a bit of trouble running some basic functions such as registerUser()
and setLightState()
. It constantly throws a Api Error: body contains invalid json
error. I have however been successful in running functions like connect()
and deleteUser()
.
I'm running on a Windows 8.1 environment, with node version 0.10.35 and bridge swversion 01018228.
The Schedules API implementation needs to be updated to support the changes in the underlying Bridge API.
Attention is required to times and how they re specified in the schedule as this area has changed a lot.
I'm using node-hue-api 1.0.3 and I have not set a custom scene id prefix.
When calling api.createScene, the resulting id is a NaN, whereas this should be a unique string.
Example result json:
{ lights: [ '4', '5', '6' ], id: 'NaN' }
I think the problem is in
HueApi.prototype._getScenePrefix = function () {
return this._getConfig().scene_prefix;
};
I think it should be
HueApi.prototype._getScenePrefix = function () {
return this._getConfig().scenePrefix;
};
The following code triggers the .fail()
callback immediately:
var hue = require("node-hue-api");
var api = new hue.HueApi();
// ip = '192.168.2.1'
api.registerUser(ip, null, null).then(function(result) {
d.resolve();
console.log('registerUser result:', result);
}).fail(function(result) {
d.reject('button not pressed');
console.error('registerUser error:', result);
}).done();
Which results in an immediate ApiError {message: "link button not pressed", type: 101}
in my console. I'm still working on the same project as described in #51, so maybe gulp-browserify is messing something up again?
Any ideas on how to solve this?
httpPromise.js contains the following line for setting a HTTP request timeout:
options.timeout = 10000; //TODO make adjustable
I am using your library with Node-RED and under certain conditions the Hue hub is unable to answer in under 10 sec. This causes the whole Node-RED server to crash since the thrown TIMEOUT exception is not catched. For now I have commented out this line and have no issues anymore.
Hence I would make this setting strongly optional.
Hi,
I have this case, where I get a connection reset when obtaining the lightStatus for many lamps (around 8).
My current solution is to use a queue, but it would be nice to bind it to the open connections or unresolved promises.
Error: write ECONNRESET
at exports._errnoException (util.js:746:11)
at Socket._writeGeneric (net.js:681:26)
at Socket. (net.js:637:12)
at Socket.g (events.js:199:16)
at Socket.emit (events.js:129:20)
at TCPConnectWrap.afterConnect as oncomplete
The 1.7 firmware update on the bridge has introduced a number of increment options that need to be added to the API
I noticed the following:
It seems that it first turns on, so the light wants to return to its previous bright white state. After that it gets its new color state.
Using the Hue Tab, when i do the same (one button is bright white, the second is dark red and the main is off), the flash doesn't happen. It turns from off to dark red directly,
Does anybody know why this happens with the node-hue-api but not with the Hue Tab? Are I am doing something wrong?
Hi,
We noticed that the transitiontime did not work.
You misspelled it in hue-api/commands/traits/tLightStateBody.js
I also wondered why you don't just pass the json directly to the Hue Bridge?
Enable auto discovery of bridge and auto signup of username.
Store these values on the server.
Produces a red
light after passing white rgb colors
lightState
.create()
.on()
.rgb(255,255,255)
.brightness(100)
Produces a white
light after passing black rgb colors
lightState
.create()
.on()
.rgb(0, 0, 0)
.brightness(100)
If I run api.setGroupLightState(0, lightState.create().off())
nothing happens - if I address a single light bulb it works api.setLightState(1, lightState.create().on())
.
When I attempt to change the color of a group of lights I get "Api Error: RGB state is not supported for groups yet" using setGroupLightState() function.
It looks like the https://www.meethue.com/api/nupnp endpoint has now changed to require https - requests to http://www.meethue.com/api/nupnp get redirected - this causes an error when attempting to use node-hue-api.locateBridges:
/path/node_modules/node-hue-api/node_modules/q/q.js:126
throw e;
^
Api Error: Unexpected response status; 302
at _checkResponse (/path/node_modules/node-hue-api/hue-api/httpPromise.js:93:15)
at _fulfilled (/path/node_modules/node-hue-api/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/path/node_modules/node-hue-api/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/path/node_modules/node-hue-api/node_modules/q/q.js:760:13)
at /path/node_modules/node-hue-api/node_modules/q/q.js:574:44
at flush (/path/node_modules/node-hue-api/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Save the presumed state of the lights on the server so we don't have to send requests and wait to learn the state of the lights before mutating them.
I'm writing a proxy for my hue bridge that augments it with a new non-hue networked lights - when doing discovery of hue bridges, they respond with a location
header which is a URL to a description document. That document contains useful information like bridge serial number and the URLBase property.
Right now node-hue-api
does a ssdp search for bridges, then requests /description.xml
from port 80 of the hosts that respond to the search in order to get the bridge id - this happens to follow the hue implementation but doesn't seems to be in the spirit of the protocol - it should follow the location
header instead.
So, for example, the ssdp search node-hue-api
generates is:
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: ssdp:discover
MX: 10
ST: urn:schemas-upnp-org:device:Basic:1
The response is then:
HTTP/1.1 200 OK
ST: urn:schemas-upnp-org:device:Basic:1
USN: uuid:07a50742-5a89-4b27-9a9e-374df1191a61::urn:schemas-upnp-org:device:Basic:1
LOCATION: http://192.168.1.67:64764
CACHE-CONTROL: max-age=100
DATE: Sat, 18 Jul 2015 11:43:43 GMT
SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.8.0
EXT:
The next request from node-hue-api
should be to http://192.168.1.67:64764
, instead it's to http://192.168.1.67/description.xml
I think this is because when makes the request to the host and then has the path to /description.xml
hard coded.
As a shameless plug I've written an ssdp implementation that automagically goes off, fetches and parses the contents of the location header for you - might solve the problem..
Simple question: what is the markup you are using in code comments, particularly in index.js
, and how does it work?
I notice that the locateBridges
function uses the meethue.com NUPnP service. Have you considered also using UPnP as shown in the Hue developer documentation? Their flowchart shows using UPnP, and if no results are returned, then use NUPnP. Alternately, they suggest running the UPnP and NUPnP queries simultaneously.
I'm trying to store and recall scenes. The scenes are created with the correct lamp selection on the bridge, but when I call api.activateScene using the scene id, the lamps do not respond.
Unfortunately I cannot verify the light states that are stored for each scene, only the lamp set that makes up the scene.
This is my code. It shows each scene once (because the first time the light states are set separately using setLightState instead of using the scene mechanism). After that the scenes mechanism (api.createScene, api.activateScene) should take over, but the lamps do not change according to the called scenes.
index.js:
var hue = require("node-hue-api"),
HueApi = hue.HueApi,
lightState = hue.lightState;
var displayResult = function (result) {
console.log(JSON.stringify(result, null, 2));
};
var displayError = function (err) {
console.log(JSON.stringify(err, null, 2));
};
var hostname = "xxx.xxx.xxx.xxx",
username = "someusername",
api;
api = new HueApi(hostname, username);
//load initial config from json
var sceneConfig = require('./scenes.json');
//set the lightstate for each light separately when they're not stored as a scene yet
var setStates = function (lightStates, callback) {
var todo = Object.keys(lightStates).length;
console.log(todo);
//safety function to make sure all states are set before saving to scene
var lightDone = function () {
todo--;
console.log(todo);
if (todo === 0) {
callback();
}
};
for (var lightId in lightStates) {
api.setLightState(lightId, lightStates[lightId])
.then(lightDone)
.fail(displayError)
.done();
}
};
//activate a scene from the scene config. if it has no Hue scene id yet,
//set the states separately and store them as a Hue scene
var activateScene = function (sceneName) {
var scene = sceneConfig[sceneName];
if (scene !== null) {
if (scene.id !== undefined) {
console.log('using predefined scene id ' + scene.id);
api.activateScene(scene.id)
.then('predefined scene result: ' + console.log)
.done();
} else if (scene.states !== undefined) {
setStates(scene.states, function () {
var lightIds = Object.keys(scene.states);
api.createScene(lightIds, '', function (err, result) {
if (err) throw err;
//store the created scene id in the scenes config object
scene.id = result.id;
sceneConfig[sceneName] = scene;
console.log('scene created.');
console.log(result);
});
});
}
}
};
//switch between scenes every 4 seconds
var switchBool = true;
setInterval(function () {
var sceneToActivate = switchBool ? 'gold' : 'sleep';
activateScene(sceneToActivate);
switchBool = !switchBool;
}, 4000);
scenes.json:
{
"gold": {
"states": {
"4": {
"on": true,
"bri": 123,
"hue": 14582,
"sat": 251
},
"5": {
"on": true,
"bri": 123,
"hue": 14582,
"sat": 251
},
"6": {
"on": true,
"bri": 123,
"hue": 14582,
"sat": 251
}
}
},
"sleep": {
"states": {
"1": {
"on": false
},
"2": {
"on": true,
"bri": 254
},
"3": {
"on": true,
"bri": 123,
"hue": 14582,
"sat": 251
},
"4": {
"on": false
},
"5": {
"on": false
},
"6": {
"on": false
}
}
}
}
Hi,
I found a problem with the API,
If I set hsl(0, 100, 100) it make the light Red but the good value in HSL for red is hsl(0, 100, 50).
Anyone agree with this ?
In places, the readme says things like:
The creation of groups is not officially supported in the released Hue API from Phillips (version 1.0).
Groups are fully supported in the current version of the Hue API. The documentation and/or the module should be updated accordingly.
I created a LightState
for a single lamp using an invalid id (for example 0 instead of 1). The error message is a bit missleading, here's the stack trace:
"error":"Cannot call method 'hasRGB' of undefined",
"stack":"TypeError: Cannot call method 'hasRGB' of undefined\n at HueApi._getLightStateOptions (
/a-project/node_modules/node-hue-api/hue-api/index.js:996:15)\n at HueApi.setLightState (
/a-project/node_modules/node-hue-api/hue-api/index.js:322:24)\n at Object.exports.lampDim (
Need to add support for Rules API in the library
Hi Peter,
I work for Philips Hue Developer Support. In case you were not aware, in a few months time we will be changing the way usernames are created on the bridge (for security reasons). Custom whitelist usernames will no longer be allowed and the bridge randomly generated username must be used instead. Please see below link for more information:
http://www.developers.meethue.com/documentation/important-whitelist-changes
I had a quick look at your code and it looks like you are POSTng the "username" (index.js line 1124 in _setCreateUserOptions method). This will start failing around February 2016 so it should be removed. Looking at your description on your project page (Registering without an existing Device ID/User ID section) it appears you already have the code to using the Bridge Randomly generated username, so hopefully it should be a simple case of just removing the option to generate custom usernames. Apologies for the inconvenience.
Thanks
Steve
There is a new file named 'patch' in the 1.0.0 npm package. I don't think it's supposed to be there.
It seems from package.js that >=1.2.3-2 <1.3.0 is required whereas npm only provides up to 0.4.
I'm just starting to play around with this API (thanks a lot for writing this), at the moment getting the lights, I'm not receiving any info on the type of lights, is this something I'm doing wrong?
hueApi.lights()
.then(function(result) {
this.log('Lights = ' + JSON.stringify(result));
cb(null, result);
}.bind(this))
.fail(function(err) {
this.log('getLights error: ', err);
cb(err);
}.bind(this))
.done();
Code looks like this, so is just the example from the readme.
The only reason I'd like this info is that Lux lamps look like they may only like having a brightness state applied to them.
The schedules API now supports different types of time formats that need to be built into the API
First of all. Thanks for a great project! Great functionality that really made the work with implementing the hue lights into my home automation system quite fun!
Now I am trying to unleash the creativity of my family when it comes to setting the lights to nice colors and combinations. For that I would like to use the scenes API which is not yet supported by your API.
Instead of doing a my own wrapper I have tried to enhance your API, I am about to create a pull request with those changes.
Thanks again for your work with this!
When performing some sequential upnpSearch (e.g. to force reconnection upon link going down), node.js EventEmitter gives up since it reaches the maxListeners limit.
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at process.addListener (events.js:160:15)
at process.on.process.addListener (node.js:796:26)
at new SSDPSearch (/.../node_modules/node-hue-api/hue-api/search.js:57:14)
at Object.locateBridges (/.../node_modules/node-hue-api/hue-api/search.js:15:18)
at Object.module.exports.networkSearch [as upnpSearch] (/.../node_modules/node-hue-api/hue-api/bridge-discovery.js:20:19)
at Firefly.searchForBridge (/.../backend/server/firefly.js:15:13)
at /.../backend/server/firefly.js:18:22
at _fulfilled (/.../node_modules/node-hue-api/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/.../node_modules/node-hue-api/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/.../node_modules/node-hue-api/node_modules/q/q.js:749:13)
at /.../node_modules/node-hue-api/node_modules/q/q.js:509:49
at flush (/.../node_modules/node-hue-api/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:442:13)
This relates to Pull Request #32.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.