@Sim209 Here’s roughly what I think may be happening in this scenario (and possibly also in your other scenarios):
The script asks the lamp to set itself to 1 brightness.
The lamp then processes that set-brightness command.
The script then asks the lamp, “What’s your current brightness?”
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.”
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!)
+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.
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:
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.
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?
@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?
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.
It works brilliantly on my fancy lights with integrated leds.
However, with Philips Hue light bulbs I have noticed that they don’t fade in smoothly, whichever curve I apply. There’s a noticeable jump from 0 to 60% (estimate) brightness, and then an underwhelming fade in effect. I found some reports online saying that this is typical for led bulbs and, for Philips hue lights specifically, works better with the Hue Bridge (which I haven’t tested). Has this been your experience as well?
@Ark88888 If I might ask, would you be open to trying a quick test automation?
If so, try creating an automation that has a “run in parallel” action, and then within that “run in parallel” action, try adding only four “light: turn on” actions—one for each lamp.
When you run that test automation, do those four lights turn on at the same time? Or no?
In short, I think your lamp might be fibbing a bit:
If you might be interested in confirming that hunch, you can do so by enabling debug logging and then running your fade:
First, if you haven’t yet installed the Home Assistant Log Viewer add-on , install that. (This should add a “Log Viewer” item to your sidebar within Home Assistant.)
Then open the Log Viewer in one of your browser tabs. And then in a second browser tab, open the automation with your test fade.
Then within the automation with the test fade, enable Debug Mode within the options for Ashley’s Light Fader.
From there, run that fade, and while the fade is running, switch over to the browser tab where you’ve got the Log Viewer open.
You should see some debugger output within the Log Viewer that looks something like this:
(I’ve sliiightly reformatted the below log bits just for clarity.)
2024-04-30 15:02:25.660 WARNING (MainThread) [homeassistant.components.system_log.external]
easeInOutSine easing type with 686 ms delay. remainingTimeInMilliseconds = 44923, and absoluteBrightnessSpan = 50
2024-04-30 15:02:25.661 WARNING (MainThread) [homeassistant.components.system_log.external]
startBrightness = 25, endBrightness = 75, and processingDelayInMilliseconds = 62
2024-04-30 15:02:28.548 WARNING (MainThread) [homeassistant.components.system_log.external]
Set Living Room Lamps to 26 brightness. (Linear brightness would have been 28.)
Delay is 686 ms. Elapsed time is 2.97 seconds. (endBrightness is 75.)
2024-04-30 15:02:30.750 WARNING (MainThread) [homeassistant.components.system_log.external]
Set Living Room Lamps to 27 brightness. (Linear brightness would have been 31.)
Delay is 686 ms. Elapsed time is 5.17 seconds. (endBrightness is 75.)
2024-04-30 15:02:32.237 WARNING (MainThread) [homeassistant.components.system_log.external]
Set Living Room Lamps to 28 brightness. (Linear brightness would have been 32.)
Delay is 686 ms. Elapsed time is 6.66 seconds. (endBrightness is 75.)
And if you might like, feel free to share an excerpt from your debug logs, and I’ll be happy to give that a look.
It so happens that I have some Philips Hue bulbs myself, and although I haven’t specifically come across the issues that you had mentioned, I’d be happy to try to chime with some thoughts.
I have a potential idea about what you might be running into here—and the gist of it is that nonsmooth fades are generally caused by the fader script having to take too large of a jump between its brightness, levels. For instance, if the fader were to have to apply brightness levels of 1%, 20%, 40%, 80%, and then 100%, that would almost definitely not be terribly smooth.
Here are the two main things that can cause fades to have large brightness jumps in their sequence:
It so happens that any given light takes a certain amount of time to process each set-brightness command. For instance, if a given light were to hypothetically take 500 ms to process a given light command, and if the fade were to be requested for 5 seconds, then that would only allow for about 10 set-brightness commands between the start of the fade (0 seconds) and the finish (5 seconds).
So if it might turn out that your light isn’t be able to process set-brightness commands very quickly, then that may be one factor.
A related factor is that even if a given light might be able to process set-brightness commands rather quickly, you still can’t exceed what the math might allow.
So for example, let’s suppose that a given lamp might be able to process set-brightness commands super quickly—perhaps it might be able to process 10 per second (which would work out to 100 ms per set-brightness command). In that scenario, if supposing that you were to try to fade that light from 0% to 100% over a span of 1 second, that probably still wouldn’t work go very smoothly since you could only fit in about 10 set-brightness commands within that 1 second.
Of those two factors, the first one—the inherent delay within the lamp—is outside of your control. While the second one—the fade’s duration or the fade’s brightness span—is something that you might have some control over.
Fortunately, you’ve already affirmed your good taste by buying Philips Hue bulbs. [Philips isn’t a sponsor or anything—I just like their stuff.] It so happens that Philips Hue bulbs natively support transitions, and when bulbs natively support transitions, those are almost always way smoother than what any script can possibly achieve.
So if you might need to fade your Philips Hue bulbs between two brightness levels super quickly, I would recommend using the bulbs’ built-in native transitions.
Or if you might be feeling daring, you could potentially instead try enabling this script’s “If available, use the lamp’s native transitions too?” option, which attempts to apply its own fade while mixing that with the bulb’s native transitions to help smooth out the overall effect. That being said, that feature is marked as “experimental” for a reason—it’s something that won’t always necessarily offer much (if any) improvement over the lamp’s built-in fade transition.
In short, I think that your best bet would be to lean on your bulb’s support for native transitions. (And if you might like, you could also potentially try out the “If available, use the lamp’s native transitions too?” option too—although if perhaps you might prefer to skip straight to using your bulb’s native transitions, that’s a reasonable approach too.)