{"id":23109100,"url":"https://github.com/mariusrumpf/node-lifx","last_synced_at":"2025-04-08T03:10:15.705Z","repository":{"id":32534568,"uuid":"36116338","full_name":"MariusRumpf/node-lifx","owner":"MariusRumpf","description":"Node.js implementation of the LIFX LAN protocol :bulb:","archived":false,"fork":false,"pushed_at":"2023-01-25T11:20:59.000Z","size":346,"stargazers_count":144,"open_issues_count":21,"forks_count":28,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-31T12:06:03.857Z","etag":null,"topics":["javascript","js","lan","lifx","light","mit","node","nodejs","protocol","udp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MariusRumpf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-23T09:31:49.000Z","updated_at":"2024-09-15T03:01:53.000Z","dependencies_parsed_at":"2023-02-14T06:55:13.673Z","dependency_job_id":null,"html_url":"https://github.com/MariusRumpf/node-lifx","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariusRumpf%2Fnode-lifx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariusRumpf%2Fnode-lifx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariusRumpf%2Fnode-lifx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MariusRumpf%2Fnode-lifx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MariusRumpf","download_url":"https://codeload.github.com/MariusRumpf/node-lifx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767236,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","js","lan","lifx","light","mit","node","nodejs","protocol","udp"],"created_at":"2024-12-17T01:32:49.785Z","updated_at":"2025-04-08T03:10:15.664Z","avatar_url":"https://github.com/MariusRumpf.png","language":"JavaScript","readme":"# LIFX Node.js Library\n\n\u003e **Warning**: This repository currently has no active maintainer. For that reason, development is stale. Consider using an active fork, like [lifx-lan-client](https://github.com/node-lifx/lifx-lan-client).\n\n[![NPM Version](https://img.shields.io/npm/v/node-lifx.svg)](https://www.npmjs.com/package/node-lifx)\n[![Build Status](https://img.shields.io/travis/MariusRumpf/node-lifx/master.svg)](https://travis-ci.org/MariusRumpf/node-lifx)\n[![Build status](https://img.shields.io/appveyor/ci/MariusRumpf/node-lifx/master.svg)](https://ci.appveyor.com/project/MariusRumpf/node-lifx)\n[![Dependency Status](https://dependencyci.com/github/MariusRumpf/node-lifx/badge)](https://dependencyci.com/github/MariusRumpf/node-lifx)\n[![codecov.io](https://img.shields.io/codecov/c/github/MariusRumpf/node-lifx/master.svg)](https://codecov.io/github/MariusRumpf/node-lifx?branch=master)\n[![Gitter Chat](https://img.shields.io/gitter/room/node-lifx/Lobby.svg)](https://gitter.im/node-lifx/Lobby)\n\n\nA Node.js implementation of the [LIFX protocol](https://github.com/LIFX/lifx-protocol-docs). Developed to work with a minimum firmware version of 2.0.\n\nThis library is not, in any way, affiliated or related to LiFi Labs, Inc.. Use it at your own risk.\n\n## Installation\n\n```sh\n$ npm install node-lifx --save\n```\n\n## Compatibility\n\nNode.js 0.12+ and io.js are tested and supported on Mac, Linux and Windows.\n\n## Usage\nThe file `cli.js` contains a working example.\n\n### Client\nThe library uses a client for network communication. This client handles communication with all lights in the network.\n```js\nvar LifxClient = require('node-lifx').Client;\nvar client = new LifxClient();\n\nclient.init();\n```\nThe `Client` object is an EventEmitter and emmits events whenever any changes occur. This can be a new light discovery, a light sending a message or similar.\nThe client starts discovery of lights right after it is initialized with the `init` method. If a new light is found the client emmits a `light-new` event. This event contains the light as an object on which methods can be called then:\n\n```js\nvar LifxClient = require('node-lifx').Client;\nvar client = new LifxClient();\n\nclient.on('light-new', function(light) {\n  // Change light state here\n});\n\nclient.init();\n```\n\n### Changing light state\nThe states of a light can be changed with different methods:\n\n#### `light.on([duration], [callback])`\nThis turns a light on.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`duration` | int | 0 | Turning on will be faded over the time (in milliseconds).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\nUsage examples:\n```js\nlight.on(); // Turns the light on instantly\nlight.on(2000); // Fading the light on over two seconds\n```\n\n#### `light.off([duration], [callback])`\nThis turns a light off.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`duration` | int | 0 | Turning off will be faded over the time (in milliseconds).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\nUsage examples:\n```js\nlight.off(); // Turns the light off instantly\nlight.off(2000); // Fading the light off over two seconds\n```\n\n#### `light.color(hue, saturation, brightness, [kelvin], [duration], [callback])`\nChanges the color of a light to an HSB color value. This is the preferred method to change the color of a light.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`hue` | int | | Between 0 and 360, representing the color hue in degree which changes the color.\n`saturation` | int | | Between 0 and 100, representing the color intensity from 0% to 100%.\n`brightness` | int | | Between 0 and 100, representing the light brightness from 0% to 100%.\n`kelvin` | int | 3500 | Between 2500 and 9000, representing the color temperature.\n`duration` | int | 0 | Fade the color to the new value over time (in milliseconds).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\nUsage examples:\n```js\nlight.color(0, 100, 50); // Set to red at 50% brightness\nlight.color(50, 50, 80, 3500, 2000); // Set to a light green at 80% brightness over next two seconds\n```\n\n#### `light.colorRgbHex(hexString, [duration], [callback])`\nChanges the color of a light to an RGB color value given in Hex Format. Note that RGB poorly represents color of light,\nprefer HSBK values given via the `color` method.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`hexString` | string | | A hex RGB string starting with `#`\n`duration` | int | 0 | Fade the color to the new value over time (in milliseconds).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\n\nUsage examples:\n```js\nlight.colorRgbHex('#F00'); // Set to red\nlight.colorRgbHex('#FFFF00'); // Set to yellow\n```\n\n#### `light.colorRgb(red, green, blue, [duration], [callback])`\nChanges the color of a light to an RGB color value. Note that RGB poorly represents color of light,\nprefer HSBK values given via the `color` method.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`red` | int | | Amout of red in color from 0 to 255\n`green` | int | | Amout of green in color from 0 to 255\n`blue` | int | | Amout of blue in color from 0 to 255\n`duration` | int | 0 | Fade the color to the new value over time (in milliseconds).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\n\nUsage examples:\n```js\nlight.colorRgb(255, 0, 0); // Set to red\nlight.colorRgb(255, 255, 0); // Set to yellow\n```\n\n#### `light.maxIR(brightness, callback)`\nSet's the maximum infrared brightness of the light (only for lights that support infrared light)\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`brightness` | int | | Between 0 and 100, representing the light brightness from 0% to 100%.\n`callback` | function | | `function(error, data) {}`\n\nUsage examples:\n```js\nlight.maxIR(0); // Set's a maximum infrared brightness of 0\nlight.maxIR(25); // Set's a maximum infrared brightness of 25\n```\n\n#### `light.getMaxIR(callback)`\nRequests the maximum infrared brightness of the light (only for lights that support infrared light)\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  brightness: 25\n}\n```\n\n\n### Requesting light state and info\nInfos of the state and spec of the light can be requested with the following methods:\n\n#### `light.getState(callback)`\nRequests general info from a light, this includes color, label and power state. This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  color: { hue: 120, saturation: 0, brightness: 100, kelvin: 8994 },\n  power: 0,\n  label: 'Kitchen'\n}\n```\n\n#### `light.getPower(callback)`\nRequests current power state (on or off). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n0 // off\n```\n\n#### `light.getFirmwareVersion(callback)`\nRequests the firmware version from a light (minor and major version). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  majorVersion: 2,\n  minorVersion: 1\n}\n```\n\n#### `light.getHardwareVersion(callback)`\nRequests the hardware version from a light (vendor, product and version). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  vendorId: 1,\n  vendorName: 'LIFX',\n  productId: 1,\n  productName: 'Original 1000',\n  version: 6,\n  productFeatures: {\n    color: true,\n    infrared: false,\n    multizone: false\n  }\n}\n```\n\n#### `light.getFirmwareInfo(callback)`\nRequests info from the micro controller unit of a light (signal, tx and rx). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  signal: 0,\n  tx: 0,\n  rx: 0\n}\n```\n\n#### `light.getWifiInfo(callback)`\nRequests wifi info from a light (signal, tx and rx). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  signal: 0.000009999999747378752,\n  tx: 16584,\n  rx: 12580\n}\n```\n\n#### `light.getWifiVersion(callback)`\nRequests the wifi firmware version from the light (minor and major version). This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\nExample result:\n```js\nnull,\n{\n  majorVersion: 2,\n  minorVersion: 1\n}\n```\n\n#### `light.getAmbientLight(callback)`\nRequests the ambient light value in flux from the light. This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n\n\nExample result:\n```js\nnull,\n10\n```\n\n### Labels\nLabels of lights can be requested and set using the following methods:\n\n#### `light.getLabel(callback, [cache])`\nRequests the label of a light. This function is asynchronous.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`callback` | function | | `function(error, data) {}`\n`cache`    | boolean  | false | Use the last known value for the label and and do not request from the light again\n\nExample result:\n```js\nnull,\n'Kitchen'\n```\n\n#### `light.setLabel(label, [callback])`\nSets a new label for a light.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`label` | string | | New Label with 32 bit size maximum (which is a length of 32 with non unicode chars).\n`callback` | function | null | `function(error) {}` Called after the command has reached the light or after `client.resendMaxTimes` with `client.resendPacketDelay` in case it has not. `error` is `null` in case of success and given if the sending has failed.\n_Note: Using callback multiplies network load for this command by two or more times._\n\n\nUsage examples:\n```js\nlight.setLabel('Bedroom Light');\nlight.setLabel('Kitchen Light 4', function(err) {\n  if (err) { throw err; }\n  console.log('New light label has been set');\n});\n```\n\n### Get a light\n#### `client.light(identifier)`\nFind a light in the list off all lights by ip, label or id.\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`identifier` | string | | Light label (case sensitive) `client.light('Kitchen')`, the ip address `client.light('192.168.2.102')` or the light id `client.light('0123456789012')`\n\nReturns a light object that can then be used to call methods on it. For example `client.light('192.168.2.102').on()`.\n\n### Get all lights\n\n#### `client.lights([filter])`\nGet a list of all known lights\n\nOption | Type | Default | Description\n------ | ---- | ------- | -----------\n`filter` | string | null | Filter list of lights to return only active (`null` or `'on'`), inactive (`'off'`) or all (`''`)\n\n### Client events\nThe following events might be thrown by the client.\n\n#### `light-new`\nThis event is thrown when there is a new light discovery that has not been seen at runtime before. This event is provided with the new light object.\n`client.on('light-new', function(light) {});`\n\n#### `light-offline`\nThis event is thrown when a light hasn't been discovered for a time. The light given is no longer expected to be reachable.\n`client.on('light-offline', function(light) {});`\n\n#### `light-online`\nThis event is thrown when a light is discovered again after being offline.\n`client.on('light-online', function(light) {});`\n\n### Start / Stop discovery\nThe discovery for each client can be started and stopped at runtime using these commands:\n\n#### `client.startDiscovery()`\nStarts the discovery process.\n\n#### `client.stopDiscovery()`\nStops the discovery process.\n\n### Client settings\nFor the initialization of the client different settings can be provided. This is an example with the default options:\n\n```js\nvar LifxClient = require('node-lifx').Client;\nvar client = new LifxClient();\n\n// ...\n\nclient.init({\n  lightOfflineTolerance: 3, // A light is offline if not seen for the given amount of discoveries\n  messageHandlerTimeout: 45000, // in ms, if not answer in time an error is provided to get methods\n  startDiscovery: true, // start discovery after initialization\n  resendPacketDelay: 150, // delay between packages if light did not receive a packet (for setting methods with callback)\n  resendMaxTimes: 3, // resend packages x times if light did not receive a packet (for setting methods with callback)\n  debug: false, // logs all messages in console if turned on\n  address: '0.0.0.0', // the IPv4 address to bind the udp connection to\n  broadcast: '255.255.255.255', // set's the IPv4 broadcast address which is addressed to discover bulbs\n  lights: [] // Can be used provide a list of known light IPv4 ip addresses if broadcast packets in network are not allowed\n             // For example: ['192.168.0.112', '192.168.0.114'], this will then be addressed directly\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariusrumpf%2Fnode-lifx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariusrumpf%2Fnode-lifx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariusrumpf%2Fnode-lifx/lists"}