HomebridgeMagicHome-DynamicPlatform icon indicating copy to clipboard operation
HomebridgeMagicHome-DynamicPlatform copied to clipboard

Hue to CCT function needs rework

Open Zacknetic opened this issue 4 years ago • 0 comments

The current version of the Hue to CCT function breaks some devices by sending full brightness (255) to both warm white and cold white. This causes the device to enter an errored state and will read "CCT 200%" in the MagicHome app.

This function must be changed so that 255 is the max output. i.e. (cw: 0, ww 255) (cw: 100, ww: 155) (cw: 255, ww: 0). Here is the current, broken implementation, which we are using now and can be located in platformAccessory.ts.

hueToWhiteTemperature() {
    const hsl = this.lightState.HSL;
    let multiplier = 0;
    const whiteTemperature = { warmWhite: 0, coldWhite: 0 };
    if (hsl.hue <= 90) {        //if hue is <= 90, warmWhite value is full and we determine the coldWhite value based on Hue
      whiteTemperature.warmWhite = 255;
      multiplier = ((hsl.hue / 90));
      whiteTemperature.coldWhite = Math.round((255 * multiplier));
    } else if (hsl.hue > 270) { //if hue is >270, warmWhite value is full and we determine the coldWhite value based on Hue
      whiteTemperature.warmWhite = 255;
      multiplier = (1 - (hsl.hue - 270) / 90);
      whiteTemperature.coldWhite = Math.round((255 * multiplier));
    } else if (hsl.hue > 180 && hsl.hue <= 270) { //if hue is > 180 and <= 270, coldWhite value is full and we determine the warmWhite value based on Hue
      whiteTemperature.coldWhite = 255;
      multiplier = ((hsl.hue - 180) / 90);
      whiteTemperature.warmWhite = Math.round((255 * multiplier));
    } else if (hsl.hue > 90 && hsl.hue <= 180) {//if hue is > 90 and <= 180, coldWhite value is full and we determine the warmWhite value based on Hue
      whiteTemperature.coldWhite = 255;
      multiplier = (1 - (hsl.hue - 90) / 90);
      whiteTemperature.warmWhite = Math.round((255 * multiplier));
    }
    return whiteTemperature;
  } //hueToWhiteTemperature

Think of it like a bank with 255. CW and WW can't withdraw more than the bank has. The closer to 0/360, the more ww has in their account. The closer to 180, the more cw has in their account.

Zacknetic avatar Dec 11 '20 19:12 Zacknetic