Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This module provides input and output nodes for communicating with Lifx lights,
* Trigger events for light changes
* Self syncing, uses background polling to detect external changes to light
* Displays current state for light in Node-Red ui
* ability to set waveform


### Examples
Expand Down Expand Up @@ -55,6 +56,20 @@ More advanced way to control the light is to send an object payload with one or
| `kelvin` | Set kelvin color temperature (2200-6500) |
| `duration` | Transition time (ms) |

*setting waveform*
Waveform is a way to create effect in lifx bulbs, like the breath effect in the Lifx App. Setting a wave form will be at the following JSON form.

```json
{
"isTransient": true,
"color": {"hue": 0, "saturation": 65535, "brightness": 65535, "kelvin": 3500},
"period": 800,
"cycles": 3,
"skewRatio": 0,
"waveform": "SINE" // one of SAW, SINE, HALF_SINE, TRIANGLE, PULSE
}
```

**Notice:** to get the same behavioras the Lifx app when modifying the color temperature you will need to manually set the saturation to zero. This is because the Lifx light can adjust temperature and color independent of each other and I didn't want to limit the choices for the user.

Example: Sending the following to the light will turn it on and dim it upp to 77% over 10 seconds
Expand Down
39 changes: 39 additions & 0 deletions lib/lifx-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ LightHandler.prototype.setLightState = function setState(data) {
return this.lightServer.setLightState(this.id, data);
};

/**
* Set waveform of light
* @param {object} data New light data
* @return {boolean} False if there is no such light or it's not discovered yet
*/
LightHandler.prototype.setLightWaveForm = function setState(data) {
return this.lightServer.setLightWaveForm(this.id, data);
};

/**
* Send data to light
Expand Down Expand Up @@ -327,6 +335,37 @@ LightServer.prototype.getLights = function getLights() {
return retVal;
}

/**
* Set light state wave form
*
* example {
* isTransient: true,
* color: {hue: 0, saturation: 65535, brightness: 65535, kelvin: 3500},
* period: 800,
* cycles: 3,
* skewRatio: 0,
* waveform: SAW, SINE, HALF_SINE, TRIANGLE, PULSE
* }
* @param {string} lightID ID/Label for the light
* @param {object} value New values for the light wave form
* @return {boolean} False if no such light exists
*/
LightServer.prototype.setLightWaveForm = function setLightWaveForm(lightID, value) {

if (!this.lights.hasOwnProperty(lightID))
return false;

value.waveform = nodeLifx.constants.LIGHT_WAVEFORMS.indexOf(value.waveform)

var packetObj = nodeLifx.packet.create('setWaveform', value, this.lifxClient.source);

packetObj.target = lightID

this.lifxClient.send(packetObj, () => {})

return true;
}


/**
* Exports LightServer
Expand Down
7 changes: 6 additions & 1 deletion red/lifx-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ module.exports = function(RED, isOutput) {
node.on('input', (msg) => {
if (!node.isOutput && node.lightHandler) {
try {
node.lightHandler.setLightState(msg.payload);
if (msg.payload.waveform) {
node.lightHandler.setLightWaveForm(msg.payload);
} else {
node.lightHandler.setLightState(msg.payload);
}

}
catch (e) {
node.error(e.message, e.stack);
Expand Down