Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support for setting light waveforms #5

Merged
merged 5 commits into from
Apr 14, 2020

Conversation

ristomatti
Copy link
Owner

@ristomatti ristomatti commented Apr 14, 2020

This merges jdomeij#8 and adapts it to work with the changes on this fork.

The feature is marked experimental as:

  • the current implementation uses raw packets as there's no
    official support for the command on lifx-lan-client
  • there's no validation for the input properties
  • brightness and hue values use 0-65535 range instead of
    0-100 / 0-360
  • output node info tab documentation is missing

Example payload to test (note the raw saturation and brightness ranges):

{
  "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
}

Closes #4.

lyonlai and others added 5 commits April 12, 2018 01:13
The feature is only experimental as:
- the current implementation uses raw packets as there's no
  official support for the command on lifx-lan-client
- there's no validation for the input properties
- brightness and hue values use 0-65535 range instead of
  0-100 / 0-360
- node's info tab documentation is missing
@ristomatti ristomatti mentioned this pull request Apr 14, 2020
@Andobi
Copy link

Andobi commented Apr 14, 2020

Node red has a range node that I guess could be used to map the new ranges.
Will the Lifx-lan-client build the packet from these payloads?

@ristomatti
Copy link
Owner Author

ristomatti commented Apr 14, 2020

@Andobi Yep using range node would definitely be a good workaround. However I don't like the inconsistency between commands within the library so it would be nice to fix at some point.

Lifx-lan-client has a similar partial support for setting the waveform (which the code here uses), so yes it should work. You can instal this similarly as the previous one with:

npm install ristomatti/node-red-contrib-node-lifx#feature/set-waveform

No need to remove the previous version. This also includes all the previous changes.

You can import the below two nodes and connect them to a light to test.

[{"id":"4a5eb957.0ec0a8","type":"inject","z":"541dcf12.49751","name":"waveform","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":800,"wires":[["c46a327b.e2eb6"]]},{"id":"c46a327b.e2eb6","type":"template","z":"541dcf12.49751","name":"set waveform","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n  \"isTransient\": true,\n  \"color\": {\"hue\": 0, \"saturation\": 65535, \"brightness\": 65535, \"kelvin\": 3500},\n  \"period\": 800,\n  \"cycles\": 3,\n  \"skewRatio\": 0,\n  \"waveform\": \"SINE\"\n}","output":"json","x":290,"y":800,"wires":[["9e9f6f52.eae85"]]}]

@ristomatti
Copy link
Owner Author

@Andobi The unexpected happened: #6

This means I will be able to update the NPM package.

@Andobi
Copy link

Andobi commented Apr 14, 2020

Alright then! That's good. I'll test it out shortly.

@Andobi
Copy link

Andobi commented Apr 14, 2020

You can import the below two nodes and connect them to a light to test.

[{"id":"4a5eb957.0ec0a8","type":"inject","z":"541dcf12.49751","name":"waveform","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":800,"wires":[["c46a327b.e2eb6"]]},{"id":"c46a327b.e2eb6","type":"template","z":"541dcf12.49751","name":"set waveform","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n  \"isTransient\": true,\n  \"color\": {\"hue\": 0, \"saturation\": 65535, \"brightness\": 65535, \"kelvin\": 3500},\n  \"period\": 800,\n  \"cycles\": 3,\n  \"skewRatio\": 0,\n  \"waveform\": \"SINE\"\n}","output":"json","x":290,"y":800,"wires":[["9e9f6f52.eae85"]]}]

This worked, but it was scary. I'm going to mess with the numbers to make it less violent.

@Andobi
Copy link

Andobi commented Apr 14, 2020

{ "isTransient": true, "color": {"hue": 0, "saturation": 65535, "brightness": 30000, "kelvin": 5000}, "period": 2000, "cycles": 5, "skewRatio": 0, "waveform": "SINE" }

This is nicer. I'm starting from white. There is a weird double pulse around the starting point using SINE
I can remove "kelvin" setting and it still works. TRIANGLE gives a different type of pulsing, as does PULSE. In fact looks like all the waveforms work.

@ristomatti
Copy link
Owner Author

Great! I agree the provided example was quite violent. I'll merge this and see if I could get also the npm package updated.

@ristomatti ristomatti merged commit 48be73c into master Apr 14, 2020
@ristomatti ristomatti deleted the feature/set-waveform branch April 14, 2020 17:30
@ristomatti
Copy link
Owner Author

