Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ Change the RGB colour of the light. Note 0,0,0, is not `off`.

### client.rename(light,name,cb)
Change the light's name to the string `name`, where `light` is the index received from `client.clients()`.

### client.brightness(light, birghtnessValue,cb)
Control the brightness of a single light, where `light` is the index received from `client.clients()` and `birghtnessValue` is in range 0 - 255. At value 0 the light will switch off.
20 changes: 20 additions & 0 deletions lib/Hue.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,23 @@ Hue.prototype.station = function(config,cb) {
return this;
};

/**
* Control brightness of one light.
* @param light {String} id of a light to work with
* @param brightnessValue {Integer} value from 0 to 255 for min to max brightness
* @param cb {Function} callback function
*/
Hue.prototype.brightness = function(light, brightnessValue, cb) {
var opts = {
method:'PUT',
url:'http://'+this._station+'/api/'+this._key+'/lights/'+light+'/state',
json:{on: brightnessValue > 0, bri:brightnessValue % 256},
timeout:30000
};

request(opts,function(e,r,b) {
if (e) cb(e)
else if (typeof cb === "function") cb.apply(this,Helpers.parseHueResponse(b));
});
return this;
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hue.js",
"version": "0.2.13",
"version": "0.2.14",
"description": "Library for interacting with a Phillips Hue base station",
"main": "index.js",
"scripts": {
Expand All @@ -26,5 +26,8 @@
"author": {
"name": "Daniel Friedman"
},
"contributors": [
{"name": "Valentin Alexeev", "email": "valentin.alekseev@gmail.com"}
],
"license": "MIT"
}