michielpost / Q42.HueApi

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

Color Loop actions require specified brightness for transition to function #232

Closed Exergist closed 3 years ago

Exergist commented 3 years ago

It seems that activating or deactivating a Color Loop effect and smoothly transitioning the effect (from on -> off and vice-versa) only works when a brightness is specified within the triggering LightCommand. As an example:

// Method for setting multiple lights to a specified color effect at specified brightness (percentage or byte), and brightnessPercent overrides brightnessByte
public async Task SetLightsEffect(string[] LightIds, ColorEffect effect, double? brightnessPercent, TimeSpan transitionTime = default(TimeSpan), byte? brightnessByte = null,  bool forceLightsOn = true)
{
    LightCommand lc = new LightCommand();

    if (effect == ColorEffect.ColorLoop)
        lc.Effect = Effect.ColorLoop;
    else
        lc.Effect = Effect.None;

    lc.TransitionTime = transitionTime;
    byte? brightness = ProcessBrightness(brightnessPercent, brightnessByte);
    if (brightness != null)
        lc.Brightness = brightness;
    if (forceLightsOn == true)
    {
        if (AnyLightOff(LightIds) == true)
            lc.On = true;
    }
    await this.SendLightCommand(lc, LightIds);
}

If brightnessPercent or brightnessByte are both null the transitions are abrupt (seemingly TimeSpan.Zero), whereas if either has a value then the lc.Brightness parameter is populated in the command and the transition happens as specified.

I'm guessing this is a quirk of the Hue API itself, but I wanted to mention it just in case.

michielpost commented 3 years ago

Yes, this is a Hue API quirk. You can check with a tool like Fiddler if all your specified properties are send in the json to the Hue bridge. If you specify a property and it's not in the json, it's a Q42.HueApi library bug, else it's probably the Hue bridge.