Make sure you have installed all of the following prerequisites on your development machine:
- Node.js - Download & Install Node.js and the npm package manager.
The recommended way to get Nanoleaf Client is to use git to directly clone repository:
$ git clone https://github.com/VadimGarkusha/nanoleaf-client.git
This will clone the latest version of the Nanoleaf Client repository.
To install the dependencies, run this in the application folder from the command-line:
$ npm install nanoleaf-client
In order to use the client you need to know your device IP on the network and a user token.
Get device IP. NOTE: before running this command make sure the device is plugged in and is connected to the network. You can check it with phone app.
Be careful with IPs! Sometimes, if you plug out the device or a router an IP address might change.
import { ServiceDiscovery } from 'nanoleaf-client';
let serviceDiscovery = new ServiceDiscovery();
serviceDiscovery.discoverNanoleaf().then(devices => {
// devices is an array of all Nanoleaf devices found on the network.
// device info contains location info, uuid and device Id.
console.log(devices);
});
Before executing this command, hold power button on your nanoleaf device for 5 seconds until the white LED starts glowing. After that you have 30 seconds to execute this command and get a token. Client will be authorized automatically.
NOTE: Device can hold up to 5 tokens. New tokens come in FIFO order.
client.authorize().then(token => {
console.log(token);
}).catch(err => {
console.log(err);
});
getInfo()
- returns object with information about current state of deviceidentify()
- causes panels to flash in unison, returns response with status if successfulauthorize()
- authorizes nanoleaf client for future requests and returns string auth tokengetGlobalOrientation()
- returns object with global orientation value
turnOn()
- turns on the deviceturnOff()
- turns off the devicepower(power)
- accepts boolean parameter and sets device power statusgetPowerStatus()
- returns object with power status
getSaturation()
- returns object with current saturation valuesetSaturation(value)
- accepts numerical parameter and sets saturation valueincrementSaturation(increment)
- accepts numerical parameter and incerements saturation value by it
getBrightness()
- returns object with current brightness valuesetBrightness(value)
- accepts numerical parameter and sets brightness valueincreaseBrightness(increment)
- accepts numerical parameter and incerements brightness value by itsetDurationBrightness(value, duration)
- accepts two numerical parameter and sets brightnessvalue
forduration
period
getHue()
- returns object with current hue valuesetHue(value)
- accepts numerical parameter and sets hue valueincreaseHue(increment)
- accepts numerical parameter and incerements hue value by it
getColorTemperature()
- returns current color temperature valuesetColorTemperature(value)
- accepts numerical parameter and sets color temperature valueincrementColorTemperature(increment)
- accepts numerical parameter and incerements color temperature value by it
getColorMode()
- returns string with current color temperature valuect
(color temperature),hs
(hue/saturation), oreffect
getSelectedEffect()
- returns string with selected effectgetEffectInfo(effectName)
- accepts string with effect name and returns object with effect propertiessetEffect(value)
- accepts string with effect names and sets it as current effectgetEffectList()
- returns array of strings with available effects
setHsvColor(h, s, v)
- accepts three numerical parameters and sets hsv color based on themsetHslColor(h, s, l)
- accepts three numerical parameters and sets hsl color based on themsetHexColor(hexString)
- accepts string parameter with hex values and sets color based on itsetRgbColor(r, g, b)
- accepts three numerical parameters and sets rgb color based on them
import { NanoleafClient } from 'nanoleaf-client';
let client = new NanoleafClient('<device_ip>', '<user_token>');
// For example
let client = new NanoleafClient('192.168.0.10', 'qEQ8ZLcPuOVesarDXIW6eGQQd1Hhn1d9');
// Without token
let noTokenClient = new NanoleafClient('192.168.0.10');
// Adding token later
noTokenClient.authorize('qEQ8ZLcPuOVesarDXIW6eGQQd1Hhn1d9');
client.turnOn().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
client.turnOff().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
client.getInfo().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
This project is licensed under the MIT License - see the LICENSE.md file for details