Giter VIP home page Giter VIP logo

node-lifx's Introduction

LIFX Node.js Library

Warning: This repository currently has no active maintainer. For that reason, development is stale. Consider using an active fork, like lifx-lan-client.

NPM Version Build Status Build status Dependency Status codecov.io Gitter Chat

A Node.js implementation of the LIFX protocol. Developed to work with a minimum firmware version of 2.0.

This library is not, in any way, affiliated or related to LiFi Labs, Inc.. Use it at your own risk.

Installation

$ npm install node-lifx --save

Compatibility

Node.js 0.12+ and io.js are tested and supported on Mac, Linux and Windows.

Usage

The file cli.js contains a working example.

Client

The library uses a client for network communication. This client handles communication with all lights in the network.

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.init();

The Client object is an EventEmitter and emmits events whenever any changes occur. This can be a new light discovery, a light sending a message or similar. The client starts discovery of lights right after it is initialized with the init method. If a new light is found the client emmits a light-new event. This event contains the light as an object on which methods can be called then:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.on('light-new', function(light) {
  // Change light state here
});

client.init();

Changing light state

The states of a light can be changed with different methods:

light.on([duration], [callback])

This turns a light on.

Option Type Default Description
duration int 0 Turning on will be faded over the time (in milliseconds).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.on(); // Turns the light on instantly
light.on(2000); // Fading the light on over two seconds

light.off([duration], [callback])

This turns a light off.

Option Type Default Description
duration int 0 Turning off will be faded over the time (in milliseconds).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.off(); // Turns the light off instantly
light.off(2000); // Fading the light off over two seconds

light.color(hue, saturation, brightness, [kelvin], [duration], [callback])

Changes the color of a light to an HSB color value. This is the preferred method to change the color of a light.

Option Type Default Description
hue int Between 0 and 360, representing the color hue in degree which changes the color.
saturation int Between 0 and 100, representing the color intensity from 0% to 100%.
brightness int Between 0 and 100, representing the light brightness from 0% to 100%.
kelvin int 3500 Between 2500 and 9000, representing the color temperature.
duration int 0 Fade the color to the new value over time (in milliseconds).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.color(0, 100, 50); // Set to red at 50% brightness
light.color(50, 50, 80, 3500, 2000); // Set to a light green at 80% brightness over next two seconds

light.colorRgbHex(hexString, [duration], [callback])

Changes the color of a light to an RGB color value given in Hex Format. Note that RGB poorly represents color of light, prefer HSBK values given via the color method.

Option Type Default Description
hexString string A hex RGB string starting with #
duration int 0 Fade the color to the new value over time (in milliseconds).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.colorRgbHex('#F00'); // Set to red
light.colorRgbHex('#FFFF00'); // Set to yellow

light.colorRgb(red, green, blue, [duration], [callback])

Changes the color of a light to an RGB color value. Note that RGB poorly represents color of light, prefer HSBK values given via the color method.

Option Type Default Description
red int Amout of red in color from 0 to 255
green int Amout of green in color from 0 to 255
blue int Amout of blue in color from 0 to 255
duration int 0 Fade the color to the new value over time (in milliseconds).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.colorRgb(255, 0, 0); // Set to red
light.colorRgb(255, 255, 0); // Set to yellow

light.maxIR(brightness, callback)

Set's the maximum infrared brightness of the light (only for lights that support infrared light)

Option Type Default Description
brightness int Between 0 and 100, representing the light brightness from 0% to 100%.
callback function function(error, data) {}

Usage examples:

light.maxIR(0); // Set's a maximum infrared brightness of 0
light.maxIR(25); // Set's a maximum infrared brightness of 25

light.getMaxIR(callback)

Requests the maximum infrared brightness of the light (only for lights that support infrared light)

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  brightness: 25
}

Requesting light state and info

Infos of the state and spec of the light can be requested with the following methods:

light.getState(callback)

Requests general info from a light, this includes color, label and power state. This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  color: { hue: 120, saturation: 0, brightness: 100, kelvin: 8994 },
  power: 0,
  label: 'Kitchen'
}

light.getPower(callback)

Requests current power state (on or off). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
0 // off

