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

Hi @handcoding . I just created an account and logged in to say thanks. This is perfect for gradually fading out the lights in my snake tank instead of turning them off suddenly. It works perfectly. Kudos!

1 Like

Thank you @handcoding ! Your fader script worked a treat.

One question, though: am I the only one who would like to do the opposite (defade?) for lights in the morning. Start from the low brightness and warm temp the lights were faded to in the evening and work up to the normal day lights. I tried but the script didn’t work for that purpose.

1 Like

I made some test, your work seems awesome @handcoding … Unfortunatly, i encounter some problems.

1 - If the light is off (for a 0% → 100% brightness fading), using the script will lead to the following situation : The light switch on at the minimal brightness (or even not switch on) and the script instantanly stop.
→ a little turnaround is easy : setup the light at minimal brightness (1%) before using the script
→ Hint for solution : Looking my logs, I think that the default value of ‘Turn of the fade if the light is switch off’ was creating a problem. I hadf an error with that, but the light wan’t turned off, it was the initial state. Turning on and off this option resolve the problem.

2 - If i try to change, brightness and color… Only Color Temperature changes and the brightness stay at minimal value

Thanks a lot for your work and your help :slight_smile:

Thanks so much for your kind words, @draxonic!

@carnosine Could you perhaps elaborate on the troubles that you had encountered with this scenario?

If you might like, feel free to enable the script’s logging for more info. (If you haven’t yet installed the Home Assistant Log Viewer add-on , I’d recommend installing that. That should add a “Log Viewer” item to your sidebar within Home Assistant.)

@Sim209 Could you perhaps share an excerpt from your logs from when you had tried this? (The script should automatically compensate if you enable "Turn off the fade if the light is switched off.”)

If you might be up for sharing your logs for this scenario, I’d be interested in taking a look at those too. The script should be able to fade both color temperature and brightness (and in my testing on my home system, it’s been able to do that).

(If you haven’t yet installed the Home Assistant Log Viewer add-on , I’d recommend installing that. That should add a “Log Viewer” item to your sidebar within Home Assistant.)

The lamp’s brightness or color temp just wasn’t changing at all when trying to go brighter/cooler with the script. I thought that the script was never meant to be used that way and that’s why. Sure I’ll try to see why that is if the script indeed should and does work in that direction, too.

I don’t think I can install add-ons because I’m on a docker core installation. But I’ll try and dig up some logs if the script indeed is supposed to work in both directions.

The logs say this:

—clip—
2024-07-24 16:58:57.340 WARNING (MainThread) [homeassistant.components.system_log.external] Stopped Ashley’s Light Fader because a color fade was requested for Cabinet, but its current color temperature doesn’t seem to be defined using Kelvin units. (You can look into this by going into Developer Tools and checking that Cabinet has a defined “color_temp_kelvin” attribute.)
—clip—

This is true. The lamp is an Ikea lamp and it has an internal temp scale that is not in Kelvin. However I have set it up identically for fade and defade where a number helper provides the target temp in the internal scale. And it works on fade but croaks on defade.

@carnosine For whatever it’s worth, I personally think of “fading” as “transitioning between two levels”—though I get the impression that you might not think of “fading” in that way?

So I just wanted to check, when you when you refer to “fading” and “defading,” does “fading” for you mean “going from brighter to dimmer”? And does “defading” mean “going from dimmer to brighter”? (Or is it the other way around?)

And along those lines—when you say, “I have set it up identically for fade […] and it works on fade,” is that to say that you were able to use the script to have the light simultaneously go from brighter to dimmer and from a higher color temperature to a lower color temperature? And that that worked fine? (Or it is the reverse?)

(This script can only fade color temperatures in Kelvin, so if you might be saying that the script is able to fade from a higher non-Kelvin color temperature to a lower non-Kelvin color temperature, I’m not sure how that might be possible?)

I meant fading = going from cooler to warmer and from brighter to dimmer. Defading is the reverse. Defading: dat’s only da mounin.

Both my Ikea and Philips Hue bulbs takes color_temps in mired which is a Kelvin scale but not the regular one. Values are between say 100-500. As strange as it may seem your script does work to fade those lights.

There is some interpretation going on somewhere as the HA gui does show those bulbs color temp in regular Kelvin though the z2m integration uses the mired scale.

If I might ask, when you view your Ikea lights in Home Assistant’s Developer Tools, what does its entry show for supported_color_modes? (For instance, my Philips Hue lights shows supported_color_modes: color_temp, xy.)

And on a related note, could you perhaps enable logging for a sample fade for your Ikea lights (the fade that works), and then could you share the first 5 lines from the log output here? (If your Ikea lights were to support only mired—which this script doesn’t support—I’d be curious to see what might actually be happening there.)

I actually replaced the Ikea bulbs with Philips ones already. What I can say is that the Ikea bulbs do support color_temp and xy (though that mode is listed as color_xy in z2m). Here are the capabilities from z2m’s documentation: IKEA LED1924G9 control via MQTT | Zigbee2MQTT

Both the Ikea and Philips bulbs are/were used via z2m. Also both support only mired for color_temp via z2m so HA is definitely doing some translating there.

Though the z2m integration does not support Kelvin your script works when you define color temp targets for the Philips bulbs in Kelvin. Works for the evening fade, that is. I haven’t tried the other direction yet. That’ll have to be tomorrow.

That the mqtt integration or HA itself is doing some translating with these values makes it all a bit confusing.

Nothing to report really except with the Philips bulbs at least everything just works using Kelvins instead of mireds.

@handcoding Here’s my tests and the corresponding logs:

A1) Only birghtnesss from off to 255
→ Nothing appends

