Ashley’s Light Fader 2.0✨: fade lights and/or color temperature with your choice of easing (curves), including ease-in, ease-out, and ease-in-out

I do have one issue; the script works perfectly for a single light, but if I add multiple, it doesn’t dim any of them; it I execute just the script, it gives a hash list error.

Hi, @robert10! And thanks very much for your kind words!

If you might like to fade multiple lights at the same time, you can do that by adding a “run in parallel” action to your automation and then adding multiple simultaneous calls to this script (one script call for each light) within that “run in parallel” action.

That is to say: while this script can’t natively fade multiple lights, you can call multiple instances of this script in parallel to achieve the same effect.

Interesting, would running this script on a ‘light group’ (via ‘Helpers’) not accomplish the same thing?

@RickFurtado I haven’t personally tested this script on a light group, but that might also potentially be an option?

If you (or any other folks) might happen to give that a go, I’d be curious to hear how that might pan out.

Many thanks for your kind words, @C.Potgieter!

This works flawlessly for my WLED strips.
They however don’t support kelvin temperatures.

Any chance of supporting temperature fade for lights that don’t support Kelvin?
But rather an xy or rgb value for a “fake” temperature

I’m not theoretically opposed to considering adding support for lights that don’t use Kelvin. But the tricky part is that I just haven’t been able to find reliable formulas for converting from XY → Kelvin, Kelvin → XY, RGB → Kelvin, or Kelvin → RGB.

All the same, if by chance you—or anyone else—might be able to scrounge up some formulas for converting between those formats, I’d be open to giving some more thought to adding support for them.

(To potentially add support for XY, I would need a formula for converting from XY to Kelvin as well as a formula for converting from Kelvin to XY. Similarly, to potentially add support for RGB, I would need a formula for converting from RGB to Kelvin as well as a formula for converting from Kelvin to RGB.)

Error: UndefinedError: ‘light’ is undefined

I am sure this is a user error issue. but any help would be appreciated.

@Steven_McCartt Just to double-check, are you setting the light parameter when you run the script?

That should hopefully show as the topmost option when you call the script, and that lets the script know which light you’d like to run the fade on.

@Sim209 Here’s roughly what I think may be happening in this scenario (and possibly also in your other scenarios):

  1. The script asks the lamp to set itself to 1 brightness.
  2. The lamp then processes that set-brightness command.
  3. The script then asks the lamp, “What’s your current brightness?”
  4. At this point, the lamp should reply to the script with “I’m at 1 brightness”—because that’s what the lamp’s brightness should be if it had actually processed that set-brightness command—but instead the lamp replies with “I’m at 0 brightness.”
  5. So from there, the script exits early because it thinks that the lamp had been turned off.

The way that lamps typically work in steps 1 and 2 is that they accept the set-brightness command, and then the script doesn’t continue until that set-brightness command has been applied.

But for some reason, when your particular lamp gets to step 2, the lamp seems to be saying to the script “All good—I’ve processed that set-brightness command!” even though it hasn’t actually processed that set-brightness command just yet. And—sure enough—when the script gets to step 3 where it checks whether the lamp is at 0 brightness (off), the lamp is indeed still at 0 brightness.

I’m not really sure why your lamp might be acting as if it had processed that set-brightness command (in step 2) when it actuality it hadn’t yet processed that set-brightness command.

Perhaps it may be that the lamp isn’t able to process set-brightness commands all that quickly, and perhaps the lamp might be pretending to have processed that set-brightness command so as to appear snappier than it might actually be?

I don’t have much solid advice here, but if indeed your lamp might not be able to process set-brightness commands from the script all that quickly, you could perhaps try increasing the script’s Minimum delay per step parameter to try to ensure that the lamp isn’t being sent set-brightness commands faster than the lamp can handle?

And as that goes, I believe that the Minimum delay per step parameter’s default value is 100 ms, but you might potentially try something like 200 ms or 250 ms. Or maybe even as high as 500 ms? (And if you do, I’d be most curious to hear how things might turn out!)

@carnosine So just to check—are things working for you now? (If perhaps not, I’d be quite open to trying to help if I can.)

+1 for allowing other colour temperature methods. I had the previous version of this script working for brightness and yesterday updated it to the latest one (I don’t see version numbers anywhere) in the hope to use it for a sunrise effect with my WLED strip but it didn’t work. The light just stayed on it’s initial temp and brightness.

Hi, @sparkydave!

I’d be open to considering other color-temperature methods if by chance you (or anyone else) might be able to uncover formulas that can convert between, say, WLED → Kelvin as well as Kelvin → WLED. Without those formulas, my hands are unfortunately tied.

And I’m not trying to imply that those formulas don’t exist somewhere—they might? But I just haven’t been able to find them through my own googling.

If you might be curious at all, you can see the script’s version number by opening any automation that calls the script and then checking near the top of the script call:

1 Like

