# Dimming from current lighting level to 15% over 20 seconds

**URL:** <https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389>\
**Category:** Questions & Help\
**Tags:** homey-pro\
**Created:** [April 9, 2025, 11:50pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389 "2025-04-09T23:50:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby\_Gonzales](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bobby_gonzales/32/121027_2.png) [@Bobby\_Gonzales](https://community.homey.app/u/Bobby_Gonzales)\
**Post date:** [April 9, 2025, 11:50pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/1 "2025-04-09T23:50:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [April 10, 2025, 4:26am UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/3 "2025-04-10T04:26:54Z")

</div>

Look at fe

[[APP][Pro] Chronograph - Adds precise timer, stopwatch and transition functionality to Homey](https://community.homey.app/t/app-pro-chronograph-adds-precise-timer-stopwatch-and-transition-functionality-to-homey/18214)

Or [Transitions — Flexible time transitions](https://community.homey.app/t/transitions-flexible-time-transitions/443)

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [April 10, 2025, 7:42am UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/4 "2025-04-10T07:42:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [April 10, 2025, 9:28am UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/5 "2025-04-10T09:28:07Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/d/7d0c3b28dda717737ee593fe7c196fa9514bd245.png)

---

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [April 10, 2025, 10:07am UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/6 "2025-04-10T10:07:46Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/b/ab7a1026a0fefd8bd56adf28e7725611ca06646b.png)  
To open the menu, right klick on the flow card.

---

<div class="post-metadata">

**Author:** ![OH2TH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oh2th/32/111414_2.png) [@OH2TH](https://community.homey.app/u/OH2TH)\
**Post date:** [April 10, 2025, 3:05pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/7 "2025-04-10T15:05:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bobby\_Gonzales](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bobby_gonzales/32/121027_2.png) [@Bobby\_Gonzales](https://community.homey.app/u/Bobby_Gonzales)\
**Post date:** [April 10, 2025, 3:44pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/8 "2025-04-10T15:44:45Z")

</div>

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)**
>
> ![Image.jpeg](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/b/9bb136935511d419edf6031f56653b44314d61a1.jpeg)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 10, 2025, 11:25pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/9 "2025-04-10T23:25:02Z")

</div>

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

```auto
/* 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);

```

 ![1000000712](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/8/a8e2957e7ca88fa483f1f7b12d56b3a68b4ba485.jpeg)

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

 ![1000000714](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/e/2e8ddad637624f8fe38fac714d63cdbde3129bea.jpeg)

Dim up vid:  
 ![GIF_20250411_141802_527](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/7/272dca24bf11d25d57c72d9a5c84a47712d59a8b.gif)

Dim down vid:  
 ![GIF_20250411_141919_690](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/e/5ef91c1163e66265ff3a715fc67c4a881bbaff6d.gif)

---

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [April 11, 2025, 1:19pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/10 "2025-04-11T13:19:09Z")

</div>

> [@OH2TH](#):
>
> Not all lights have the option for duration.

I know that, and I already pointed that out:

> [@DirkG](#):
>
> However, this is not supported by all lamps.

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.

---

<div class="post-metadata">

**Author:** ![Bobby\_Gonzales](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bobby_gonzales/32/121027_2.png) [@Bobby\_Gonzales](https://community.homey.app/u/Bobby_Gonzales)\
**Post date:** [April 12, 2025, 6:03pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/12 "2025-04-12T18:03:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 12, 2025, 6:07pm UTC](https://community.homey.app/t/dimming-from-current-lighting-level-to-15-over-20-seconds/134389/13 "2025-04-12T18:07:33Z")

</div>

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