2024-07-28 16:48:07.467 WARNING (MainThread) [homeassistant.components.system_log.external] easeInOutSine easing type with 100 ms delay. remainingTimeInMilliseconds = 39920, and absoluteBrightnessSpan = 255
2024-07-28 16:48:07.470 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 0, endBrightness = 255, and processingDelayInMilliseconds = 35
2024-07-28 16:48:08.605 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 1 brightness. (Linear brightness would have been 8.) Delay is 100 ms. Elapsed time is 1.24 seconds. (endBrightness is 255.)
2024-07-28 16:48:08.836 WARNING (MainThread) [homeassistant.components.system_log.external] Stopped Ashley’s Light Fader because Ampoule Tapo was turned off during the fade.

A2) Only birghtnesss from off to 100%
→ The light gets on but stay at 1% Brightess

2024-07-28 16:49:59.887 WARNING (MainThread) [homeassistant.components.system_log.external] easeInOutSine easing type with 297 ms delay. remainingTimeInMilliseconds = 39934, and absoluteBrightnessSpan = 100
2024-07-28 16:49:59.890 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 0, endBrightness = 100, and processingDelayInMilliseconds = 36
2024-07-28 16:50:02.261 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 1 brightness. (Linear brightness would have been 5.) Delay is 297 ms. Elapsed time is 2.45 seconds. (endBrightness is 100.)
2024-07-28 16:50:02.586 WARNING (MainThread) [homeassistant.components.system_log.external] Stopped Ashley’s Light Fader because Ampoule Tapo was turned off during the fade.

A3) Same after disable and enable the “Cancel the fade if the lamp is turned off during the fade?” Option
→ The light gets on but stay at 1% Brightess (Finaly i made a mistake on last post it doesn’t work)

2024-07-28 16:52:39.777 WARNING (MainThread) [homeassistant.components.system_log.external] easeInOutSine easing type with 297 ms delay. remainingTimeInMilliseconds = 39945, and absoluteBrightnessSpan = 100
2024-07-28 16:52:39.780 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 0, endBrightness = 100, and processingDelayInMilliseconds = 36
2024-07-28 16:52:42.153 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 1 brightness. (Linear brightness would have been 5.) Delay is 297 ms. Elapsed time is 2.44 seconds. (endBrightness is 100.)
2024-07-28 16:52:42.473 WARNING (MainThread) [homeassistant.components.system_log.external] Stopped Ashley’s Light Fader because Ampoule Tapo was turned off during the fade.

A4) Same after disable the “Cancel the fade if the lamp is turned off during the fade?” Option

Too much things in the log because it’s working :wink:



B1) Now Brightess and Color (Always with the “Cancel the fade if the lamp is turned off during the fade?” option disable)
From off to 255 Brightness
From 2500K to 6500K
→ As you see the color change but not the Brightness