light.getFirmwareVersion(callback)

Requests the firmware version from a light (minor and major version). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  majorVersion: 2,
  minorVersion: 1
}

light.getHardwareVersion(callback)

Requests the hardware version from a light (vendor, product and version). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  vendorId: 1,
  vendorName: 'LIFX',
  productId: 1,
  productName: 'Original 1000',
  version: 6,
  productFeatures: {
    color: true,
    infrared: false,
    multizone: false
  }
}

light.getFirmwareInfo(callback)

Requests info from the micro controller unit of a light (signal, tx and rx). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  signal: 0,
  tx: 0,
  rx: 0
}

light.getWifiInfo(callback)

Requests wifi info from a light (signal, tx and rx). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  signal: 0.000009999999747378752,
  tx: 16584,
  rx: 12580
}

light.getWifiVersion(callback)

Requests the wifi firmware version from the light (minor and major version). This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
{
  majorVersion: 2,
  minorVersion: 1
}

light.getAmbientLight(callback)

Requests the ambient light value in flux from the light. This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}

Example result:

null,
10

Labels

Labels of lights can be requested and set using the following methods:

light.getLabel(callback, [cache])

Requests the label of a light. This function is asynchronous.

Option Type Default Description
callback function function(error, data) {}
cache boolean false Use the last known value for the label and and do not request from the light again

Example result:

null,
'Kitchen'

light.setLabel(label, [callback])

Sets a new label for a light.

Option Type Default Description
label string New Label with 32 bit size maximum (which is a length of 32 with non unicode chars).
callback function null function(error) {} Called after the command has reached the light or after client.resendMaxTimes with client.resendPacketDelay in case it has not. error is null in case of success and given if the sending has failed.
Note: Using callback multiplies network load for this command by two or more times.

Usage examples:

light.setLabel('Bedroom Light');
light.setLabel('Kitchen Light 4', function(err) {
  if (err) { throw err; }
  console.log('New light label has been set');
});

Get a light

client.light(identifier)

Find a light in the list off all lights by ip, label or id.

Option Type Default Description
identifier  string Light label (case sensitive) client.light('Kitchen'), the ip address client.light('192.168.2.102') or the light id client.light('0123456789012')

Returns a light object that can then be used to call methods on it. For example client.light('192.168.2.102').on().

Get all lights

client.lights([filter])

Get a list of all known lights

Option Type Default Description
filter  string null Filter list of lights to return only active (null or 'on'), inactive ('off') or all ('')

Client events

The following events might be thrown by the client.

light-new

This event is thrown when there is a new light discovery that has not been seen at runtime before. This event is provided with the new light object. client.on('light-new', function(light) {});

light-offline

This event is thrown when a light hasn't been discovered for a time. The light given is no longer expected to be reachable. client.on('light-offline', function(light) {});

light-online

This event is thrown when a light is discovered again after being offline. client.on('light-online', function(light) {});

Start / Stop discovery

The discovery for each client can be started and stopped at runtime using these commands:

client.startDiscovery()

Starts the discovery process.

client.stopDiscovery()

Stops the discovery process.

Client settings

For the initialization of the client different settings can be provided. This is an example with the default options:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

// ...

client.init({
  lightOfflineTolerance: 3, // A light is offline if not seen for the given amount of discoveries
  messageHandlerTimeout: 45000, // in ms, if not answer in time an error is provided to get methods
  startDiscovery: true, // start discovery after initialization
  resendPacketDelay: 150, // delay between packages if light did not receive a packet (for setting methods with callback)
  resendMaxTimes: 3, // resend packages x times if light did not receive a packet (for setting methods with callback)
  debug: false, // logs all messages in console if turned on
  address: '0.0.0.0', // the IPv4 address to bind the udp connection to
  broadcast: '255.255.255.255', // set's the IPv4 broadcast address which is addressed to discover bulbs
  lights: [] // Can be used provide a list of known light IPv4 ip addresses if broadcast packets in network are not allowed
             // For example: ['192.168.0.112', '192.168.0.114'], this will then be addressed directly
});

node-lifx's People

Contributors