@Andobi You can now just npm install node-red-contrib-node-lifx to get the latest changes. 🙂

@Andobi
Copy link

Andobi commented Apr 14, 2020

That's awesome, good job. I'm very happy as my kitchen lights are now in sync with the transition to red without any complicated node red flows.
You probably already saw the LIFX Lan Protocol docs which could be useful for implementing MultiZone (Z or Beam) and Tile colour patterns, if at some point you or others have time and will to do this.

@Andobi
Copy link

Andobi commented Apr 14, 2020

From the documentation and from discussions at the LIFX forum, it seems preferable to use setWaveformOptional instead of setWaveform.
I tried to tweak this myself by editing:

  • line 360 of lifx-server.js to setWaveformOptional
  • uncommenting line 51 of packet.js in the lifx-lan-client (id 119)

Sadly that didn't work, gives an error in node red:

Cannot read property 'size' of undefined

Also the docs state:

Hue: range 0 to 65535
Saturation: range 0 to 65535
Brightness: range 0 to 65535

So will have to scale all of them

@ristomatti
Copy link
Owner Author

That's awesome, good job. I'm very happy as my kitchen lights are now in sync with the transition to red without any complicated node red flows.

Glad to help! Some of these changes will be useful to me also.

You probably already saw the LIFX Lan Protocol docs which could be useful for implementing MultiZone (Z or Beam) and Tile colour patterns, if at some point you or others have time and will to do this.

Yes. Actually support for the setMultiZoneEffect is hanging as a pull request to lifx-lan-client. I will test it now and if it's ok I'll merge it. After it gets published I can look into adding support to node-red-contrib-node-lifx also.

There's also a PR for the tile support but it's gone stale. I think the implementation needs furher refining before it can be added. I haven't had time to look into it as it's a lot more complicated feature. I cannot give any estimate when this will be progressed.

One reason for lack of motivation to add the Tile support is that someone has already created a very nicely documented Tile effects library lifx-tile-effects-framework which uses node-lifx-lan (another LIFX client library). I believe it would be less work to create a Node-RED wrapper for that instead.

@ristomatti
Copy link
Owner Author

From the documentation and from discussions at the LIFX forum, it seems preferable to use setWaveformOptional instead of setWaveform.
I tried to tweak this myself by editing:

  • line 360 of lifx-server.js to setWaveformOptional
  • uncommenting line 51 of packet.js in the lifx-lan-client (id 119)

Sadly that didn't work, gives an error in node red:

Cannot read property 'size' of undefined

You were on the right track there but in addition to uncommenting setWaveformOptional in packet.js, a packet builder needs to be at least added in the lib/lifx/packets folder. There might be some other things also that I don't remember right now.

@Andobi
Copy link

Andobi commented Apr 15, 2020

Thanks, I've had a look at that but it's definitely beyond me at the moment.

@Andobi
Copy link

Andobi commented Apr 16, 2020

For anyone else looking at this, here is a hsb scaler subflow, feed the usual payload in and it will come out the other end with adjusted values.
[{"id":"10861a8b.e538b5","type":"subflow","name":"hsb scaler","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"34bf866b.96f3ca"}]}],"out":[{"x":320,"y":160,"wires":[{"id":"cff2e9aa.7ef8e8","port":0}]}],"env":[],"color":"#3FADB5","icon":"node-red/range.svg"},{"id":"34bf866b.96f3ca","type":"range","z":"10861a8b.e538b5","minin":"0","maxin":"360","minout":"0","maxout":"65535","action":"scale","round":true,"property":"payload.hue","name":"hue","x":190,"y":80,"wires":[["90e9b025.3ddd"]]},{"id":"90e9b025.3ddd","type":"range","z":"10861a8b.e538b5","minin":"0","maxin":"100","minout":"0","maxout":"65535","action":"scale","round":true,"property":"payload.sat","name":"sat","x":190,"y":120,"wires":[["cff2e9aa.7ef8e8"]]},{"id":"cff2e9aa.7ef8e8","type":"range","z":"10861a8b.e538b5","minin":"0","maxin":"100","minout":"0","maxout":"65535","action":"scale","round":true,"property":"payload.bri","name":"bri","x":190,"y":160,"wires":[[]]},{"id":"a3519548.8e6268","type":"subflow:10861a8b.e538b5","z":"5244e927.375ac8","x":820,"y":180,"wires":[["38551e22.f17ba2"]]}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for setWaveform
3 participants