How to use the node-hue-api.lightState.create 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 armand1m / philips-hue-experiments / commands / turn-on.js View on Github external
const commandLineArgs = require('command-line-args')

const withLogging = require("../lib/with-logging");
const applyLightState = require("../lib/apply-light-state");
const applyLightStateToAll = require("../lib/apply-light-state-to-all");

const applyStateToAll = withLogging("turn all lights on")(applyLightStateToAll);

const optionDefinitions = [
  { name: 'id', type: Number, multiple: true },
  { name: 'all', alias: 'A', type: Boolean, defaultOption: false }
]

const options = commandLineArgs(optionDefinitions)

const state = lightState.create().on();

if (options.all) {
  applyStateToAll(state);
  process.exit(0);
}

if (!options.id) {
  console.log("Provide one id at least or run with the --all flag.");
  process.exit(0);
}

options.id.forEach(id => {
  const applyState = withLogging(`turn light with id ${id} on`)(applyLightState)
  applyState(id, state)
})
github armand1m / philips-hue-experiments / commands / turn-off.js View on Github external
const commandLineArgs = require('command-line-args')

const withLogging = require("../lib/with-logging");
const applyLightState = require("../lib/apply-light-state");
const applyLightStateToAll = require("../lib/apply-light-state-to-all");

const applyStateToAll = withLogging("turn all lights off")(applyLightStateToAll);

const optionDefinitions = [
  { name: 'id', type: Number, multiple: true },
  { name: 'all', alias: 'A', type: Boolean, defaultOption: false }
]

const options = commandLineArgs(optionDefinitions)

const state = lightState.create().off();

if (options.all) {
  applyStateToAll(state);
  process.exit(0);
}

if (!options.id) {
  console.log("Provide one id at least or run with the --all flag.");
  process.exit(0);
}

options.id.forEach(id => {
  const applyState = withLogging(`turn light with id ${id} off`)(applyLightState)
  applyState(id, state)
})
github kvartborg / hueify / src / views / Lights.jsx View on Github external
setLightBrightness (light, event) {
    this.props.api.setLightState(
        light.id,
        lightState.create().transitionFast().bri(event.target.value)
      )
      .done(this.props.api.updateState)
  }
github kvartborg / hueify / src / views / Lights.jsx View on Github external
setColor (rgb) {
    this.props.api.setLightState(
        this.state.currentLight.id,
        lightState.create().rgb(...rgb)
      )
      .done(this.props.api.updateState)
  }
github kvartborg / hueify / src / views / Groups.jsx View on Github external
setColor (rgb) {
    for (let light of this.state.currentLightGroup.lights) {
      this.props.api.setLightState(
          light,
          lightState.create().rgb(...rgb)
        )
        .done(this.props.api.updateState)
    }
  }
github armand1m / philips-hue-experiments / commands / set-brightness.js View on Github external
if (!brightnessLevel) {
  throw new Error("Brightness level argument is missing. Make sure you ran it like: `npm run set-brightness -- 70`");
}

if (brightnessLevel > 100) {
  throw new Error("Brightness level cannot be above 100. Select a value between 0 and 100.");
}

if (brightnessLevel < 0) {
  throw new Error("Brightness level cannot be below 0. Select a value between 0 and 100.");
}

const applyState = withLogging(`set brightness to ${brightnessLevel}%`)(applyLightStateToAll);

applyState(lightState.create().brightness(brightnessLevel));
github armand1m / philips-hue-experiments / commands / set-color-temperature.js View on Github external
if (!colorTemperatureLevel) {
  throw new Error("ColorTemperature level argument is missing. Make sure you ran it like: `npm run set-color-temperature -- 170`");
}

if (colorTemperatureLevel > 500) {
  throw new Error("Color Temperature level cannot be above 500. Select a value between 153 and 500.");
}

if (colorTemperatureLevel < 153) {
  throw new Error("Color Temperature level cannot be below 153. Select a value between 153 and 500.");
}

const applyState = withLogging(`set color temperature to "${colorTemperatureLevel}"`)(applyLightStateToAll);

applyState(lightState.create().colorTemperature(colorTemperatureLevel));
github kvartborg / hueify / src / views / Groups.jsx View on Github external
setGroupBrightness (group, event) {
    this.props.api.setGroupLightState(
        group.id,
        lightState.create().transitionFast().bri(event.target.value)
      )
      .done(this.props.api.updateState)
  }
github armand1m / philips-hue-experiments / commands / set-color.js View on Github external
throw new Error(createColorErrorMessage('Color was not defined'));
}

const recognizedColor = color(colorHex);

if (!recognizedColor) {
  throw new Error(createColorErrorMessage('Color could not be recognized'));
}

const colorAsHex = recognizedColor.hex();
const [red, green, blue] = recognizedColor.toJSON().slice(1, -1);
const colorName = colorToName.findClosestColor(colorAsHex).name;

const applyState = withLogging(`set color to '${colorName} (${colorAsHex})'`)(applyLightStateToAll);

applyState(lightState.create().rgb(red, green, blue));
github armand1m / philips-hue-experiments / commands / set-saturation.js View on Github external
if (!saturationLevel) {
  throw new Error("Saturation level argument is missing. Make sure you ran it like: `npm run set-saturation -- 50`");
}

if (saturationLevel > 100) {
  throw new Error("Saturation level cannot be above 100. Select a value between 0 and 100.");
}

if (saturationLevel < 0) {
  throw new Error("Saturation level cannot be below 0. Select a value between 0 and 100.");
}

const applyState = withLogging(`set saturation to ${saturationLevel}%`)(applyLightStateToAll);

applyState(lightState.create().saturation(saturationLevel));