Smooth Hue Dimming Solution - A Step-by-Step Guide

Hey everyone, I wanted to share a solution I came up with for a problem that many of us have encountered—the disappointing dimming behavior of Hue lights when using the Hue binding. This issue has been a thorn in my side for quite some time, but I finally found a workaround that works beautifully!

The Problem

If you’ve used the Hue binding for dimming, you’ve probably noticed that the transition isn’t as smooth as it could be. The lights tend to flicker or change brightness in abrupt steps, which can be quite jarring.

The Solution

The key to achieving smooth dimming lies in using the fadingLightCommand method instead of sending direct brightness commands. Here’s how it works:

  1. Trigger the Dimming: Start by detecting the trigger for dimming, such as a button press or a time-based event.
  2. Capture Current Brightness: Retrieve the current brightness level of the Hue light group.
  3. Calculate Dimming Parameters: Determine the direction of the dimming (up or down) and calculate the time it will take to reach the desired brightness level.
  4. Execute the Fading Command: Use the fadingLightCommand method to send the command to the Hue lights, specifying both the target brightness and the dimming duration.
  5. Handle Stop Commands: When the dimming should stop, calculate the elapsed time and estimate the current brightness to send a final command, ensuring a smooth transition.

The Code

Here’s a sample rule that implements this solution for a group of four white GU10 lamps:

javascript
var DIM_TIME = 4000; // Time for a full dim cycle (0-100%)
var startTime, deltaTime, currentBrightness, dimDirection, dimTime, fadeToBrightness;
var things = Java.type(‘org.openhab.core.model.script.actions.Things’);
var zdt = Java.type(‘java.time.Instant’);

if (itemRegistry.getItem(‘Mod20_EG_WC_Relais8_Hue_Brigntness’).getState() == ‘ON’) {
currentBrightness = itemRegistry.getItem(‘HUEEGFlur_Helligkeit’).getState();
if ((currentBrightness == 0) || (dimDirection == “up”)){
fadeToBrightness = 100;
dimTime = (100 - brightness) * DIM_TIME / 100;
} else {
fadeToBrightness = 0;
dimTime = brightness * DIM_TIME / 100;
}
startTime = zdt.now().toEpochMilli();
things.getActions(‘hue’,‘hue:group:02648f68d9:9’).fadingLightCommand(“color”, new PercentType(fadeToBrightness), new DecimalType(dimTime));
} else if (itemRegistry.getItem(‘Mod20_EG_WC_Relais8_Hue_Brigntness’).getState() == ‘OFF’) {
deltaTime = (zdt.now().toEpochMilli() - startTime) / DIM_TIME * 100;
if (dimDirection == “up”) {
dimDirection = “down”;
if ((currentBrightness = currentBrightness + deltaTime) > 100) currentBrightness = 100;
} else {
dimDirection = “up”;
if ((currentBrightness = currentBrightness - deltaTime) < 0) currentBrightness = 0;
}
events.sendCommand(‘HUEEGFlur_Helligkeit’, new DecimalType(currentBrightness));
}

Results

This method has completely transformed the dimming experience for my Hue lights. The transition is now smooth and linear, with no flickering or abrupt changes. The only minor caveat is that the lights may briefly adjust their brightness when the dimming is stopped, but this effect is subtle and doesn’t detract from the overall experience.

Conclusion

I hope this solution helps others who have struggled with the same issue. It’s always rewarding to find a workaround that enhances the functionality of your smart home setup. If you have any questions or suggestions for improvement, feel free to reach out!

Happy dimming! :blush: