How to use the node-hue-api.lightState function in node-hue-api

To help you get started, we’ve selected a few node-hue-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tigoe / hue-control / server-examples / fadeLight.js View on Github external
by Tom Igoe

	Based on the examples in the node-hue-api readme:
	https://github.com/peter-murray/node-hue-api

	to call this from the commandline:
	node fadeLight.js address username portname

	(username must be a previously registered user)
*/


var hue = require("node-hue-api"),	// include the node-hue-api library
	HueApi = hue.HueApi,							// make a local instance of HueApi
	hub, 															// will hold the hub info when you instantiate it
	lightState = hue.lightState;


var serialport = require("serialport"),	// include the serialport library
	SerialPort  = serialport.SerialPort;	// make a local instance of it

var address = process.argv[2],			// hub IP address from command line
	username = process.argv[3],				// your app's username from the command line
	portName = process.argv[4];				// serial port from the command line


// print a JSON object nicely:
var displayResult = function(result) {
    console.log(JSON.stringify(result, null, 2));
};

// set a light's state using parameters given:
github mpj / workroom-lights-killer / src / play.js View on Github external
var displayBridges = function(bridge) {
    console.log("Hue Bridges Found: " + JSON.stringify(bridge));
};
var displayResult = function(result) {
    console.log(JSON.stringify(result, null, 2));
};

fs.readFile('./username.tmp', 'utf8', function (err, data) {
  if (err) throw err;
  console.log('data',data);
});

fs.writeFile('./username.tmp', 'blah123');


var state = hue.lightState.create().off()
/*
console.log('state', state)

api.setLightState(15, state)
    .then(displayResult)
    .done();
*/
// Using a promise
api.lights()
    .then(displayResult)
    .done();
/*

// Using a promise
api.registerUser(hostname, null, 'dshjdksaskhjd')
    .then(displayUserResult)
github tmrudick / hue-weather-lights / jobs / weather.js View on Github external
var request = require('request'),
    HueApi = require('node-hue-api').HueApi,
    LightState = require('node-hue-api').lightState;

// Get the weather data from darksky.net at 7:15am
job('get weather', function(done) {
    var url = 'https://api.darksky.net/forecast/' + this.config.tokens.forecastio + '/' + this.config.weather.latitude + ',' + this.config.weather.longitude;

    request({ url: url, json:true}, function(err, data) {
        done({
            color: {
                red: 0,
                green: 0,
                blue: 0
            },
            forecast: data.body
        });
    });
}).at('15 7 * * *'); //.defer();
github dennisdegreef / mqtt-hue-bridge / server.js View on Github external
* Examples:
 *   /light/all/state        on
 *   /light/1/state          off
 *   /light/3/brightness     100
 *   /light/all/brightness   50
 *
 */
var mqtt     = require('mqtt');
var hue      = require('node-hue-api');
var config   = require('./config');

var mqttUri     = 'mqtt://' + config.mqtt.hostname + ':' + config.mqtt.port;
var mqttOptions = {username: config.mqtt.username, password: config.mqtt.password};
var client      = mqtt.connect(mqttUri, mqttOptions);
var api         = new hue.HueApi(config.hue.hostname, config.hue.username);
var state       = hue.lightState.create();

// topic is /light//
var topicRegex = config.mqtt.namespace + "/(.*)/(.*)";

