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.
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.)
@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.