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.
- 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.
$ cd ~
$ npm install node-lifx-lan
- Quick Start
LifxLan
objectLifxLanColor
objectLifxLanFilter
objectLifxLanDevice
object- Low level methods in the
LifxLanDevice
object- deviceGetService() method
- deviceGetHostInfo() method
- deviceGetHostFirmware() method
- deviceGetWifiInfo() method
- deviceGetWifiFirmware() method
- deviceGetPower() method
- deviceSetPower() method
- deviceGetLabel() method
- deviceSetLabel() method
- deviceGetVersion() method
- deviceGetInfo() method
- deviceGetLocation() method
- deviceSetLocation() method
- deviceGetGroup() method
- deviceSetGroup() method
- deviceEchoRequest() method
- lightGet() method
- lightSetColor() method
- lightSetWaveform() method
- lightGetPower() method
- lightSetPower() method
- lightGetInfrared() method
- lightSetInfrared() method
- multiZoneSetColorZones() method
- multiZoneGetColorZones() method
- multiZoneSetEffect() method
- tileGetDeviceChain() method
- tileSetUserPosition() method
- tileGetTileState64() method
- tileSetTileState64() method
- tileGetTiles() method
- tileGetTilesAndBounds() method
- Release Note
- References
- License
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);
});
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);
});
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);
});
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.
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:
Property | Type | Requred | Description |
---|---|---|---|
wait |
Integer | Optional | Wait 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
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:
Property | Type | Requred | Description |
---|---|---|---|
color |
LifxLanColor |
Optional | a LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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.
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:
Property | Type | Requred | Description |
---|---|---|---|
color |
LifxLanColor |
Required | a LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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.
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:
Property | Type | Requred | Description |
---|---|---|---|
duration |
Integer | Optional | Color 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.
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:
Property | Type | Requred | Description |
---|---|---|---|
filters |
Array | Optional | A list of LifxLanFilter object |
color |
LifxLanColor |
Optional | A LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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.
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:
Property | Type | Requred | Description |
---|---|---|---|
filters |
Array | Optional | A list of LifxLanFilter object |
color |
LifxLanColor |
Required | a LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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.
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:
Property | Type | Requred | Description |
---|---|---|---|
filters |
Array | Optional | A list of LifxLanFilter object |
duration |
Integer | Optional | Color 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.
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();
});
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:
Property | Type | Requred | Description |
---|---|---|---|
ip |
String | Required | IPv4 address. (e.g., "192.168.10.4" ) |
mac |
String | Required | MAC 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.
The LifxLanColor
object represents a color, which is just a hash object. It supports 4 expressions: HSB, RGB, xy/brightness, and CSS.
Property | Type | Required | Description |
---|---|---|---|
hue |
Float | Conditional | Hue in the range of 0.0 to 1.0. |
saturation |
Float | Conditional | Saturation in the range of 0.0 to 1.0. |
brightness |
Float | Conditional | Brightness in the range of 0.0 to 1.0. |
kelvin |
Integer | Optional | Color 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.
Property | Type | Required | Description |
---|---|---|---|
red |
Float | Conditional | Red component in the range of 0.0 to 1.0. |
green |
Float | Conditional | Green component in the range of 0.0 to 1.0. |
blue |
Float | Conditional | Blue component in the range of 0.0 to 1.0. |
brightness |
Float | Optional | Brightness in the range of 0.0 to 1.0. |
kelvin |
Integer | Optional | Color 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
.
Property | Type | Required | Description |
---|---|---|---|
x |
Float | Conditional | X value in the range of 0.0 to 1.0. |
y |
Float | Conditional | Y value in the range of 0.0 to 1.0. |
brightness |
Float | Conditional | Brightness in the range of 0.0 to 1.0. |
kelvin |
Integer | Optional | Color 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.
Property | Type | Required | Description |
---|---|---|---|
css |
String | Conditional | CSS color ("red" , "#ff0000" , or "rgb(255, 0, 0)" ) |
brightness |
Float | Optional | Brightness in the range of 0.0 to 1.0. |
kelvin |
Integer | Optional | Color 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
.
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.
Property | Type | Required | Description |
---|---|---|---|
label |
String | Optional | Label of bulb |
productId |
Integer | Optional | Product ID |
features |
Object | Optional | |
+color |
Boolean | Optional | If the bulb has color capability, the value is true . Otherwise, false . |
+infrared |
Boolean | Optional | If the bulb has infrared capability, the value is true . Otherwise, false . |
+multizone |
Boolean | Optional | If the bulb has multizone capability, the value is true . Otherwise, false . |
+chain |
Boolean | Optional | If the bulb has chain capability, the value is true . Otherwise, false . |
group |
Object | Optional | |
+guid |
String | Optional | GUID of group |
+label |
String | Optional | Label of group |
location |
Object | Optional | |
+guid |
String | Optional | GUID of location |
+label |
String | Optional | Label 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
.
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.
The LifxLanDevice
object supports the properties as follows:
Property | Type | Description |
---|---|---|
ip |
String | IP address. (e.g., "192.168.10.4" ) |
mac |
String | MAC address. (e.g., "D0:73:D5:25:36:B0" ) |
deviceInfo |
Object | |
+label |
String | Label of the bulb. |
+vendorId |
Integer | Vendor ID. The value is always 1 . |
+productId |
Integer | Product ID. The value depends on the product. |
+productName |
String | Product name. The value depends on the product. |
+hwVersion |
Integer | Hardware version number. |
+features |
Object | |
++color |
Boolean | The bulb has color capability, the value is true . Otherwise, false . |
++infrared |
Boolean | The bulb has infrared capability, the value is true . Otherwise, false . |
++multizone |
Boolean | The bulb has multizone capability, the value is true . Otherwise, false . |
++chain |
Boolean | The bulb has chain capability, the value is true . Otherwise, false . |
+location |
Object | |
++guid |
String | GUID of location. |
++label |
String | Label of location. |
++updated |
Date |
A JavaScript Date object representing the date and time when the location was updated. |
+group |
Object | |
++guid |
String | GUID of group. |
++label |
String | Label of group. |
++updated |
Date |
A JavaScript Date object representing the date and time when the group was updated. |
+multizone |
Object | If the bulb does not have multizone capability, the value is null . |
++count |
Integer | Number of zone. |
+chain |
Object | If the bulb does not have chain capability, the value is null . |
++start_index |
Integer | Starting tile index. |
++total_count |
Integer | Total number of tiles from start_index . |
++tile_devices |
Array | A 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
}
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:
Property | Type | Requred | Description |
---|---|---|---|
color |
LifxLanColor |
Optional | A LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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);
});
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:
Property | Type | Requred | Description |
---|---|---|---|
color |
LifxLanColor |
Optional | A LifxLanColor object representing a color |
duration |
Integer | Optional | Color 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);
});
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:
Property | Type | Required | Description |
---|---|---|---|
duration |
Integer | Optional | Color 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);
});
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:
Property | Type | Description |
---|---|---|
label |
String | Label of the bulb. |
vendorId |
Integer | Vendor ID. The value is always 1 . |
productId |
Integer | Product ID. The value depends on the product. |
productName |
String | Product name. The value depends on the product. |
hwVersion |
Integer | Hardware version number. |
features |
Object | |
+color |
Boolean | The bulb has color capability, the value is true . Otherwise, false . |
+infrared |
Boolean | The bulb has infrared capability, the value is true . Otherwise, false . |
+multizone |
Boolean | The bulb has multizone capability, the value is true . Otherwise, false . |
location |
Object | |
+guid |
String | GUID of location. |
+label |
String | Label of location. |
+updated |
Date |
A JavaScript Date object representing the date and time when the location was updated. |
group |
Object | |
+guid |
String | GUID of group. |
+label |
String | Label of group. |
+updated |
Date |
A JavaScript Date object representing the date and time when the group was updated. |
multizone |
Object | If the bulb does not have multizone capability, the value is null . |
+count |
Integer | Number of zone. |
chain |
Object | If the bulb does not have chain capability, the value is null . |
+start_index |
Integer | Starting tile index. |
+total_count |
Integer | Total number of tiles from start_index . |
+tile_devices |
Array | A 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
}
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:
Property | Type | Description |
---|---|---|
color |
Object | |
+hue |
Float | Hue in the range of 0.0 to 1.0. |
+saturation |
Float | Saturation in the range of 0.0 to 1.0. |
+brightness |
Float | Brightness in the range of 0.0 to 1.0. |
+kelvin |
Integer | Color temperature (°) in the range of 1500 to 9000. |
power |
Integer | If the bulb is turned on, the value is true . Otherwise, the value is false . |
label |
String | The label of the bulb. |
infrared |
Object | If the bulb does not have infrared capability, the value is null . |
+brightness |
Float | Infrared brightness in the range of 0.0 to 1.0. |
multizone |
Object | If the bulb does not have multizone capability, the value is null . |
+count |
Integer | Number of zone. |
+colors |
Array | |
++hue |
Float | Hue in the range of 0.0 to 1.0. |
++saturation |
Float | Saturation in the range of 0.0 to 1.0. |
++brightness |
Float | Brightness in the range of 0.0 to 1.0. |
++kelvin |
Integer | Color temperature (°) in the range of 1500 to 9000. |
chain |
Object | If the bulb does not have chain capability, the value is null . |
+count |
Integer | Number of chained devices. |
+colors |
Array[Array] | Array of device color arrays. |
+++hue |
Float | Hue in the range of 0.0 to 1.0. |
+++saturation |
Float | Saturation in the range of 0.0 to 1.0. |
+++brightness |
Float | Brightness in the range of 0.0 to 1.0. |
+++kelvin |
Integer | Color 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
},
...
]
}
}
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.
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]:
Property | Type | Description |
---|---|---|
service |
Integer | The value is always 1 which means UDP. |
port |
Integer | UDP 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
}
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]:
Property | Type | Description |
---|---|---|
signal |
Integer | Radio receive signal strength in milliWatts. |
tx |
Integer | Bytes transmitted since power on. |
rx |
Integer | Bytes 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
}
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]:
Property | Type | Description |
---|---|---|
build |
Date |
Firmware build time |
version |
Integer | Firmware 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
}
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]:
Property | Type | Description |
---|---|---|
signal |
Integer | Radio receive signal strength in milliWatts. |
tx |
Integer | Bytes transmitted since power on. |
rx |
Integer | Bytes 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
}
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]:
Property | Type | Description |
---|---|---|
build |
Date |
Firmware build time |
version |
Integer | Firmware 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
}
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]:
Property | Type | Description |
---|---|---|
level |
Integer | If 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
}
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:
Property | Type | Requred | Description |
---|---|---|---|
level |
Integer | Required | 0 (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);
});
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]:
Property | Type | Description |
---|---|---|
label |
String | Device 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"
}
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:
Property | Type | Requred | Description |
---|---|---|---|
label |
String | Required | Device 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);
});
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]:
Property | Type | Description |
---|---|---|
vendorId |
Integer | Vendor ID. |
vendorName |
String | Vendor name. |
productId |
Integer | Product ID. |
productName |
String | Product name. |
hwVersion |
Integer | Hardware version. |
features |
Object | |
+color |
Boolean | If the bulb has color capability, the value is true . Otherwise, the value is false . |
+infrared |
Boolean | If the bulb has infrared capability, the value is true . Otherwise, the value is false . |
+multizone |
Boolean | If the bulb has multizone capability, the value is true . Otherwise, the value is false . |
+chain |
Boolean | If 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
}
}
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]:
Property | Type | Description |
---|---|---|
time |
Date |
Cueent time. |
uptime |
Integer | Time since last power on (relative time in millisecond) |
downtime |
Integer | Last 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
}
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]:
Property | Type | Description |
---|---|---|
guid |
String | GUID of location. |
label |
String | Label of location. |
updated |
Date |
UTC 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"
}
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:
Property | Type | Requred | Description |
---|---|---|---|
location |
String | Optional | GUID of location (16 bytes hex representation). If this property is not specified, this method generates a rondom GUID. |
label |
String | Required | Text label for location (up to 32 bytes in UTF-8 encoding) |
updated |
Date |
Optional | UTC 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);
});
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]:
Property | Type | Description |
---|---|---|
guid |
String | GUID of group. |
label |
String | Label of group. |
updated |
Date |
UTC 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"
}
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:
Property | Type | Requred | Description |
---|---|---|---|
group |
String | Optional | GUID of group (16 bytes hex representation). If this property is not specified, this method generates a rondom GUID. |
label |
String | Required | Text label for group (up to 32 bytes in UTF-8 encoding) |
updated |
Date |
Optional | UTC 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);
});
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:
Property | Type | Requred | Description |
---|---|---|---|
text |
String | Required | An 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]:
Property | Type | Description |
---|---|---|
text |
String | The 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 ?"
}
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]:
Property | Type | Description |
---|---|---|
color |
LifxLanColorHSB |
HSB color information. |
power |
Integer | 0 (off) or 1 (on) |
label |
String | Text 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"
}
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:
Property | Type | Requred | Description |
---|---|---|---|
color |
LifxLanColorHSB |
Required | HSB color information. |
duration |
Integer | Optional | Color 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);
});
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:
Property | Type | Requred | Description |
---|---|---|---|
transient |
Integer | Required | 0 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. |
color |
LifxLanColorHSB |
Required | HSB color information. |
period |
Integer | Required | Duration of a cycle in milliseconds. |
cycles |
Float | Required | Number of cycles. |
skew_ratio |
Float | Conditional | 0.0 - 1.0 . Required only when the waveform is 4 (PULSE). |
waveform |
Integer | Required | 0 : 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);
});
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]:
Property | Type | Description |
---|---|---|
level |
Integer | 0 (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
}
The lightSetPower()
method changes the power level [SetPower - 117]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Requred | Description |
---|---|---|---|
level |
Integer | Required | 0 (off) or 1 (on) |
duration |
Integer | Optional | Power level transition time in milliseconds. The default value is 0 . |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.lightSetPower({
level: 1,
duration: 3000
});
}).then((res) => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The lightGetInfrared()
method fetches the current maximum power level of the Infrared channel exposed by the bulb [GetInfrared - 120]. 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 [StateInfrared - 121]:
Property | Type | Description |
---|---|---|
brightness |
Float | Brightness for the infrared channel (0.0 - 1.0). |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.lightGetInfrared();
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result as follows:
{
"brightness": 1
}
The lightSetInfrared()
method alters the current maximum brightness for the infrared channel [SetInfrared - 122]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Requred | Description |
---|---|---|---|
brightness |
Float | Brightness for the infrared channel (0.0 - 1.0). |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.lightSetInfrared({
brightness: 1.0
});
}).then((res) => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The multiZoneSetColorZones()
method changes the color of either a single or multiple zones [SetColorZones - 501]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Requred | Description |
---|---|---|---|
start |
Integer | Required | Start index of zone (0 - 127). |
end |
Integer | Required | End index of zone (0 - 127). |
color |
LifxLanColor |
Required | Color of the zone(s) |
duration |
Integer | Optional | Color transition time in milliseconds. The default value is 0 . |
apply |
Integer | Optional | 0 : NO_APPLY, 1 : APPLY (default), 2 : APPLY_ONLY |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.multiZoneSetColorZones({
start : 0,
end : 7,
color : {
hue : 0.35,
saturation : 1.0,
brightness : 1.0,
kelvin : 3500
},
duration : 0,
apply : 1
});
}).then((res) => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The multiZoneGetColorZones()
method fetches the zone colors for a range of zones exposed by the bulb [GetColorZones - 502]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Requred | Description |
---|---|---|---|
start |
Integer | Required | Start index of zone (0 - 127). |
end |
Integer | Required | End index of zone (0 - 127). |
If the value of the start
is less than the end
and this method fetches the information successfully, a hash object will be passed to the resolve()
function. The hash object contains the properties as follows [StateMultiZone - 506]:
Property | Type | Description |
---|---|---|
count |
Integer | The count of the total number of zones available on the device |
index |
Integer | The index of colors[0] . |
colors |
Array | A list of the LifxLanColorHSB object. |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.multiZoneGetColorZones({
start : 0,
end : 7
});
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result as follows:
{
"count": 16,
"index": 0,
"colors": [
{
"hue": 0,
"saturation": 1,
"brightness": 1,
"kelvin": 3500
},
{
"hue": 0,
"saturation": 1,
"brightness": 1,
"kelvin": 3500
},
...
]
}
Note that the actual number of elements in the colors
is 8.
If the value of the start
is equivalent to the end
and this method fetches the information successfully, a hash object will be passed to the resolve()
function. The hash object contains the properties as follows [StateZone - 503]:
Property | Type | Description |
---|---|---|
count |
Integer | The count of the total number of zones available on the device |
index |
Integer | The index of colors[0] . |
color |
LifxLanColorHSB |
HSB color information. |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.multiZoneGetColorZones({
start : 3,
end : 3
});
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output the result as follows:
{
"count": 16,
"index": 3,
"color": {
"hue": 0,
"saturation": 1,
"brightness": 1,
"kelvin": 3500
}
}
The multiZoneSetEffect()
method sets the firmware effect to display on a multizone device [SetMultiZoneEffect - 508]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Requred | Description |
---|---|---|---|
type |
Integer | Required | 0 : OFF, 1 : MOVE |
speed |
Integer | Required | Time in milliseconds for a complete animation cycle to occur |
duration |
Integer | Optional | Duration of effect in milliseconds. The default value is 0 a.k.a. infinite |
direction |
Integer | Optional | 0 : TOWARDS, 1 : AWAY |
Lifx.discover().then((device_list) => {
let dev = device_list[0];
return dev.multiZoneSetEffect({
type : 1,
speed : 1000,
duration : 0,
direction : 1
});
}).then((res) => {
console.log('Done!');
}).catch((error) => {
console.error(error);
});
The tileGetDeviceChain()
method returns information about the tiles in the chain [GetDeviceChain - 701]. 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 [StateDeviceChain - 702]:
Property | Type | Description |
---|---|---|
start_index |
Integer | Starting tile index |
tile_devices |
Array | A list of Tile objects |
total_count |
Integer | Total number of tiles from start_index |
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileGetDeviceChain();
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch(console.error);
The code above will output results as follows:
{
"start_index": 0,
"tile_devices": [
{
"accel_meas_x": 138,
"accel_meas_y": -86,
"accel_meas_z": 2054,
"user_x": 0,
"user_y": 0,
"width": 8,
"height": 8,
"device_version_vendor": 1,
"device_version_product": 55,
"device_version_version": 10,
"firmware_build": "1548977726000000000n",
"firmware_version_minor": 50,
"firmware_version_major": 3
},
...
],
"total_count": 5
}
Note that the actual number of elements in the tile_devices
array is 16.
As calling discover()
automatically retrieves chain
information for all relevant devices, the previous example could also be rewritten as follows to output the same information:
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
let chain = dev.deviceInfo.chain
console.log(JSON.stringify(chain, null, ' '));
}).catch(console.error);
The tileSetUserPosition()
method updates tile position offsets [SetUserPosition - 703]. This method returns a Promise
object.
⚠️ Warning!
Make sure you have read and fully understand the Tile Control documentation before setting these values, as doing so may greatly upset users if you get it wrong.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Required | Description |
---|---|---|---|
tile_index |
Integer | Required | Tile chain index |
user_x |
Float | Required | Horizontal tile offset |
user_y |
Float | Required | Vertical tile offset |
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileSetUserPosition({
tile_index: 0,
user_x: -0.5,
user_y: 1
});
}).then((res) => {
console.log('Done!');
}).catch(console.error);
The tileGetTileState64()
method returns the state of length
number of tiles starting from tile_index
[GetTileState64 - 707]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Required | Description |
---|---|---|---|
tile_index |
Integer | Required | Starting tile index |
length |
Integer | Optional | Tiles retrieved from/including tile_index (default: 1 ) |
x |
Integer | Optional | (default: 0 ) |
y |
Integer | Optional | (default: 0 ) |
width |
Integer | Optional | (default: 8 ) |
Note: While
x
,y
andwidth
properties are provided, the LIFX documentation states it only makes sense to setx
andy
to0
, and width to8
.
If this method fetches the information successfully, an array of hash objects—separate responses from each tile—will be passed to the resolve() function. Each hash object contains the following properties [StateTileState64 - 711]:
Property | Type | Description |
---|---|---|
tile_index |
Integer | Tile chain index |
x |
Integer | |
y |
Integer | |
width |
Integer | |
colors |
Array | |
+hue |
Float | Hue in the range of 0.0 to 1.0. |
+saturation |
Float | Saturation in the range of 0.0 to 1.0. |
+brightness |
Float | Brightness in the range of 0.0 to 1.0. |
+kelvin |
Integer | Color temperature (°) in the range of 1500 to 9000. |
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileGetTileState64({
tile_index: 0,
length: 5
});
}).then((multi_res) => {
console.log(JSON.stringify(multi_res, null, ' '));
}).catch(console.error);
The code above will output results as follows:
[
{
"tile_index": 0,
"x": 0,
"y": 0,
"width": 8,
"colors": [
{
"hue": 0.38889,
"saturation": 1,
"brightness": 0.10001,
"kelvin": 9000
},
...
]
]
},
{
"tile_index": 1,
"x": 0,
"y": 0,
"width": 8,
"colors": [
{
"hue": 0.29619,
"saturation": 1,
"brightness": 0,
"kelvin": 9000
},
...
]
},
...
}
Note that the actual number of elements in each colors
array is 64.
The tileSetTileState64()
method updates the state of length
number of tiles starting from tile_index
[SetTileState64 - 715]. This method returns a Promise
object.
This method takes a hash object as an argument containing properties as follows:
Property | Type | Required | Description |
---|---|---|---|
tile_index |
Integer | Required | Starting tile index |
length |
Integer | Optional | Tiles updated from/including tile_index (default: 1 ) |
x |
Integer | Optional | (default: 0 ) |
y |
Integer | Optional | (default: 0 ) |
width |
Integer | Optional | (default: 8 ) |
duration |
Integer | Optional | Color transition time in milliseconds (default: 0 ) |
colors |
Array | Required | Array of 64 HSBK color objects |
Note: While
x
,y
andwidth
properties are provided, the LIFX documentation states it only makes sense to setx
andy
to0
, and width to8
.
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileSetTileState64({
tile_index: 0,
colors: [...Array(64)].map(() => ({
hue: Math.floor(Math.random() * 360)/360,
saturation: 1,
brightness: Math.random(),
kelvin: 3000
}))
});
}).then((res) => {
console.log('Done!');
}).catch(console.error);
The tileGetTiles()
method wraps the tileGetDeviceChain()
method to return only the physically connected tiles in the device chain. This method returns a Promise
object.
If this method fetches the information successfully, an array of hash objects will be passed to the resolve() function. Each hash object is a Tile object with the following additional properties injected:
Property | Type | Description |
---|---|---|
tile_index |
Integer | Tile chain index |
left |
Float | Tile left x value (calculated via user_x ) |
right |
Float | Tile right x value (calculated via user_x ) |
top |
Float | Tile top y value (calculated via user_y ) |
bottom |
Float | Tile bottom y value (calculated via user_y ) |
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileGetTiles();
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch((error) => {
console.error(error);
});
The code above will output results as follows:
[
{
"tile_index": 0,
"left": 4,
"right": 12,
"top": -4,
"bottom": 4,
"accel_meas_x": 152,
"accel_meas_y": -71,
"accel_meas_z": 2053,
"user_x": 0,
"user_y": 0,
"width": 8,
"height": 8,
"device_version_vendor": 1,
"device_version_product": 55,
"device_version_version": 10,
"firmware_build": "1548977726000000000n",
"firmware_version_minor": 50,
"firmware_version_major": 3
},
...
]
Note that the actual number of elements in the returned array equals however many are physically connected in the device chain.
The tileGetTilesAndBounds()
method wraps the tileGetTiles()
method to also return a spatial bounds object for all the physically connected tiles in the device chain. 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:
Property | Type | Description |
---|---|---|
tiles |
Array | Array returned by the tileGetTiles() method |
bounds |
Object | |
+left |
Float | Minimum left value for all tiles |
+right |
Float | Maximum right value for all tiles |
+top |
Float | Minimum top value for all tiles |
+bottom |
Float | Maximum bottom values for all tiles |
+width |
Float | The right value minus the left value |
+width |
Float | The bottom value minus the top value |
Lifx.discover().then((device_list) => {
let tileProductId = 55;
let firstTile = (dev) =>
dev.deviceInfo.productId === tileProductId
let dev = device_list.find(firstTile);
return dev.tileGetTilesAndBounds();
}).then((res) => {
console.log(JSON.stringify(res, null, ' '));
}).catch((error) => {
console.error(error);
});
{
"tiles": [
{
"tile_index": 0,
"left": 4,
"right": 12,
"top": -4,
"bottom": 4,
"accel_meas_x": 158,
"accel_meas_y": -96,
"accel_meas_z": 2065,
"user_x": 0,
"user_y": 0,
"width": 8,
"height": 8,
"device_version_vendor": 1,
"device_version_product": 55,
"device_version_version": 10,
"firmware_build": "1548977726000000000n",
"firmware_version_minor": 50,
"firmware_version_major": 3
},
...
],
"bounds": {
"left": -4,
"right": 12,
"top": -20,
"bottom": 4,
"width": 16,
"height": 24
}
}
Note that the actual number of elements in the tiles
array equals however many are physically connected in the device chain.
- v0.5.0 (2020-12-06)
- Improved the stability of controlling bulbs. An UDP unicast packet will be sent up to 10 times. An UDP broadcast packet will be sent 3 times.
- From this version, this module works on Node v12 or later.
- v0.4.3 (2020-10-31)
- Updated the
products.json
. (Thanks to @r1ch)
- Updated the
- v0.4.2 (2020-07-15)
- Allowed no Params in TurnOffBroadcast. (thanks to @sansnickel)
- Fixed typos in this document. (thanks to @r1ch)
- v0.4.1 (2020-04-09)
- Added support for multizone effects (thanks to @paddy2k)
- v0.4.0 (2019-10-08)
- Supported the tile messages (thanks to @furey)
- v0.3.1 (2018-09-17)
- The lower limit of the
kelvin
property in theLifxLanColor
object was changed from 2500 to 1500. (thanks to @nikteg)
- The lower limit of the
- v0.3.0 (2018-08-08)
- Added the
brightness
parameter to theLifxLanColorCSS
andLifxLanColorRGB
object. (thanks to @paolotremadio)
- Added the
- v0.2.2 (2018-08-07)
- The
multiZoneSetColorZones()
method did not accept aLifxLanColor
object for thecolor
parameter even though this document says the method does. The method accepted only aLifxLanColorHSB
object. Now the method accepts aLifxLanColor
object for the parameter. That is, the method accepts not only aLifxLanColorHSB
object but also aLifxLanColorRGB
,LifxLanColorXyb
, andLifxLanColorCSS
object. (thanks to @paolotremadio)
- The
- v0.2.1 (2018-07-10)
- Updated the
products.json
. (Thanks to @danielHHHH)
- Updated the
- v0.2.0 (2018-07-01)
- Supported multihomed host. Now, you can discover devices expectedly even if your host computer has multiple network interfaces because broadcast packets are sent to all available network interfaces.
- v0.1.0 (2018-06-10)
- Newly added the
createDevice()
method. (Thanks to @MarcGodard)
- Newly added the
- v0.0.3 (2018-06-09)
- Supported Node.js v10. (Thanks to @VanCoding)
- v0.0.2 (2018-02-12)
- Updated
product.json
based on the latest LIFX product ID list table
- Updated
- v0.0.1 (2017-10-22)
- First public release
The MIT License (MIT)
Copyright (c) 2017 - 2020 Futomi Hatano
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.