0.5.0 • Published 3 years ago

node-lifx-lan v0.5.0

Weekly downloads
21
License
MIT
Repository
github
Last release
3 years ago

node-lifx-lan

The node-lifx-lan is a Node.js module which allows you to communicate with the Wi-Fi LED smart light products "LIFX" using the LAN protocol.

Dependencies

  • Node.js 12 +
    • Though the node-lifx-lan may work on older version of Node for now, it is strongly recommended to use Node 12 or newer. The node-lifx-lan will not support old versions of Node in the future.

Installation

$ cd ~
$ npm install node-lifx-lan

Table of Contents


Quick Start

Turn on all bulbs simultaneously

The code below turns on all LIFX bulbs in the local network.

// Create a LifxLan object
const Lifx  = require('node-lifx-lan');

// Turn on all LIFX bulbs in the local network
Lifx.turnOnBroadcast({
  color: {css: 'green'}
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Turn on bulbs satisfying a filter

The code blow turns on LIFX bulbs whose group is Room 1 in blue.

// Create a LifxLan object
const Lifx  = require('node-lifx-lan');

// Discover LIFX bulbs in the local network
Lifx.discover().then(() => {
  // Turn on LIFX bulbs whose group is `Room 1` in blue
  return Lifx.turnOnFilter({
    filters: [{
      group: {label: 'Room 1',}
    }],
    color: {css: 'blue'}
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Turn on a bulbs

The code below turns on a LIFX bulb found first in yellow.

// Create a LifxLan object
const Lifx  = require('node-lifx-lan');

// Discover LIFX bulbs in the local network
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  if(!dev) {
    throw new Error('No bulb was found.');
  }
  // Turn on a LIFX bulb found first in yellow
  return dev.turnOn({
    color: {css: 'yellow'}
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

LifxLan object

In order to use the node-lifx-lan, you have to load the node-lifx-lan module as follows:

const Lifx  = require('node-lifx-lan');

In the code snippet above, the variable Lifx is a LifxLan object. The LifxLan object has methods as described in the sections below.

discover([params]) method

The discover() method starts to scan LIFX bulbs in the local network. This method returns a Promise object. The discovery process completes successfully, a list of LifxLanDevice object will be passed to the resolve() function. The LifxLanDevice object represents a LIFX bulb.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
waitIntegerOptionalWait time of the discovery process. The unit is millisecond. The default value is 3000.

Basically you don't need to pass the wait property to this method. In most cases, the default value 3000 works well.

Lifx.discover().then((device_list) => {
  device_list.forEach((device) => {
    console.log([
      device['ip'],
      device['mac'],
      device['deviceInfo']['label']
    ].join(' | '));
  });
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

192.168.10.5 | D0:73:D5:13:96:7E | LIFX Bulb 13967e
192.168.10.2 | D0:73:D5:25:A7:28 | LIFX A19 25A728
192.168.10.4 | D0:73:D5:25:36:B0 | LIFX Pls A19 2536B0

turnOnBroadcast([params]) method

The turnOnBroadcast() method turns on all LIFX bulbs in the local network. This method sends a broadcast packet. Therefore, it turns on all bulbs pretty much simultaneously.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
colorLifxLanColorOptionala LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below turns on all LIFX bulb.

Lifx.turnOnBroadcast().then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

The code below turns on all LIFX bulbs in red with 3 seconds color transition.

Lifx.turnOnBroadcast({
  color: {css: 'red'},
  duration: 3000
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Note that this method just sends a broadcast packet, it is agnostic on the results. If you need to turn on lights in a more reliable way, it is recommended to use the turnOnFilter() method.

setColorBroadcast(params) method

The setColorBroadcast() method changes color setting on all LIFX bulbs in the local network. This method sends a broadcast packet. Therefore, it changes the color setting on all bulbs pretty much simultaneously.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
colorLifxLanColorRequireda LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below changes the color of all LIFX bulbs to blue.

Lifx.setColorBroadcast({
  color: {css: 'blue'}
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Note that this method just sends a broadcast packet, it is agnostic on the results. If you need to change the color setting in a more reliable way, it is recommended to use the setColorFilter() method.

turnOffBroadcast([params]) method

The turnOffBroadcast() method turns off all LIFX bulbs in the local network. This method sends a broadcast packet. Therefore, it turns off all bulbs pretty much simultaneously.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below turns off all LIFX bulbs with 3 seconds color transition.

Lifx.turnOffBroadcast({
  duration: 3000
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Note that this method just sends a broadcast packet, it is agnostic on the results. If you need to turn off lights in a more reliable way, it is recommended to use the turnOffFilter() method.

turnOnFilter([params]) method

The turnOnFilter() method turns on the LIFX bulbs satisfying the filters specified to this method.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
filtersArrayOptionalA list of LifxLanFilter object
colorLifxLanColorOptionalA LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

Be sure to call this method after calling the discover() method. Otherwise, no LIFX bulbs satisfying the filter will be found. That is, this method will result in error.

The code below turns on LIFX bulbs whose group is set to Room 1.

Lifx.discover().then(() => {
  return Lifx.turnOnFilter({
    filters: [{
      group: {label: 'Room 1'},
    }]
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

The LifxLanFilter object supports some types of filter. See the section "LifxLanFilter object" for more details.

If the LifxLanFilter object is not passed to this method, all LIFX bulbs recognized by the discover() method will be turned on.

Lifx.discover().then(() => {
  return Lifx.turnOnFilter();
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Though the outcome of the code above is as same as the turnOnBroadcast() method (all LIFX bulbs in the local network will be turned on), the prosess is completely different.

While the turnOnBroadcast() method just sends a broadcast packet, the turnOnFilter() method sends a packet to each devices one by one and checks responses. Though this method takes more time than the turnOnBroadcast() method, it turns on all bulbs in a more reliable way. That is, this method can let you know if an error was occurred.

setColorFilter(params) method

The setColorFilter() method changes the color of the LIFX bulbs satisfying the filters specified to this method.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
filtersArrayOptionalA list of LifxLanFilter object
colorLifxLanColorRequireda LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below changes the color of the LIFX bulbs whose label is set to LIFX Pls A19 2536B0.

Lifx.discover().then((device_list) => {
  return Lifx.setColorFilter({
    filters: [{
      label: 'LIFX Pls A19 2536B0'
    }],
    color: {css: 'green'}
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

The LifxLanFilter object supports some types of filter. See the section "LifxLanFilter object" for more details.

If the LifxLanFilter object is not passed to this method, the color settings of all LIFX bulbs recognized by the discover() method will be changed.

Lifx.discover().then((device_list) => {
  return Lifx.setColorFilter({
    color: {css: 'green'}
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Though the outcome of the code above is as same as the setColorBroadcast() method (The color settings of all LIFX bulbs in the local network will be changed), the process is completely different.

While the setColorBroadcast() method just sends a broadcast packet, the setColorFilter() method sends a packet to each devices one by one and checks responses. Though this method takes more time than the setColorBroadcast() method, it changes the color settings on all bulbs in a more reliable way. That is, this method can let you know if an error was occurred.

turnOffFilter([params]) method

The turnOffFilter() method turns off the LIFX bulbs satisfying the filters specified to this method.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
filtersArrayOptionalA list of LifxLanFilter object
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

Be sure to call this method after calling the discover() method. Otherwise, no LIFX bulbs satisfying the filter will be found. That is, this method will result in error.

The code below turns off LIFX bulbs whose group label is set to Room 1.

Lifx.discover().then(() => {
  return Lifx.turnOffFilter({
    filters: [{
      group: {label: 'Room 1'},
    }]
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

The LifxLanFilter object supports some types of filter. See the section "LifxLanFilter object" for more details.

If the LifxLanFilter object is not passed to this method, all LIFX bulbs recognized by the discover() method will be turned off.

Lifx.discover().then(() => {
  return Lifx.turnOffFilter();
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Though the outcome of the code above is as same as the turnOffBroadcast() method (all LIFX bulbs in the local network will be turned off), the prosess is completely different.

While the turnOffBroadcast() method just sends a broadcast packet, the turnOffFilter() method sends a packet to each devices one by one and checks responses. Though this method takes more time than the turnOffBroadcast() method, it turns off all bulbs in a more reliable way. That is, this method can let you know if an error was occurred.

destroy() method

The destroy() method closes the UDP socket, then disables the LifxLan object.

Once the node-lifx-lan module is loaded, the script can not finish automatically because UDP socket keeps to be open. Calling this method, the script can finish as expected.

Lifx.destroy().then(() => {
  console.log('Bye!');
}).catch((error) => {
  console.error();
});

createDevice(params) method

The createDevice() method creates a LifxLanDevice object.

The LifxLanDevice object can be obtained using the discover() method as well. However, if you have already known the IPv4 address and the MAC address of the device, this method allows you to obtain the LifxLanDevice object without the discovery process.

This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
ipStringRequiredIPv4 address. (e.g., "192.168.10.4")
macStringRequiredMAC address. (e.g., "D0:73:D5:25:36:B0")

The code below creates a LifxLanDevice object and turns on the LIFX bulb:

Lifx.createDevice({
  mac: 'D0:73:D5:25:36:B0',
  ip: '192.168.11.32'
}).then((dev) => {
  return dev.turnOn({
    color: { css: 'red' }
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

Note that the deviceInfo property in a LifxLanDevice object created by this method is set to null by default. If you want to get the device information, call the getDeviceInfo() method by yourself.


LifxLanColor object

The LifxLanColor object represents a color, which is just a hash object. It supports 4 expressions: HSB, RGB, xy/brightness, and CSS.

LifxLanColorHSB object

PropertyTypeRequiredDescription
hueFloatConditionalHue in the range of 0.0 to 1.0.
saturationFloatConditionalSaturation in the range of 0.0 to 1.0.
brightnessFloatConditionalBrightness in the range of 0.0 to 1.0.
kelvinIntegerOptionalColor temperature (°) in the range of 1500 to 9000.

When the LifxLanColorHSB object is used for the LifxLan.turnOnBroadcast(), LifxLan.turnOffBroadcast(), and LifxLan.setColorBroadcast(), the hue, saturation, and brightness properties are required. If the kelvin property is not specified, it is set to 3500.

When the LifxLanColorHSB object is used for the lightSetColor(), the hue, saturation, brightness, and kelvin properties are required.

When the LifxLanColorHSB object is used for other methods, all properties are optional.

LifxLanColorRGB object

PropertyTypeRequiredDescription
redFloatConditionalRed component in the range of 0.0 to 1.0.
greenFloatConditionalGreen component in the range of 0.0 to 1.0.
blueFloatConditionalBlue component in the range of 0.0 to 1.0.
brightnessFloatOptionalBrightness in the range of 0.0 to 1.0.
kelvinIntegerOptionalColor temperature (°) in the range of 1500 to 9000.

When the LifxLanColorRGB object is used for the LifxLan.turnOnBroadcast(), LifxLan.setColorBroadcast(), LifxLanDevice.turnOn(), and LifxLanDevice.setColor(), the red, green, and blue properties are required. If the kelvin property is not specified, it is set to 3500.

When the LifxLanColorRGB object is used for other methods, all properties are optional.

The specified RGB is converted to HSB internally. If the brightness is specified, The B component in the HSB is replaced by the value of the brightness.

LifxLanColorXyb object

PropertyTypeRequiredDescription
xFloatConditionalX value in the range of 0.0 to 1.0.
yFloatConditionalY value in the range of 0.0 to 1.0.
brightnessFloatConditionalBrightness in the range of 0.0 to 1.0.
kelvinIntegerOptionalColor temperature (°) in the range of 1500 to 9000.

When the LifxLanColorXyb object is used for the LifxLan.turnOnBroadcast(), LifxLan.turnOffBroadcast(), and LifxLan.setColorBroadcast(), the x, y, and brightness properties are required. If the kelvin property is not specified, it is set to 3500.

When the LifxLanColorXyb object is used for other methods, all properties are optional.

LifxLanColorCSS object

PropertyTypeRequiredDescription
cssStringConditionalCSS color ("red", "#ff0000", or "rgb(255, 0, 0)")
brightnessFloatOptionalBrightness in the range of 0.0 to 1.0.
kelvinIntegerOptionalColor temperature (°) in the range of 1500 to 9000.

The css property supports all of the named colors specified in the W3C CSS Color Module Level 4, such as "red", "blue", "blueviolet", etc.

In addition to the named colors, the css property supports CSS Hexadecimal color (e.g., "#ff0000") and RGB color (e.g., "rgb(255, 0, 0)"). Note that the css property does not support CSS RGBA color (e.g., "rgba(255, 0, 0, 1.0)") and HSL color (e.g., "hsl(0, 100%, 100%)") and HSLA color (e.g., "hsl(0, 100%, 100%, 1.0)").

When the LifxLanColorCSS object is used for the LifxLan.turnOnBroadcast(), LifxLan.setColorBroadcast(), LifxLanDevice.turnOn(), and LifxLanDevice.setColor(), the css property is required. If the kelvin property is not specified, it is set to 3500.

When the LifxLanColorCSS object is used for other methods, the css property is optional.

The specified CSS is converted to RGB, finally to HSB internally. If the brightness is specified, The B component in the HSB is replaced by the value of the brightness.


LifxLanFilter object

The LifxLanFilter object represents a filter, which is just a hash object. It is used for the LifxLan.turnOnFilter(), LifxLan.turnOffFilter(), and LifxLan.setColorFilter() methods.

PropertyTypeRequiredDescription
labelStringOptionalLabel of bulb
productIdIntegerOptionalProduct ID
featuresObjectOptional
+colorBooleanOptionalIf the bulb has color capability, the value is true. Otherwise, false.
+infraredBooleanOptionalIf the bulb has infrared capability, the value is true. Otherwise, false.
+multizoneBooleanOptionalIf the bulb has multizone capability, the value is true. Otherwise, false.
+chainBooleanOptionalIf the bulb has chain capability, the value is true. Otherwise, false.
groupObjectOptional
+guidStringOptionalGUID of group
+labelStringOptionalLabel of group
locationObjectOptional
+guidStringOptionalGUID of location
+labelStringOptionalLabel of location

As you can see the table above, all of the properties are optional. No LifxLanFilter means no filter. That is, all bulbs are targeted.

{
  productId: 29
}

The filter above limits to bulbs whose product ID is 29 (LIFX + A19).

You can specify multiple properties:

{
  features: {infrared: true},
  group   : {label: 'Room 1'}
}

The filter above limits to bulbs which have infrared capability AND whose group label is equivalent to Room 1. Note that multiple properties means AND condition.

The methods supporting filter takes filters as a list of the LifxLanFilter object.

Lifx.turnOnFilter({
  filters: [
    {group: {label: 'Room 1'}},
    {group: {label: 'Room 2'}}
  ]
});

Multiple LifxLanFilter objects means OR condition. The code above turns on the LIFX bulbs whose group label equivalent to Room 1 OR Room 2.


LifxLanDevice object

The LifxLanDevice object represents a LIFX bulb, which is created through the discovery process triggered by the LifxLan.discover() method. This section describes the properties and methods implemented in this object.

Properties

The LifxLanDevice object supports the properties as follows:

PropertyTypeDescription
ipStringIP address. (e.g., "192.168.10.4")
macStringMAC address. (e.g., "D0:73:D5:25:36:B0")
deviceInfoObject
+labelStringLabel of the bulb.
+vendorIdIntegerVendor ID. The value is always 1.
+productIdIntegerProduct ID. The value depends on the product.
+productNameStringProduct name. The value depends on the product.
+hwVersionIntegerHardware version number.
+featuresObject
++colorBooleanThe bulb has color capability, the value is true. Otherwise, false.
++infraredBooleanThe bulb has infrared capability, the value is true. Otherwise, false.
++multizoneBooleanThe bulb has multizone capability, the value is true. Otherwise, false.
++chainBooleanThe bulb has chain capability, the value is true. Otherwise, false.
+locationObject
++guidStringGUID of location.
++labelStringLabel of location.
++updatedDateA JavaScript Date object representing the date and time when the location was updated.
+groupObject
++guidStringGUID of group.
++labelStringLabel of group.
++updatedDateA JavaScript Date object representing the date and time when the group was updated.
+multizoneObjectIf the bulb does not have multizone capability, the value is null.
++countIntegerNumber of zone.
+chainObjectIf the bulb does not have chain capability, the value is null.
++start_indexIntegerStarting tile index.
++total_countIntegerTotal number of tiles from start_index.
++tile_devicesArrayA list of Tile objects.

The code below discovers LIFX bulbs, then shows the structure of the deviceInfo of one of the found bulbs:

Lifx.discover().then((device_list) => {
  let device = device_list[0];
  console.log(JSON.stringify(device.deviceInfo, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output as follows:

{
  "label": "LIFX Bulb 14b048",
  "vendorId": 1,
  "vendorName": "LIFX",
  "productId": 31,
  "productName": "LIFX Z",
  "hwVersion": 0,
  "features": {
    "color": true,
    "infrared": false,
    "multizone": true
  },
  "location": {
    "guid": "1ec285bd7b3bf739107d668f58f3668b",
    "label": "My Home",
    "updated": "2017-10-14T13:48:24.918Z"
  },
  "group": {
    "guid": "b4cfbfe12a8527cef9c95f159f67dfe6",
    "label": "Room 1",
    "updated": "2017-10-14T13:48:24.979Z"
  },
  "multizone": {
    "count": 16
  },
  "chain": null
}

turnOn([params]) method

The turnOn() method turns on the LIFX bulb. This method returns a Promise object. This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
colorLifxLanColorOptionalA LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below turns on the LIFX bulb in green with 3 seconds color transition:

Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.turnOn({
    color: {css: 'green'},
    duration: 3000
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

setColor(params) method

The setColor() method changes the color setting of the LIFX bulb. This method returns a Promise object. This method takes a hash object containing the properties as follows:

PropertyTypeRequredDescription
colorLifxLanColorOptionalA LifxLanColor object representing a color
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below changes the color setting of the LIFX bulb to blue with 3 seconds color transition:

Lifx.discover({wait:3000}).then((device_list) => {
  let dev = device_list[0];
  return dev.setColor({
    color: {
      hue: 0.5,
      saturation: 1.0,
      brightness: 0.3
    },
    duration: 3000
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

turnOff([params]) method

The turnOff() method turns off the LIFX bulb. This method returns a Promise object. This method takes a hash object containing the properties as follows:

PropertyTypeRequiredDescription
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

The code below turns off the LIFX bulb with 3 seconds color transition:

Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.turnOff({
    duration: 3000
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

getDeviceInfo() method

The getDeviceInfo() method fetches the device information from the LIFX bulb. This method returns a Promise object.

If the information is fetched successfully, a hash object containing the information will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
labelStringLabel of the bulb.
vendorIdIntegerVendor ID. The value is always 1.
productIdIntegerProduct ID. The value depends on the product.
productNameStringProduct name. The value depends on the product.
hwVersionIntegerHardware version number.
featuresObject
+colorBooleanThe bulb has color capability, the value is true. Otherwise, false.
+infraredBooleanThe bulb has infrared capability, the value is true. Otherwise, false.
+multizoneBooleanThe bulb has multizone capability, the value is true. Otherwise, false.
locationObject
+guidStringGUID of location.
+labelStringLabel of location.
+updatedDateA JavaScript Date object representing the date and time when the location was updated.
groupObject
+guidStringGUID of group.
+labelStringLabel of group.
+updatedDateA JavaScript Date object representing the date and time when the group was updated.
multizoneObjectIf the bulb does not have multizone capability, the value is null.
+countIntegerNumber of zone.
chainObjectIf the bulb does not have chain capability, the value is null.
+start_indexIntegerStarting tile index.
+total_countIntegerTotal number of tiles from start_index.
+tile_devicesArrayA list of Tile objects.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.getDeviceInfo();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "label": "LIFX Bulb 14b048",
  "vendorId": 1,
  "vendorName": "LIFX",
  "productId": 31,
  "productName": "LIFX Z",
  "hwVersion": 0,
  "features": {
    "color": true,
    "infrared": false,
    "multizone": true,
    "chain": false
  },
  "location": {
    "guid": "1ec285bd7b3bf739107d668f58f3668b",
    "label": "My Home",
    "updated": "2017-10-14T13:48:24.918Z"
  },
  "group": {
    "guid": "b4cfbfe12a8527cef9c95f159f67dfe6",
    "label": "Room 1",
    "updated": "2017-10-14T13:48:24.979Z"
  },
  "multizone": {
    "count": 16
  },
  "chain": null
}

getLightState() method

The getLightState() method fetches the current state of the LIFX bulb. This method returns a Promise object.

If the information is fetched successfully, a hash object containing the information will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
colorObject
+hueFloatHue in the range of 0.0 to 1.0.
+saturationFloatSaturation in the range of 0.0 to 1.0.
+brightnessFloatBrightness in the range of 0.0 to 1.0.
+kelvinIntegerColor temperature (°) in the range of 1500 to 9000.
powerIntegerIf the bulb is turned on, the value is true. Otherwise, the value is false.
labelStringThe label of the bulb.
infraredObjectIf the bulb does not have infrared capability, the value is null.
+brightnessFloatInfrared brightness in the range of 0.0 to 1.0.
multizoneObjectIf the bulb does not have multizone capability, the value is null.
+countIntegerNumber of zone.
+colorsArray
++hueFloatHue in the range of 0.0 to 1.0.
++saturationFloatSaturation in the range of 0.0 to 1.0.
++brightnessFloatBrightness in the range of 0.0 to 1.0.
++kelvinIntegerColor temperature (°) in the range of 1500 to 9000.
chainObjectIf the bulb does not have chain capability, the value is null.
+countIntegerNumber of chained devices.
+colorsArrayArrayArray of device color arrays.
+++hueFloatHue in the range of 0.0 to 1.0.
+++saturationFloatSaturation in the range of 0.0 to 1.0.
+++brightnessFloatBrightness in the range of 0.0 to 1.0.
+++kelvinIntegerColor temperature (°) in the range of 1500 to 9000.

The code below shows the state of the LIFX bulb:

Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.getLightState();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "color": {
    "hue": 0,
    "saturation": 1,
    "brightness": 1,
    "kelvin": 3500
  },
  "power": 1,
  "label": "LIFX bulb 14b048",
  "infrared": null,
  "multizone": {
    "count": 16,
    "colors": [
      {
        "hue": 0,
        "saturation": 1,
        "brightness": 1,
        "kelvin": 3500
      },
      {
        "hue": 0,
        "saturation": 1,
        "brightness": 1,
        "kelvin": 3500
      },
      ...
    ]
  }
}

Low level methods in the LifxLanDevice object

Other than the methods described above, the LifxLanDevice has low-level methods. The low-level methods based on the command packets specified in the LIFX Lan Protocol. Each command is assigned to a method. Actually, the high-level methods described above are just a combination of some low-level methods. Using the low-level methods, you can develop more sophisticated actions.

deviceGetService() method

The deviceGetService() method fetches the service information exposed by the bulb [GetService - 2]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateService - 3]:

PropertyTypeDescription
serviceIntegerThe value is always 1 which means UDP.
portIntegerUDP port number.

Actually, the result of this method is useless. This command is usually used for the discovery process.

Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetService();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "service": 1,
  "port": 56700
}

deviceGetHostInfo() method

The deviceGetHostInfo() method fetches the host MCU information exposed by the bulb [GetHostInfo - 12]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateHostInfo - 13]:

PropertyTypeDescription
signalIntegerRadio receive signal strength in milliWatts.
txIntegerBytes transmitted since power on.
rxIntegerBytes received since power on.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetHostInfo();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

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

deviceGetHostFirmware() method

The deviceGetHostFirmware() method fetches the host MCU firmware information exposed by the bulb [GetHostFirmware - 14]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateHostFirmware - 15]:

PropertyTypeDescription
buildDateFirmware build time
versionIntegerFirmware version.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetHostFirmware();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "build": "2017-08-09T00:12:50.000Z",
  "version": 65558
}

deviceGetWifiInfo() method

The deviceGetWifiInfo() method fetches the Wifi subsystem information exposed by the bulb [GetWifiInfo - 16]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateWifiInfo - 17]:

PropertyTypeDescription
signalIntegerRadio receive signal strength in milliWatts.
txIntegerBytes transmitted since power on.
rxIntegerBytes received since power on.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetWifiInfo();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "signal": 46,
  "tx": 2158016404,
  "rx": 2158016404
}

deviceGetWifiFirmware() method

The deviceGetWifiFirmware() method fetches the Wifi subsystem information exposed by the bulb [GetWifiFirmware - 18]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateWifiFirmware - 19]:

PropertyTypeDescription
buildDateFirmware build time
versionIntegerFirmware version.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetWifiFirmware();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "build": "1970-01-01T00:00:00.000Z",
  "version": 0
}

deviceGetPower() method

The deviceGetPower() method fetches the power status exposed by the bulb [GetPower - 20]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StatePower - 22]:

PropertyTypeDescription
levelIntegerIf the bulb is powered on, the value is 1. Otherwise, the value is 0.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetPower();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "level": 1
}

deviceSetPower(params) method

The deviceSetPower() method set the device power level [SetPower - 21]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
levelIntegerRequired0 (off) or 1 (on).
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceSetPower({
    level: 1
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

deviceGetLabel() method

The deviceGetLabel() method fetches the device label exposed by the bulb [GetLabel - 23]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateLabel - 25]:

PropertyTypeDescription
labelStringDevice label.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetLabel();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "label": "LIFX Pls A19 2536B0"
}

deviceSetLabel(params) method

The deviceSetLabel() method set the device label text [SetLabel - 24]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
labelStringRequiredDevice label text (up to 32 bytes in UTF-8 encoding).
Lifx.discover().then((device_list) => {
  dev = device_list[0];
  return dev.deviceSetLabel({
    label: 'My desk light'
  });
}).then((res) => {
  console.log('done!');
}).catch((error) => {
  console.error(error);
});

deviceGetVersion() method

The deviceGetVersion() method fetches the device label exposed by the bulb [GetVersion - 32]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateVersion - 33]:

PropertyTypeDescription
vendorIdIntegerVendor ID.
vendorNameStringVendor name.
productIdIntegerProduct ID.
productNameStringProduct name.
hwVersionIntegerHardware version.
featuresObject
+colorBooleanIf the bulb has color capability, the value is true. Otherwise, the value is false.
+infraredBooleanIf the bulb has infrared capability, the value is true. Otherwise, the value is false.
+multizoneBooleanIf the bulb has multizone capability, the value is true. Otherwise, the value is false.
+chainBooleanIf the bulb has chain capability, the value is true. Otherwise, the value is false.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetVersion();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "vendorId": 1,
  "vendorName": "LIFX",
  "productId": 29,
  "productName": "LIFX+ A19",
  "hwVersion": 0,
  "features": {
    "color": true,
    "infrared": true,
    "multizone": false,
    "chain": false
  }
}

deviceGetInfo() method

The deviceGetInfo() method fetches the run-time information exposed by the bulb [GetInfo - 34]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateInfo - 35]:

PropertyTypeDescription
timeDateCueent time.
uptimeIntegerTime since last power on (relative time in millisecond)
downtimeIntegerLast power off period, 5 second accuracy (in millisecond)
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetInfo();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "time": "2017-10-21T01:55:21.090Z",
  "uptime": 38843404,
  "downtime": 0
}

deviceGetLocation() method

The deviceGetLocation() method fetches the location information exposed by the bulb [GetLocation - 48]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateLocation - 50]:

PropertyTypeDescription
guidStringGUID of location.
labelStringLabel of location.
updatedDateUTC timestamp of last label update.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetLocation();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "guid": "1ec285bd7b3bf739107d668f58f3668b",
  "label": "My Home",
  "updated": "2017-10-14T13:48:24.918Z"
}

deviceSetLocation(params) method

The deviceSetLocation() method set the device location [SetLocation - 49]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
locationStringOptionalGUID of location (16 bytes hex representation). If this property is not specified, this method generates a rondom GUID.
labelStringRequiredText label for location (up to 32 bytes in UTF-8 encoding)
updatedDateOptionalUTC timestamp of last label update. If this property is not specified, this method set this value to the current time.
Lifx.discover().then((device_list) => {
  dev = device_list[0];
  return dev.deviceSetLocation({
    label: 'My Studio',
  });
}).then((res) => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

deviceGetGroup() method

The deviceGetGroup() method fetches the location information exposed by the bulb [GetGroup - 51]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StateGroup - 53]:

PropertyTypeDescription
guidStringGUID of group.
labelStringLabel of group.
updatedDateUTC timestamp of last group update.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceGetGroup();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "guid": "b4cfbfe12a8527cef9c95f159f67dfe6",
  "label": "Room 1",
  "updated": "2017-10-14T13:48:24.979Z"
}

deviceSetGroup(params) method

The deviceSetGroup() method set the device group [SetGroup - 52]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
groupStringOptionalGUID of group (16 bytes hex representation). If this property is not specified, this method generates a rondom GUID.
labelStringRequiredText label for group (up to 32 bytes in UTF-8 encoding)
updatedDateOptionalUTC timestamp of last label update. If this property is not specified, this method set this value to the current time.
Lifx.discover().then((device_list) => {
  dev = device_list[0];
  return dev.deviceSetGroup({
    label: 'My Desk'
  });
}).then((res) => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

deviceEchoRequest() method

The deviceEchoRequest() method requests a text echo-back to the bulb [EchoRequest - 58]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
textStringRequiredAn arbitrary string (up to 64 bytes in UTF-8 encoding)

Note that this method accepts only text though the LIFX LAN protocol specification says that you can send binary data,

If this method send a request successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [EchoResponse - 59]:

PropertyTypeDescription
textStringThe text echoed back by the bulb.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.deviceEchoRequest({
    text: 'Bonjour, ça va bien ?'
  });
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "text": "Bonjour, ça va bien ?"
}

lightGet() method

The lightGet() method fetches the light state exposed by the bulb [Get - 101]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [State - 107]:

PropertyTypeDescription
colorLifxLanColorHSBHSB color information.
powerInteger0 (off) or 1 (on)
labelStringText label of the bulb.
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.lightGet();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "color": {
    "hue": 0.66407,
    "saturation": 1,
    "brightness": 1,
    "kelvin": 3500
  },
  "power": 1,
  "label": "LIFX A19 25A728"
}

lightSetColor() method

The lightSetColor() method changes the light state [SetColor - 102]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
colorLifxLanColorHSBRequiredHSB color information.
durationIntegerOptionalColor transition time in milliseconds. The default value is 0.

Note that hue, saturation, brightness, and kelvin properties in the LifxLanColorHSB are all required in this method.

Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.lightSetColor({
    color   : {
      hue        : 0.16,
      saturation : 1.0,
      brightness : 1.0,
      kelvin     : 5000
    },
    duration: 1.0
  });
}).then((res) => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

lightSetWaveform() method

The lightSetWaveform() method apples an waveform effect to the bulb [SetWaveform - 103]. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequredDescription
transientIntegerRequired0 or 1. If the value is 0, the color will stay as the new color after the effect is performed. If the value is 1, the color will return to the original color after the effect.
colorLifxLanColorHSBRequiredHSB color information.
periodIntegerRequiredDuration of a cycle in milliseconds.
cyclesFloatRequiredNumber of cycles.
skew_ratioFloatConditional0.0 - 1.0. Required only when the waveform is 4 (PULSE).
waveformIntegerRequired0: SAW, 1: SINE, 2: HALF_SINE, 3: TRIANGLE, 4: PULSE.

Note that hue, saturation, brightness, and kelvin properties in the LifxLanColorHSB are all required in this method.

See the LIFX official page for more information on waveforms.

Lifx.discover({wait:3000}).then((device_list) => {
  dev = device_list[0];
  // Set the color to yellow
  return dev.lightSetColor({
    color   : {
      hue        : 0.16,
      saturation : 1.0,
      brightness : 1.0,
      kelvin     : 3500
    },
    duration: 0.0
  });
}).then(() => {
  // Set the waveform effect
  return dev.lightSetWaveform({
    transient  : 1,
    color      : { // Red
      hue        : 1.0,
      saturation : 1.0,
      brightness : 1.0,
      kelvin     : 3500
    },
    period     : 10000,
    cycles     : 10,
    waveform   : 1 // SINE
  });
}).then(() => {
  console.log('Done!');
}).catch((error) => {
  console.error(error);
});

lightGetPower() method

The lightGetPower() method fetches the power level exposed by the bulb [GetPower - 116]. This method returns a Promise object.

If this method fetches the information successfully, a hash object will be passed to the resolve() function. The hash object contains the properties as follows [StatePower - 118]:

PropertyTypeDescription
levelInteger0 (off) or 1 (on)
Lifx.discover().then((device_list) => {
  let dev = device_list[0];
  return dev.lightGetPower();
}).then((res) => {
  console.log(JSON.stringify(res, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "level": 1
}

lightSetPower(params) method

The `lightSetPo

0.5.0

3 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

7 years ago