For everyone’s benefit, there was a discussion around this some time ago and the best source I’ve come across is also the one that was quoted then.

You can go from XY to CCT (in Kelvin) with an approximation, but you cannot go the other way. You have to read the above article to understand why. These things aren’t equivalent. Mathematically, by trying to go from Kelvin to CCT doesn’t have a single solution: you’re going from one variable (Kelvin) to two (X and Y).

The equivalent is to ask: In a 3D room, I’m standing 1m from one of the walls. Where exactly in the room am I? You cannot answer this with a point. You could be standing (or floating) anywhere on a plane 1m from the wall.

3 Likes

Sorry having troubles making this work with a motion sensor
could someone make a template that uses an occupancy sensor to use this fader to ease on a light and then ease it off after the light has been on for some period of time?

@rsingh Just to check—are you looking to have the light turn off based on time alone?

For instance, if supposing that “some period of time” were to be 2 minutes, are you looking to have the light turn on when motion is detected—and then have the light turn off after 2 minutes whether or not there’s motion? Or are you looking to have the light turn off once there hasn’t been motion for, say, 2 minutes?

the first one “light turn on when motion is detected—and then have the light turn off after 2 minutes whether or not there’s motion”

@rsingh For that sort of thing, I’d recommend something along these lines:

~begin pseudo code~

When

  • The motion detector turns from off to on

Then do:

  • Ashley’s Light Fader
    • Lamp: [your lamp]
    • Fade time: 15 seconds [or whatever duration you might prefer]
    • End brightness level: 100%
  • Wait 2 minutes
  • Ashley’s Light Fader
    • Lamp: [your lamp]
    • Fade time: 15 seconds [or whatever duration you might prefer]
    • End brightness level: 0%

~end pseudo code~

Does that help at all?

Or if by chance you might still be stuck, feel free to share how far you’ve gotten in your automation and which part you’re stuck on, and I’ll be happy to help out if I can.

Great job, the dimming/brightening feature works very well, but I have a small issue. First, in order for everything to work, I have to set each light as a separate automation (four different light sources). Second, despite having the same time trigger, the lights turn on with a delay: lights 1 and 2 almost simultaneously (a few seconds after the set time), then 3, and finally, after a longer delay, light 4. The entire process takes about three minutes in total. I noticed that the duration of the entire process depends on the dimming/brightening time I set (currently 20 minutes). Is there any way to optimize this?

2 Likes

@Ark88888 Just to check, is your goal to have a single trigger that activates the fades for 4 lights at the same time?

If that may be the case, one way that you can optimize that would be to:

  1. Create a single automation with that trigger
  2. Then, within the “Then do” section, add a “Run in parallel” action.
  3. From there, inside that “Run in parallel” grouping, add each of your 4 fades.

And with that setup, that should let you have all 4 fades run at the same time.

Does that perhaps help with your situation? Or after trying that, are there by chance any other loose ends?

I had the same (or very similar question) and the “run in parallel” option worked great. Thank you so much.

1 Like

Thank you so much for your response! Unfortunately, it didn’t help. Each light turns on separately at random intervals, but for some reason, my previous setup with four separate automations causes three of the lights to turn on simultaneously, while only the fourth one turns on with a delay.

Hi! I got one light working amazingly… but in parallel, one turns on and fades, the other turns on and stops at 1%. Any ideas?

alias: Fade in light
description: ""
trigger:
  - platform: time
    at: "11:18:00"
condition: []
action:
  - parallel:
      - action: script.light_fader
        data:
          lampBrightnessScale: zeroToTwoFiftyFive
          easingTypeInput: easeInOutSine
          endBrightnessPercent: 100
          endBrightnessEntityScale: zeroToTwoFiftyFive
          autoCancelThreshold: 10
          shouldStopIfTheLampIsTurnedOffDuringTheFade: true
          shouldResetTheStopEntityToOffAtStart: false
          shouldInvertTheValueOfTheStopEntity: false
          minimumStepDelayInMilliseconds: 100
          shouldTryToUseNativeLampTransitionsToo: false
          isDebugMode: true
          light: light.hue_ambiance_luster_1
          transitionTime:
            hours: 0
            minutes: 1
            seconds: 0
      - action: script.light_fader
        data:
          lampBrightnessScale: zeroToTwoFiftyFive
          easingTypeInput: easeInOutSine
          endBrightnessPercent: 100
          endBrightnessEntityScale: zeroToTwoFiftyFive
          autoCancelThreshold: 10
          shouldStopIfTheLampIsTurnedOffDuringTheFade: true
          shouldResetTheStopEntityToOffAtStart: false
          shouldInvertTheValueOfTheStopEntity: false
          minimumStepDelayInMilliseconds: 100
          shouldTryToUseNativeLampTransitionsToo: false
          isDebugMode: true
          light: light.hue_ambiance_luster_2
          transitionTime:
            hours: 0
            minutes: 1
            seconds: 0
mode: single

anybody? :face_holding_back_tears: