Dimming from current lighting level to 15% over 20 seconds

I’m new to automating with Homey Pro. How do I create a “Movie Time” flow to smoothly dim the Family Room lights from the current level to 15% over 20 seconds? My dimmer switch is a GE Enbrighten.

Look at fe

[APP][Pro] Chronograph - Adds precise timer, stopwatch and transition functionality to Homey

Or Transitions — Flexible time transitions

There might be a “duration” slider when setting the dim level.

did that for a Sonos setup, but the method would be the same:

1 Like

In my opinion the easiest way is to use the build-in option Duration… of the flow card Dim to… itself, as @Rmb already mentioned. However, this is not supported by all lamps.


To open the menu, right klick on the flow card.

1 Like

Not all lights have the option for duration. For example every light presented by Zigbee2MQTT and I think I missed it with Matter lights when I tried using Philips Hue lights with Matter.

My lights do not have the option for Duration, so, in Advanced Flows, I did multiple steps one second apart to dim the lights. Unfortunately, I do not know how to start from the existing light level, so, I start at 50% down to 15%.

(attachments)

When you don’t mind using scripts, you can use this one below;
It dims a light from it’s current level to the level you saved in a variable. It automatically dims up or down to that value;

You can use flow card “Run code with argument”
Just copy/paste this script, and enter the variable name which holds the desired dim value (0.01 - 1)
Enter the lamp name as argument in the flow card

/* Dim-- a light in steps to [variable] level */

// Use flowcard "Run code with argument",
// the argument is the lamp's name
 
// (for a media device for it's volume: device.class = amplifier, volume = volume_set).

// USER INPUT
// For dimming to a Logics variable value (0.01.01 - 1),
// enter variable name here
let varName = "NightDimlevel";
// Enter a delay time (for the next dim level)
var waitForDimlevel = 750; /* time in ms */
// Enter the value to increase the dim level with
var myDimlevelStep = 0.02; 
// User input end

let myLight = args[0];
// only for testing with console
//myLight = "Lamp Voorraam";
var myDimlevelEnd = ''; // don't change this

if (myLight == '' || myLight == undefined) {
    console.log ('Missing argument, enter a device name at flowcard argument field');
    return(false);
} else {

// Reading the variable value
// and updating 'myDimlevelEnd'
const logicVars = await Homey.logic.getVariables()
for (var iLogicVar in logicVars){
  if (logicVars[iLogicVar].name == varName)
  myDimlevelEnd = logicVars[iLogicVar].value
}
log(`\n- Value from logics var [${varName}]: ${myDimlevelEnd}\n`)

var waitTime = ''
// Get all devices
const devices = await Homey.devices.getDevices();

  // Loop over all devices
  for (const device of Object.values(devices)) {

    if (device.name == myLight) {

      // If this device is a light (class)
      // Or this is a 'What's plugged in?'-light (virtualClass)
      if (device.class === 'light' || device.virtualClass === 'light' || device.class == 'button') {

      // Get the current dim level of the device
      var currentDimlvl = ''
      currentDimlvl = device.capabilitiesObj.dim.value

      // Just to inform you while testing
      await log(`- Current Dim level: ${currentDimlvl} \n- Wait for ${waitForDimlevel}ms between each step of ${myDimlevelStep} `)         
      
      // this works, but myDimlevelStep has to be rounded
      if ( myDimlevelEnd >= currentDimlvl ) {
        await log("- " + myDimlevelEnd + " > " + currentDimlvl )
        for (let step = currentDimlvl ; step <= myDimlevelEnd; step += Number(myDimlevelStep) ) {  
          // for (var i = 0; i < myVar.length; i+3) {
            // every three
          // }
          await wait(waitForDimlevel);
          step = Math.round((step)*100)/100; // round to 0.00      
          
          log(`\nDimming ${device.name} to ${step}`)
          
          // decreasing the dim level
          await device.setCapabilityValue('dim', step)
            .then(() => log('OK'))
            .catch(error => log(`Whoops an Error!:`, error));

          if (step <= 0.03) {
          device.setCapabilityValue('dim', 0.01); 
          }
          // just in case, quit if 'step' has become zero or 1          
          if (step < 0.01 || step > 0.99) {
          break;
          }
        }
      }

      if ( myDimlevelEnd <= currentDimlvl ) {
      await log("- " + myDimlevelEnd + " < " + currentDimlvl )
        for (let step = currentDimlvl ; step >= myDimlevelEnd; step -= Number(myDimlevelStep) ) {  
          // for (var i = 0; i < myVar.length; i+3) {
            // every three
          // }
          await wait(waitForDimlevel);
          step = Math.round((step)*100)/100; // round to 0.00      
          
          log(`\nDimming ${device.name} to ${step}`)
          
          // decreasing the dim level
          await device.setCapabilityValue('dim', step)
            .then(() => log('OK'))
            .catch(error => log(`Whoops an Error!:`, error));

          if (step <= 0.03) {
          device.setCapabilityValue('dim', 0.01); 
          }
          // just in case, quit if 'step' has become zero or 1          
          if (step < 0.01 || step > 0.99) {
          break;
          }
        }
      }
     }
    }
  }
}

return(true);

Here you see the lamp name as argument in the flow card

Dim up vid:
GIF_20250411_141802_527

Dim down vid:
GIF_20250411_141919_690

2 Likes

I know that, and I already pointed that out:

I have a Fibaro Walli Dimmer in use and this feature is also not supported.
What I don’t know, however, is if the reason for this is that the device doesn’t technically support this feature, or if the feature isn’t implemented in the Homey Fibaro app.

Thank you @Peter_Kawa ! Not knowing anything really about Script programming… I did some tinkering and figured everything out! Great education for me!

1 Like

YW!
I’m no programmer either, I built this script a while ago with all info I could find. And no cheatGpt of course :zany_face: