mwittig / node-milight-promise

A node module to control Milight LED bulbs and OEM equivalents such as Rocket LED, Limitless LED Applamp, Easybulb, s`luce, iLight, iBulb, and Kreuzer
MIT License
114 stars 27 forks source link

Missing brightness function for CCT (WhiteCommand) #36

Closed markg85 closed 6 years ago

markg85 commented 6 years ago

Hi,

Just curious where the brightness function is for the WhiteCommand object, it's not there. I did notice that CCT bulbs in the milight app only do have a brightness up/down (not a slider) and that up/down is in WhiteCommand. Does this mean there simply is no brightness command with a given percentage for those bulbs?

mwittig commented 6 years ago

For CCT brightness cannot be set directly to a relative value, e.g 50%, but you can increase or decrease the brightness (see also examples folder and the code snippet below. Apart from this it is possible to switch to maximum brightness (light.maxBright())

light.ready().then(function() {
  for (var x = 0; x < 10; x++) {
    light.sendCommands(commands.white.brightDown(zone));
    light.pause(100);
  }
  for (var x = 0; x < 10; x++) {
    light.sendCommands(commands.white.brightUp(zone));
    light.pause(100);
  }
...
mwittig commented 6 years ago

For your application you can emulate setting the dim level, by calling maxBright followed by a number of brightDown calls to match the desired level.

According to my findings there are 19 different dimming steps for CCTs supported by the milight controller. The number of brightDown calls required can be calculated as follows:

Round((100 - level) / 20) where level is a value in the range 0..100.

If the result is 20 you need to switch off the light. If you don't want to switch off lights at the lowest level use Round((100 - level) / 19) instead.

mwittig commented 6 years ago

I am closing this now. Please re-open if you wish to follow up.