How to use node-hue-api - 10 common examples

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 ecaron / smart-nightlight-manager / utils / brightChecker.js View on Github external
/* eslint new-cap: ["error", { "newIsCap": false }] */
const hue = require('node-hue-api').v3

const hex2rgb = require('../lib/hex2rgb')
const db = require('../lib/db')

if (process.argv.length !== 3) {
  console.warn('This script must be run as `node brightChecker.js ID`, where ID is the number Hue has for light')
  process.exit(1)
}

db.event.on('loaded', function () {
  const bridgeInfo = db.settings.findOne({ type: 'hue' })

  if (!bridgeInfo) {
    console.warn('Did you forget to run Hue settings setup?')
    process.exit(1)
  }
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 cheshire137 / hue-steamer / app.js View on Github external
getLightStatus(group.lights[i]);
  }
};
var displayBridge = function(bridge) {
  console.log('Bridge "' + bridge.name + '"');
  console.log("\tTime: " + bridge.localtime);
  console.log("\tAPI version: " + bridge.apiversion);
  api.getGroup('0').then(displayGroup).done();
};
// api.config().then(displayBridge).done();

var displayBridges = function(bridge) {
    console.log("Hue Bridges Found: " + JSON.stringify(bridge));
};

hue.upnpSearch(2000).then(displayBridges).done();

// // var redX = 0.6417, redY = 0.304;
// // var blueX = 0.168, blueY = 0.041;
// // // var state = lightState.create().on().xy(redX, redY);
// // var state = lightState.create().on().effect('none');

// // api.setLightState(lightID, state).
// //     then(displayLightState).fail(displayError).done();
github GladysAssistant / Gladys / server / services / philips-hue / index.js View on Github external
module.exports = function PhilipsHueService(gladys, serviceId) {
  // require the node-hue-api module
  // @ts-ignore
  const hueClient = require('node-hue-api').v3;
  const philipsHueLightHandler = new PhilipsHueLightHandler(gladys, hueClient, serviceId);

  /**
   * @public
   * @description This function starts the PhilipsHueService service
   * @example
   * gladys.services['philips-hue'].start();
   */
  async function start() {
    logger.log('starting Philips Hue service');
    philipsHueLightHandler.init();
  }

  /**
   * @public
   * @description This function stops the PhilipsHueService service
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 tlackemann / hubert / src / hue.js View on Github external
return new Promise((res, rej) => {
    hue.nupnpSearch((err, result) => {
      if (err) {
        log.error('An error occurred fetching bridges from Hue: %s', err)
        return rej(err);
      }

      // Get the first bridge
      const bridge = result.length ? result[0] : {}
      if (!bridge.id) {
        log.error('No bridges found!');
        return rej('No bridges found');
      }

      log.info('Found bridge: %s (IP: %s)', bridge.id, bridge.ipaddress)
      res(bridge)
    })
  })
github mpj / workroom-lights-killer / src / play.js View on Github external
api.lights()
    .then(displayResult)
    .done();
/*

// Using a promise
api.registerUser(hostname, null, 'dshjdksaskhjd')
    .then(displayUserResult)
    .fail(displayError)
    .done();


// --------------------------
// Using a promise
*/
hue.nupnpSearch().then(displayBridges).done();
api.config().then(displayResult).done();


api.config(function(err, config) {

})
github cheshire137 / hue-steamer / src / server.js View on Github external
server.get('/bridges/discover', async (req, res) => {
  const timeout = 2000; // 2 seconds
  hue.nupnpSearch(timeout).then((bridges) => {
    res.json(bridges);
  }).fail((err) => {
    res.status(400).json(err);
  }).done();
});