hueset

1.2.0 • Public • Published

hueset

A node module to set Phillips hue bulb parameters

Installation

Hueset can be used as a global or local package. To install it locally and use it in your project, run:

npm install hueset

If you just want to control hue bulbs from the command line, install it globally. This will give you access to the hueset command line argument:

npm install -g hueset

Usage

To use hueset, you need to setup a user on your hue bridge, know your bridge's IP address, and know the light number you'd like to control. Check out this guide for getting that basic info.

var user = '12345';
var ip = '10.0.0.1';
var light = '1';
var color = 'red';
 
var Hue = require('hueset');
var light = new Hue.light(user, ip, light);
 
light.on(color);
  • user is the hash generated by creating a user on your hue bridge
  • ip is the local IP address of your hue bridge
  • light is the light number you'd like to actuate
  • color is any valid CCS color string, such as 'red' or '#ff0000'

.on([color])

Turns on the light referenced by the new Hue.light constructor. If a color is supplied, the light is set to that color when it is turned on. Lights that are already on will be set to the new color. If no color is supplied, the light's on state will be set to 'true' and use the previous color values. Lights that do not support color will use the computed brightness value of the supplied color (i.e. it's safe to set Philips Hue White bulb to 'purple'.)

light.on('red');

.get(cb(err, resp))

Get the current state of a light. This works for both color bulbs and dimmable lights. Accepts a callback function that takes two parameters, err and response - err is null for successful responses.

Response is in the format:

{
  on: Bool,
  color: Color
}

where on is a boolean, and color is an abstract Color object created with qix's color module

light.get(function(err, res){
  if (err) {
    // problem getting light info
    return;
  }
  console.log(res.on); // true or false
  console.log(res.color) // Color object
  console.log(res.color.hex()) // something like #ff0000
});

.off()

Turns off the light referenced by the new Hue.light constructor. Note that this only set's the light's on state to 'false', so subsequent calls to .on() will restore the light to the exact same color and brightness from before .off() was called.

light.off();

Global Usage

When installed globablly, you can call hueset from the command line.

CLI switches

See command line options and usage by running hueset --help

Usage: hueset [options]

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -u, --user [value]   Hue User Name
    -i, --ip [value]     IP address of hue hub
    -l, --light <n>      Light number (1, 2, etc.)
    -c, --color [value]  Any valid CSS color ('red', #00ff33, etc.)
    -o, --off            Turn off light specified by --light

Example:

$ hueset -u '1234' -i '10.0.0.1' -l 2 -c yellow

Any of these switches overrides environment variables, so this is possible:

export hueuser=123456
export hueip=10.0.100.42
export huelight=4

command line:

source .env
$ hueset -c red

Omitting other actions (no color, no 'off' flag) returns a light's properties:

source .env
$ hueset
{ on: true,
  color: { model: 'hsv', color: [ 120, 100, 50 ], valpha: 1 } }

Environment Vars

Hueset will read environment variables. Set these on the command line, or source them from a .env file that is excluded from your SCM.

.env:

export hueuser=123456
export hueip=10.0.100.42
export huelight=4

command line:

source .env
$ hueset -c red

These can also be set or overridden at runtime

source .env
$ huelight=2 hueset -c red

Readme

Keywords

none

Package Sidebar

Install

npm i hueset

Weekly Downloads

1

Version

1.2.0

License

MIT

Last publish

Collaborators

  • 13protons