node-lifx-lan
v0.5.1
Published
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.
Downloads
38
Maintainers
Readme
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
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
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:
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
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:
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.
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:
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.
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:
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.
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:
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.
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:
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.
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:
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.
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:
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.
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
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.
LifxLanColorRGB
object
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
.
LifxLanColorXyb
object
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.
LifxLanColorCSS
object
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
.
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.
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
.
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:
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
}
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:
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);
});
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:
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);
});
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:
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);
});
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:
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
}
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:
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
},
...
]
}
}
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]:
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
}
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]:
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
}
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]:
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
}
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]:
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
}
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]:
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
}
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]:
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
}
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:
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);
});
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]:
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"
}
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:
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);
});
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]:
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
}
}
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]:
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
}
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]:
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"
}
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:
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);
});
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]:
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"
}
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:
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);
});
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:
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 ?"
}
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]:
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"
}
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:
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);
});
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:
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);
});
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]:
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
}
lightSetPower(params) method
The `lightSetPo