bmv437 avatar daigeb avatar devbobo avatar fkistner avatar jaredpetersen avatar jasoncodes avatar mariusrumpf avatar ristomatti avatar robinbol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-lifx's Issues

Create event for state changed of bulb

It would be great if node-lifx could emit an event when a user changes the state of a light using the mobile app for example. Right now this is not possible as far as I know. I know polling could be used but that is rather undesired.

I have tried to cook up something myself, however I could not really read the incoming traffic and check whether the needed information was actually broadcasted.

Basic : "TypeError: value is out of bounds"

Trying to get a basic hello world example running, but no joy.

I created a new project, imported the node module, and then created a file with just this in it:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.init();

Here's the error that's showing up:

TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:705:11)
    at Buffer.writeUInt8 (buffer.js:715:5)
    at Object.Packet.headerToBuffer (/Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/lib/lifx/packet.js:209:7)
    at Object.Packet.toBuffer (/Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/lib/lifx/packet.js:257:21)
    at Client.<anonymous> (/Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/lib/lifx/client.js:233:26)
    at /Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/node_modules/lodash/index.js:2874:23
    at /Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/node_modules/lodash/index.js:3049:15
    at Function.<anonymous> (/Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/node_modules/lodash/index.js:3346:13)
    at Client.send (/Users/kevin.cannon/Documents/node-lifx-helloworld/node_modules/node-lifx/lib/lifx/client.js:223:5)

I reckon it's something small. Any tips would be appreciated.

Zip file uploaded here:
https://dl.dropboxusercontent.com/u/89613/node-lifx-helloworld.zip
Any ideas?

ES6 syntax

How would I be able to import this with ES6 syntax, seeing as by default you are supposed to use a require statement like so:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.init();

How would you do this with ES6 syntax?

light.getState(), light.getLabel(), light.getHardwareVersion(), ... , time out

Using the example, the getState() and getHardwareVersion() time out, this used to work. Am I the only one experiencing this issue? Bulb is on firmware 2.1 according to the LIFX desktop firmware updater.

Keys:
Press 1 to turn the lights on
Press 2 to turn the lights off
Press 3 to turn the lights red
Press 4 to turn the lights green
Press 5 to turn the lights blue
Press 6 to turn the lights a bright bluish white
Press 7 to turn the lights a bright reddish white
Press 8 to show debug messages including network traffic
Press 9 to hide debug messages including network traffic
Press 0 to exit

Started LIFX listening on 0.0.0.0:56700

New light found.
ID: d073d501c21b
IP: 192.168.1.16:56700
[Error: No LIFX response in time]
/Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/example/example.js:14
                console.log('Label: ' + info.label);
                                            ^

TypeError: Cannot read property 'label' of null
    at /Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/example/example.js:14:31
    at Client.<anonymous> (/Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/lib/lifx/light.js:127:14)
    at Client.<anonymous> (/Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/lib/lifx/client.js:369:24)
    at Array.forEach (native)
    at Client.processMessageHandlers (/Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/lib/lifx/client.js:340:24)
    at Client.<anonymous> (/Users/robinbolscher/Development/apps/com.lifx/node_modules/node-lifx/lib/lifx/client.js:177:12)
    at emitTwo (events.js:87:13)
    at Socket.emit (events.js:172:7)
    at UDP.onMessage (dgram.js:480:8)

Library Randomly Crash

Hey there!

I have two LIFx Color 1000 bulbs (one in my bedroom and other in the living room) and a Raspberry Pi that I am running homebridge on. I haven't been able to reproduce consistently (hence randomly :p) but every now and again homebridge-lifx-lan (the developer of that plugin sent me here :p) crashes homebridge. I have a feeling however, that the issue is with the two bulbs - the power to the living room light was turned off all day and homebridge hadn't crashed at all until that light came back on. This is the error that is thrown when the crash occurs:

buffer.js:830
    throw new RangeError('Index out of range');
    ^

