michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
409 stars 114 forks source link

Color temperature not applying when deactivating Color Loop #231

Closed Exergist closed 3 years ago

Exergist commented 3 years ago

I use the following method to set the temperature of a group of lights:

// Method for setting multiple lights to a specified mired color temperature
public async Task SetLightsTemperature(string[] LightIds, int miredTemp, double? brightnessPercent, TimeSpan transitionTime = default(TimeSpan), byte? brightnessByte = null, bool forceLightsOn = true)
{
    if (miredTemp >= 153 && miredTemp <= 500)
    {
        byte? brightness = ProcessBrightness(brightnessPercent, brightnessByte);
        LightCommand lc = new LightCommand();
        lc.TransitionTime = transitionTime;
        lc.Effect = Effect.None;
        lc.ColorTemperature = miredTemp;
        if (brightness != null)
            lc.Brightness = brightness;
        if (forceLightsOn == true)
        {
            if (AnyLightOff(LightIds) == true)
                lc.On = true;
        }
        await this.SendLightCommand(lc, LightIds);
        ///await this.SendLightCommand(lc, LightIds); // A second call of this LightCommand properly updates the light color temperature
    }
    else
        Console.WriteLine("Mired color temperature '" + miredTemp + "' outside acceptable range (must be between 153 and 500)");
}

If a Color Loop effect is already activated prior to running this method, I've found that while the Color Loop does deactivate and the Brightness does adjust, the passed-in miredTemp is NOT implemented. Calling the SendLightCommand again (see commented code) DOES implement the requested miredTemp.

What I'm trying to achieve here is that any ongoing effects are deactivated whenever a request for a specific color is made. I wasn't expecting the color temperature assignment be "skipped."

Exergist commented 3 years ago

For additional clarification - I set the light temperature to a particular value (ABC) prior to engaging a Color Loop so that groups of lights all "start" at the same light color and are in sync. When I run the above code (without the extra SendLightCommand) the light color reverts back to this starting ABC color temperature instead of the miredTemp specified above.

Because the lights seem to "remember" their state prior to engaging the Color Loop, setting them to a specific new color like RED (which requires disengaging the Color Loop first) results in a brief flash of the original color and then the RED transition.

michielpost commented 3 years ago

Yes, this is the behavior of the Philips Hue lights. Sometimes you have to get creative and try to work around it. Try a longer or shorter transition time, or minimize the flash by setting a lower brightness in the previous state, before you active the color loop. It depends on what you want to achieve and how it looks.

Exergist commented 3 years ago

Good to know, thank you for the feedback!