peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

Chaining light states #116

Closed palfaro91 closed 6 years ago

palfaro91 commented 6 years ago

HI team,

First off, great library. It has been pretty easy to learn and use. I have more of a how-to question than an issue. I was trying to chain light state changes to produce something similar to a shortAlert(); but with changing colors. Is there a provided method to do this or is this something that I have to do?

For example: light flashes red, then it flashes gold, then it flashes, green, then it returns to its default state.

peter-murray commented 6 years ago

Hi,

Thanks for your kind words, glad that you have found it useful 😀

You would have to use a chain of promises or nested callbacks, depending upon your preference, to call set light state on the light, with a potential transition time to slow it down, as I would expect it may transition too quickly, to set each of the colours.

You may possibly need a timeout in between each colour transition to support the transition time setting if you use that, to achieve what you want.

If it executes too quickly, I.e. the light is still setting a colour when you hit it with another request you may get an error with that request as I have seen that in the past, but the latest bridge software seems to handle those scenarios better these days.

palfaro91 commented 6 years ago

Ok, I had a feeling and just wanted to make sure that a method didn't exist. Essentially it would be something like api.setLightState(1, someState).then(function(){ setTimeout(function(){ api.setLightState(1, someOtherState).then(function(){ // continue until desired effect and set back to default }) },1000) }

peter-murray commented 6 years ago

Yes, that looks about right to achieve what you want