RangeError: Index out of range
    at checkOffset (buffer.js:830:11)
    at Buffer.readUInt16LE (buffer.js:876:5)
    at Object.Packet.headerToObject (/usr/lib/node_modules/homebridge-lifx-lan/node_modules/node-lifx/lib/lifx/packet.js:124:18)
    at Object.Packet.toObject (/usr/lib/node_modules/homebridge-lifx-lan/node_modules/node-lifx/lib/lifx/packet.js:141:14)
    at Client.<anonymous> (/usr/lib/node_modules/homebridge-lifx-lan/node_modules/node-lifx/lib/lifx/client.js:161:18)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:191:7)
    at UDP.onMessage (dgram.js:540:8)

If you need anything else from me, I'll gladly help!

getColorZones doesn't return all zones.

getColorZones states a count of 16 zones. Indexes set to 0, 15, it only returns first 8 HSBK items no matter if I ask for 2 zones or all 16.

  light.getColorZones(0, 15, (err, data) => {
    logger.debug(JSON.stringify(data))
  })
{ size: 102,
  addressable: true,
  tagged: false,
  origin: true,
  protocolVersion: 1024,
  source: 'e6b8b4ac',
  target: 'd073d5149b32',
  reserved1: <Buffer 00 00>,
  site: 'LIFXV2',
  ackRequired: false,
  resRequired: false,
  sequence: 6,
  time: <Buffer 48 90 5e 01 7f 92 c9 14>,
  type: 'stateMultiZone',
  reserved2: <Buffer 00 00>,
  count: 16,
  index: 0,
  color: 
   [ { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 },
     { hue: 9102, saturation: 65535, brightness: 65535, kelvin: 3500 } ] }

State change methods sometimes don't succeed

Hi,

I've been testing this library and I think it's really good!

However, I've observed a problem with the 'state change' methods (light.on, light.off, light.color) occasionally not succeeding. This only happens when the client has been idle for some time (e.g. running for 1 hour without being used.)

I've observed this issue using the interactive-cli.js script. I start the script and the initial tests work fine. I then leave the script running in the background for a while (e.g. 1 hour). When I come back to the script and try to turn the lights on/off or change their colour, it seems to work but nothing happens to the physical lights. When I try again the lights start responding and all seems to be OK (and sometimes it takes a few goes before the lights start to respond.)

If it's any use, here are some examples of the debugging output from interactive-cli.js.

First - here's when I tried to turn the lights off and it failed:

All lights turned off
D - 2a00001444763bb1d073d5018c4600000000000000000019000000000000000075000000000000000000 > 192.168.0.106
D - 2400003444763bb100000000000000000000000000000019000000000000000002000000 > 255.255.255.255
D - 2900005444763bb1d073d5018c4600004c49465856320019447d4aa01e841e1403000000017cdd0000 < 192.168.0.106
D - 2900005444763bb1d073d5018c4600004c4946585632001944a13ea11e841e1403000000057cdd0000 < 192.168.0.106
D - 2400003444763bb100000000000000000000000000000019000000000000000002000000 > 255.255.255.255
D - 240000340000000000000000000000000000000000000000000000000000000002000000 < 192.168.0.115
D - 2400003444763bb100000000000000000000000000000019000000000000000002000000 > 255.255.255.255
D - 2900005444763bb1d073d5018c4600004c49465856320019c431b0ef20841e1403000000017cdd0000 < 192.168.0.106
D - 2900005444763bb1d073d5018c4600004c49465856320019c455a4f020841e1403000000057cdd0000 < 192.168.0.106
D - 2400003444763bb100000000000000000000000000000019000000000000000002000000 > 255.255.255.255

Second - here's where I turned the lights off and it worked:

All lights turned off
D - 2a00001444763bb1d073d5018c460000000000000000001a000000000000000075000000000000000000 > 192.168.0.106
D - 240000340000000000000000000000000000000000000000000000000000000002000000 < 192.168.0.115
D - 2900005400000000d073d5018c4600004c49465856320000c4354bd122841e1403000000017cdd0000 < 192.168.0.106
D - 2900005400000000d073d5018c4600004c49465856320000c4593fd222841e1403000000057cdd0000 < 192.168.0.106
D - 2400003444763bb10000000000000000000000000000001a000000000000000002000000 > 255.255.255.255
D - 2400003444763bb10000000000000000000000000000001a000000000000000002000000 > 255.255.255.255
D - 2900005444763bb1d073d5018c4600004c4946585632001ac44faa6f24841e1403000000017cdd0000 < 192.168.0.106
D - 2900005444763bb1d073d5018c4600004c4946585632001ac4739e7024841e1403000000057cdd0000 < 192.168.0.106
D - 240000340000000000000000000000000000000000000000000000000000000002000000 < 192.168.0.115
D - 2900005400000000d073d5018c4600004c4946585632000004805a2625841e1403000000017cdd0000 < 192.168.0.106
D - 2900005400000000d073d5018c4600004c4946585632000004a44e2725841e1403000000057cdd0000 < 192.168.0.106
D - 2400003444763bb10000000000000000000000000000001a000000000000000002000000 > 255.255.255.255

Regards,

James.

light-online firing incorrectly

I have some code which detects when a light comes online, and its kelvin and brightness are set based on a predetermined config.

Perhaps since an iOS app update, or maybe even a light firmware update, now - whenever I interact with the app, say for example to change a light brightness - the light-online event fires. (Even though it was already online).