var lights = [];
api.lights().then(function(result) {
    lights = result.lights;

    client.on('message', function (topic, message) {
        var topicParts = topic.match(topicRegex);
        if(topicParts == null) {
            // These are not the topics you are looking for
            return;
        }
        var identifier = topicParts[1];
        var property   = topicParts[2];
github ecaron / smart-nightlight-manager / lib / bridge.js View on Github external
var bridgeInfo = db.get('bridge').first().value();
var _ = require('lodash');
var defaultStayOnMinutes = 60;

if (!bridgeInfo) {
  console.warn('Missing config/db.json does not contain bridge information. Did you forget to run "npm run setup"?');
  process.exit(1);
}

if (typeof bridgeInfo !== 'object' || !bridgeInfo.ip || !bridgeInfo.username) {
  console.warn('config.bridge.json does not contain an object with "ip" and "username". Did you forget to run "npm run setup"?');
  process.exit(1);
}

exports.HueApi = hue.HueApi;
exports.lightState = hue.lightState;
exports.api = new exports.HueApi(bridgeInfo.ip, bridgeInfo.username);
exports.lightLog = {};
exports.lights = {};
exports.api.lights(function (err, data) {
  if (err) {
    logger.error(err);
  }
  _.each(data.lights, function (light) {
    exports.lights[light.id] = {
      id: light.id,
      timer: false,
      timerTime: false,
      addLog: function (message) {
        if (this.log.length > 20) {
          this.log.shift();
        }
github node-red / node-red-nodes / hardware / philips_hue / 103-philips_hue.js View on Github external
var msg2 = {};
                msg2.topic = this.topic;
                if (err) throw err;

                if(result[0]==null) {
                    msg2.payload="No Philips Hue Bridge located! Nothing to be done.";
                    console.log("No Philips Hue Bridge located!");
                    node.send(msg2);
                }
                else {
                    //save the IP address of the 1st bridge found
                    this.gw_ipaddress = result[0].ipaddress;

                    //set light status
                    var api = new HueApi(this.gw_ipaddress, node.username);
                    var lightState = hue.lightState;
                    var state = lightState.create();

                    var status;
                    if(msg.payload=="ALERT"){
                        status = "ALERT";
                    }
                    else if(node.lamp_status=="ON" || msg.payload=="ON") status = "ON";
                    else if(node.lamp_status=="OFF" || msg.payload=="OFF") status = "OFF";


                    if(status=="ALERT") {
                        api.setLightState(node.lamp_id, state.alert()).then(displayResult).fail(displayError).done();
                    }
                    else if(status=="ON") {
                        api.setLightState(node.lamp_id, state.on()).then(displayResult).fail(displayError).done();
                    }
github hecomi / tsubakumi2 / services / apis / device / hue.js View on Github external
var colors      = require('colors');
var hue         = require('node-hue-api');
var HueApi      = hue.HueApi;
var lightState  = hue.lightState;
var lightStates = [];

var InvalidApiError = msg => {
	var e = new Error(msg);
	e.name = 'InvalidApiError';
	return e;
};

var routes = app => {
	return (req, res) => {
		var api = new HueApi(app.get('hue').ip, app.get('hue').user);
		var callHueApi = (apiName, arg1, arg2) => {
			var callback = (err, result) => {
				if (err) {
					console.error(err.red);
				}
github jakkra / SmartMirror / util / hue.js View on Github external
var hue = require('node-hue-api'),
  HueApi = hue.HueApi,
  lightState = hue.lightState;

const { lights } = require('../config');
let rlights,
  groupAll,
  groups = [];

const hostname = process.env.HUE_HOSTNAME,
  username = process.env.HUE_USERNAME;

const api = new HueApi(hostname, username);

refreshLights();
setInterval(refreshLights, 10 * 60 * 1000);

api.groups(function(err, result) {
  if (err) throw err;
github node-red / node-red-nodes / hardware / hue / 104-hue_manage.js View on Github external
function setLights(node, myMsg) {

    var msg2 = {};
    msg2.topic = this.topic;

    //set light status
    var api = new HueApi(node.gw_ipaddress, node.username);
    var lightState = hue.lightState;
    var state = lightState.create();

    var status;
    var lamp = -1;

    //check for AUTO status (lamp settings set through node input)
    if(node.lamp_status=="AUTO") {
        var color;
        var brightness;

        //get lamp id from msg.lamp:
        lamp = myMsg.lamp;

        //get brightness:
        brightness = myMsg.brightness;
github ebidel / lighthouse-hue / src / huelights.js View on Github external
lights.forEach(light => {
        //const state = hue.lightState.create().hue(color).bri(255).sat(0);//.transition(1000);
        const state = hue.lightState.create().hue(color).bri(255).sat(255);

        if (light.id === activeLightId) {
          state.on();
        } else {
          state.off();
        }
        this.api.setLightState(light.id, state);
      });