2024-07-28 17:01:11.487 WARNING (MainThread) [homeassistant.components.system_log.external] easeInOutSine easing type with 100 ms delay. remainingTimeInMilliseconds = 19900, absoluteColorTemperatureSpan = 4000, and absoluteBrightnessSpan = 0
2024-07-28 17:01:11.490 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 255, endBrightness = 255, startColorTemperature = 2500, endColorTemperature = 6500, and  processingDelayInMilliseconds = 78
2024-07-28 17:01:11.843 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 2502°K. Delay is 100 ms. Elapsed time is 0.46 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:12.498 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 2509°K. Delay is 100 ms. Elapsed time is 1.12 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:13.171 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 2538°K. Delay is 100 ms. Elapsed time is 1.8 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:13.892 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 2591°K. Delay is 100 ms. Elapsed time is 2.52 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:14.279 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 2670°K. Delay is 100 ms. Elapsed time is 2.9 seconds. (endColorTemperature is 6500.)
[...]
2024-07-28 17:01:29.518 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 6331°K. Delay is 100 ms. Elapsed time is 18.14 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:30.180 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 6427°K. Delay is 100 ms. Elapsed time is 18.81 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:30.838 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 6472°K. Delay is 100 ms. Elapsed time is 19.46 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:31.555 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 6496°K. Delay is 100 ms. Elapsed time is 20.18 seconds. (endColorTemperature is 6500.)
2024-07-28 17:01:32.219 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 6500°K. Elapsed time is 20.85 seconds.

B2) And finally:
From 1 to 255 Brightness
From 2500K to 6500K
→ Stay at 1% Brightness, the color change but the script ends because of brightness error over 10%

2024-07-28 17:08:46.094 WARNING (MainThread) [homeassistant.components.system_log.external] easeInOutSine easing type with 100 ms delay. remainingTimeInMilliseconds = 19954, absoluteColorTemperatureSpan = 4000, and absoluteBrightnessSpan = 252
2024-07-28 17:08:46.097 WARNING (MainThread) [homeassistant.components.system_log.external] startBrightness = 3, endBrightness = 255, startColorTemperature = 2500, endColorTemperature = 6500, and  processingDelayInMilliseconds = 31
2024-07-28 17:08:46.432 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 3 brightness and 2501°K. (Linear brightness would have been 6.) Delay is 100 ms. Elapsed time is 0.4 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:47.089 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 3 brightness and 2507°K. (Linear brightness would have been 10.) Delay is 100 ms. Elapsed time is 1.06 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:47.760 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 5 brightness and 2535°K. (Linear brightness would have been 18.) Delay is 100 ms. Elapsed time is 1.73 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:48.129 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 8 brightness and 2584°K. (Linear brightness would have been 26.) Delay is 100 ms. Elapsed time is 2.1 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:48.789 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 11 brightness and 2621°K. (Linear brightness would have been 31.) Delay is 100 ms. Elapsed time is 2.76 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:49.739 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 16 brightness and 2703°K. (Linear brightness would have been 39.) Delay is 100 ms. Elapsed time is 3.71 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:50.090 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 25 brightness and 2851°K. (Linear brightness would have been 51.) Delay is 100 ms. Elapsed time is 4.06 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:50.745 WARNING (MainThread) [homeassistant.components.system_log.external] Set Ampoule Tapo to 29 brightness and 2916°K. (Linear brightness would have been 56.) Delay is 100 ms. Elapsed time is 4.71 seconds. (endBrightness is 255 and endColorTemperature is 6500.)
2024-07-28 17:08:50.872 WARNING (MainThread) [homeassistant.components.system_log.external] Stopped Ashley’s Light Fader because Ampoule Tapo was found to be at 1%, a difference of 10 percentage points from the expected brightness of 11%, which is higher than the auto-cancel threshold of 10 percentage points

Hope its helping :wink:

Hi there, I am trying to use this script. However, I am getting an error.

Error: UndefinedError: ‘light’ is undefined

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

Great work @handcoding

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

Regards

1 Like

this is great! Thank you.

1 Like

Ashley, this is great. Finally a simple to understand and implement script that does exactly what it
Says it does!

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.

Any suggestions to resolve this?

1 Like

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?