...meaning that my code runs (when it shouldn't be). And the brightness I just chose with the app, is then overridden.

Not working in Windows when running Docker

For whatever reason, this isn't working for me in Windows. There's no issue or error, I just don't see any clients showing up.

const fs = require('fs')
const LifxClient = require('node-lifx').Client

const client = new LifxClient()

client.on(
  'light-new',
  light => (
    light
    .getLabel(
      (_, label) => (
        console.log(
          light.address,
          '\t',
          label
        )
      )
    )
  )
)

client.init()

I'm LAN-networked, so that might have something to do with it. The LIFX Universal Windows app sees lights and will use that port so I don't think it's something in Windows itself.

Did something change or do I need to enable some setting to get this working properly in Windows?

MultiZone Packets for LIFX Z

The new LIFX Z does contain multiple lights which can be controlled individually by using MultiZone packets. In order to make use of them this has to be implemented. Documentation can be found here.

Suggested Feature: Global Functions (+ code)

I think it would be nice to have global functions on the client object, so you can do this:

client.allOff();
client.allOn();
client.allColor(55,33,99);

I needed this for my experiments, so I wrote some simple wrappers for this. Feel free to add it if it's useful. The error handling is managed well by the light methods.

in client.js

/**
 * Turns all known bulbs off
 * @return null
 */
Client.prototype.allOff = function(duration) {

  _.forEach(this.devices, function(light) {
      light.off(duration);
  });
  return null;
};

/**
 * Turns all known bulbs on
 * @return null
 */
Client.prototype.allOn = function(duration) {

  _.forEach(this.devices, function(light) {
      light.on(duration);
  });
  return null;
};

/**
 * Change hue of all bulbs
 * @return null
 */
Client.prototype.allColor = function(hue, saturation, brightness, kelvin, duration) {

  _.forEach(this.devices, function(light) {
      light.color(hue, saturation, brightness, kelvin, duration);
  });
  return null;
};

Also, I created a new commandline helloworld for myself, it's nothing special, but sharing it in case it's useful to you:
http://pastebin.com/tzqnfkdx

Multiple node-lifx client instances on the same ip address

Hey Marius,
Thanks for your hard work on this awesome library. I have a couple projects that use your package but I get an error that the port is taken when I spin up another project using the same package.

When I change the port in Client.init(), it starts fine but never receives any messages or events. Can only one instance consume messages from the bulbs on port 56700?

add light.setPower()

It would be nice to have full control over the light power instead of having only on and off methods.

node-lifx on raspberry pi

Hi,
I'm try to get this librarie working on my raspberry pi 2 (running node.js v0.10.2), but whenever I try to use it or to launch cli.js I get this error:

LIFX UDP Packet error
Trace: { [Error : getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
    at Client.<anonymous> (/home/pi/node_modules/node-lifx/lib/lifx/client.js:101:13)
    at Socket.EventEmitter.emit (events.js:95:17)
    at dgram.js:184:12
    at asyncCallback (dns.js:68:16)
    at Object.onanswer [as oncomplete] (dns.js:124:7)
LIFX error:
Error: getaddrinfo ENOTFOUND
    at errnoExeption (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

(Sorry for my english by the way)

Typo in README

The usage example for light.on([duration], [callback]) incorrectly states that the function turns off the light:

light.on(); // Turns the light off instantly
light.on(2000); // Fading the light off over two seconds

Constant disconnecting

Hey mate, im having issues with bulbs constantly going on and offline. I did try messing with config.json and changing lightOfflineTolerance=15 and resendMaxTimes= 6
Which resulted in a slight improvement. The lifx app controls them fine even when they are "offline" in homebridge. Any ideas? Really stumped.

Constants wrong for LIFX Mini Day & Night

I noticed the minimum Kelvin value is set to 2500:

{
  HSBK_MINIMUM_KELVIN: 2500,
  HSBK_DEFAULT_KELVIN: 3500,
  HSBK_MAXIMUM_KELVIN: 9000,
}

But the LIFX Mini Day & Night bulbs go down to 1500K and only up to 4000K. In this case, I think there might need to be another set of constants depending on the bulb type.

powerOn or powerOff with duration set to 0 is not instant

When I use the on() or off() methods on a bulb with a duration set to 0, than the light still seems to fade in/out over ~100-200ms.
Funny enough, when I set the brightness to 0 with a duration of 0, than it is instant.

I'm not sure if this is a 'problem' with this npm module or with the LIFX firmware itself. Any ideas?

Groups

Bulbs might be grouped together. Bulbs may be requested by group. Commands might be send to a group.

Lights no longer controllable after IP address change?

Hi,

I've been observing an issue over the last few days were if a light is powered off for sufficient time that it loses its IP address, once it is powered on again it is no longer controllable by node-lifx.

Specifically:

  1. A light is initially discovered, and can be controlled via node-lifx
  2. The light is powered off for a significant period of time (long enough to lose its IP address)
  3. The light is powered on again and is issued a new IP address
  4. The light is rediscovered by node-lifx. However, the light is no longer controllable

I can recreate this issue using the interactive_cli.js test program.

Regards,

James.

manually send a udp command to node-lifx to turn on a light

I am building a proxy for my loxone automation system, which can send simple udp commands, to use my lifx lights using your awesome library! Thanks!

I was wondering as I am running node-lifx client how do I send messages to it ? like
udp://ipaddress.local/<someMesssageToTurnOnLighWithID123abc>

It seems superfluous to add a udp listener myself ontop of the already instantiated existing udp listener in node-lifx...

Please update vulnerable dependencies

I went ahead and ran npm install and it found quite a few vulnerable packages:

found 450 vulnerabilities (239 low, 206 moderate, 4 high, 1 critical)

Running npm audit fix didn't get them all. I had to run npm audit fix --force to fix them all. It said some dependencies had breaking changes, but everything's working for me so maybe it's looking at the version number changes. Either way, GitHub also has a service where it will automatically pull-request changes to vulnerable packages.

I would love it if this library could be updated with these changes.

"LIFX bulb off method expects duration to be a number"

When I try running my code, it outputs:

"LIFX bulb off method expects duration to be a number"

I'm relatively new to node js, so I wasn't able to understand why the issue occurred. Any ideas why?

My code is as follows:

var LifxClient = require('node-lifx').Client;
var client = new LifxClient();

client.on('bulb-new', function (bulb) {
bulb.on(['1000']);
});

client.init();

Labels

Bulbs might be requested by label, labels might be changed.

IR capable lights timeout when light.getMaxIR is called

I encountered the issue while testing Node-RED node plugin node-red-contrib-node-lifx. The two of my lights were not listed on Node-RED UI even though they show up when using node-lifx directly. I tracked this down to be the cause of getMaxIR timing out and returning an error on IR capable lights (the plugin does not request the state unless the lights report the capability).

I tried to get an idea what could cause this but didn't figure it out within the time I had available today, hence reporting this as an issue. The maxIR(brightness) command seems to work ok (the new value is updated to the Android app). This might be an issue with my lights or possibly a change within the firmware? I can look into this later on.

I submitted a PR to node-red-contrib-node-lifx that prevents the issue with Node-RED though (low hanging fruit for me).

Callback for light.on + light.off?

Hi. I've started building a CLI for LIFX bulbs, utilizing your package because it has a nice API. So thanks.

I'm just wondering, would it be possible for light.on and light.off to have a callback for when the operation completes? Maybe along with a timeout as well? I'm currently using a polling approach, but it's a bit messy.

Request a package confirmation

Requesting a confirmation callback from a method is possible by using LIFX protocols acknowledgement package. This comes at cost for the performance / network when used to much but might be very useful when a library depends on a specific method before continuing a process.
The timeout option might come in a high cost of performance then and is not very useful.

Example:

light.on(3000, function(err) {
  // continue here
});

Socket error after bind fails

In node-lifx/lib/lifx/client.js if bind fails (say, because the address is in use) the error is emitted correctly. Unfortunately, later on socket.send will cause an exception during scanning because self.port is not set up correctly.

This can be fixed by moving this code

// Start scanning
if (opts.startDiscovery) {
  this.startDiscovery();
}

Inside the this.socket.bind block that immediately precedes it. e.g.

  this.socket.bind(opts.port, opts.address, function() {
    this.socket.setBroadcast(true);
    this.emit('listening');
    this.port = opts.port;
    if (typeof callback === 'function') {
      return callback();
    }

    // Start scanning
    if (opts.startDiscovery) {
      this.startDiscovery();
    }
  }.bind(this));

Bulb not found

Hi Marius,

When I run the cli.js script, I get the following output:

`Started LIFX listening on 0.0.0.0:56700

{ size: 100,
addressable: true,
tagged: false,
origin: true,
protocolVersion: 1024,
source: '42524b52',
target: 'd073d500ae66',
reserved1: ,
site: 'LIFXV2',
ackRequired: false,
resRequired: false,
sequence: 0,
time: ,
type: 'echoResponse',
reserved2: ,
payload: 'LIFX���7��=\u0014' } ' from 192.168.1.158'
{ size: 38,
addressable: true,
tagged: false,
origin: true,
protocolVersion: 1024,
source: '42524b52',
target: 'd073d500ae66',
reserved1: ,
site: 'LIFXV2',
ackRequired: false,
resRequired: false,
sequence: 0,
time: ,
type: 'stateTemperature',
reserved2: ,
temperature: 3800 } ' from 192.168.1.158'
{ size: 40,
addressable: true,
tagged: false,
origin: true,
protocolVersion: 1024,
source: '42524b52',
target: 'd073d500ae66',
reserved1: ,
site: 'LIFXV2',
ackRequired: false,
resRequired: false,
sequence: 0,
time: ,
type: 406,
reserved2: } ' from 192.168.1.158`

getAmbientLight always returns 0 on BR30+ (IR capable)

I noticed that getAmbientLight() always returns 0 for BR30+ (IR capable) lights. I tested this on 2 seperate lights. Regular A19's (Color 1000) seem to work just fine (always returning some value greater than 0).

I do believe these IR capable lights contain such a sensor just like the others do. Although I must say the only real evidence of that I could find over here: https://lan.developer.lifx.com/docs/infrared-channel-control;

In the future other metrics such as ambient light levels and the overall temperature of the bulb may also be used to adjust the Infrared channel.

Any ideas on this?

Do you need someone to take over the project?

From looking at the Git branches, there was work done to create a newer version in 2017. This work was never completed, and any merged pull request since 0.8.0 haven't been deployed to npm.

I use this software to control the lights on my home network and still think it's the best solution out there. Sadly, without these changes, updates, and security fixes, the library will eventually become useless.

Either I could take over this project myself, or I could create my own. You've gone through a considerable effort building out this library, I think rewriting it myself would be a waste of time when you've already produced a substantial amount of work.

More examples

  • Interactive example changing bulb state from commandline

Change single parts of color

The library makes use of the color method which requires hue, saturation, brightness and kelvin values. It might be useful to have a method for every single part if it, without affecting others.

For example setting different shades of white is easy with the app but complex with the library. To utilize one has to keep track of the latest color value and only change the kelvin value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.