Realzing a Smooth HUE Dimmer - solved

Hello community,

Today I don’t want to ask a question, but present a solution. Several of you, an me too, have the problem that dimming rules for hue lights are disapointing, when using the hue-binding. Two days ago I had an idear to fix this behavior.

The idear is not to send brightness commands until the disiered brightness is reached. Instead of this I use .fadingLightCommand. The steps for the rule are the following:

  1. get trigger for dimming
  2. get the current brightness
  3. get the current time in ms
  4. sending .fadingLightCommand
  5. get the trigger for stop dimming
  6. get the current time and calculate the elapsed time. With this I can calculate at which brightness the hue inernal dimming should be
  7. sendCommand (estimated brightness) and stop the internal dimming within the lamps

The following code shows how this could be realized with a simple rule for a group of four white GU10 lamps:

var DIM_TIME = 4000;  // defines the time for an dim-cycle from 0 to 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));
}

Well the calculated estimation assums that the dimming, triggered with the “.fadingLightCommand” is linear. From my point of view so it is. I get a smooth diming for all lamps, none of them has another behavior. The only flaw is that the lamps may briefly change their brightness again when stopped. But to detect this effect you have to know that it could appear. MAybee it should be fixed with a small timeoffset …

Okay, thats all. I hope that I can now give something back to the forum that has helped me so often.

Thanks, have success and stay healthy
Stef

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.