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, @ronnieSVK—thanks so much for your kind words!

And for whatever it’s worth, while I totally understand your use case—and I also have an idea in the next paragraph that may be able to help with that!—I’m also slightly hesitant to add a secondary brightness slider for 0–255 if only because the script already has tons of options, and I just feel that with each additional field that I were to add, the script might become a bit more daunting to newcomers?

All the same, I also have an idea that I think may be able to resolve your use case: I believe that you can achieve what you describe if you were to add an input-number helper within your Home Assistant instance? And if by chance you might be new to that sort of thing, here’re the steps for that if it may be of interest—

  1. Within your Home Assistant instance, go to Settings → Devices & services.
  2. Then click on the “Helpers” tab (across the top).
  3. From there, click on “Create Helper” (at the bottom right)
  4. Then select “Number”.
  5. And then on the next screen, you might enter values such as these:
    • Name: “Extra-low brightness”
    • Icon: [anything that you’d like]
    • Minimum value: 1
    • Maximum value: 5
    • Display mode: slider
    • Step size: 1
    • Unit of measurement: “brightness”

(And all together, that might look something like this:)

  1. And then click “Create”.

  2. After you’ve created it, you should then see an entry for “Extra-low brightness” (or whichever name you’ve given it) within the list of items on the “Helpers” tab.

  3. Lastly, I’d recommend clicking on that “Extra-low brightness” entry and then setting its slider’s value to “1” (if it isn’t already set to that value).

From here, if you then open to the automation where you’re calling Ashley’s Light Fader, you can then make use of that entity by entering its name within the ”Use an entity instead for the end-brightness value?” field and then setting the “The end-brightness entity’s brightness scale” field to “0 to 255”:

And with that in place, I think that that should hopefully do what you need. And if you might have any questions along the way, feel free to reply here, and I’ll be happy to chime in!

1 Like

Thank you for the really helpful script! I was just wondering how I could use this script to always fade my light if I change the brightness. So that if I change the brightness a fade should always be applied. I thought that using a number helper as an entity for the end-brightness value should do the job. It does work if I directly control the number helper. But I am controlling my lights through my Google Assistant and my Google Home App where the number helper does not appear and thus cannot be used. Is it somehow possible to make this work?

1 Like

Hi, @kubilayc38!

For better or for worse, what you describe—having this fader script be automatically applied for all light transitions—isn’t really possible. And that’s in part because when you change your lights through Google Assistant or the Google Home app, that controls the lights directly, which bypasses most of the triggers that Home Assistant can hook into.

With that being said, if the lights that you’re wanting to control might have built-in support for transitions, there’s a chance that you might be able to get an automatic fading effect whenever you change the lights’ levels through Google Assistant or the Google Home App by setting up a default transition time for some (or all) of your lights using light_profiles.csv.

I haven’t messed about with light_profiles.csv myself, so if by chance you were to get stuck, I unfortunately won’t be able to help you with that part. But if it may help as a starting point, it looks like this thread goes over the broad strokes of the syntax for light_profiles.csv.

1 Like

Hello Ashley,
This script is great thank you for your great effort. I could make it work with my Govee led strip light transition for turning on more smoothly. But i want it turn off exactly how it turned off. Is it even possible with this script ?

Hi @yusufbogatepe!

Could you perhaps elaborate on what you mean by “I want it turn off exactly how it turned off”? I don’t think I quite understand.

Hi @kvikindi and @ThatBlockyPenguin,

Just to give you and other folks an update—I’m currently working through the code for adding color-temperature-fading support to the script.

I can’t make any promises as to when the feature will be fully complete, but I wanted to let you know that it’s in progress.

2 Likes

Amazing news, thanks Ashley :slight_smile:

1 Like

Hey Ashley. I’ve got an existing basic script based on Jeffrey Stone’s (Slackerlabs) Lights With Level script that works pretty well, but I’ve added your script too and will put it through its paces later :laughing:.

I’m also now stalk… I mean following you on X or Twitter or whatever it’s called these days :laughing:

Thanks.

1 Like

I’m rooting for ya!
Appreciate the update!
Your script is such an effortless addition to my family’s daily use of HA :blush:
I’m baffled that this feature isn’t baked into HA itself!
Stay fantastic!

2 Likes

This is fantastic! I’m wondering if it’s possible to allow an area to be input in lieu of entity id. I know you can use groups, and maybe that’s actually the way to go… What I’m hoping to do is use this script with the assist feature, and say “sunset {{ area name }}” to trigger a script called “sunset” (which then calls your script,) on lights in whatever area is mentioned.

I tried using

{{ expand(states.light)|selectattr('entity_id', 'in',
         area_entities('Living Room'))|map(attribute='entity_id')| list}}"

but I get an error about dict not having “lower” probably because it’s expecting a string instead of a list of entity ids

1 Like

@ThreepE0 For better or for worse, that isn’t something that the script supports.

That’s in part because a given area might have various lights that could all be at different starting brightnesses—and so if the script were to try to natively support fades for multiple lights like that, this script would probably need to be multithreaded, which I don’t think is in the cards.

With that being said, as one alternative option, you could certainly use groups (as you had mentioned). Or—alternately—you could potentially create an automation that were to make use of the “Run in Parallel” action to call this script multiple times, once for each lamp in a given room. (And if any of that might not quite make sense right away, I’d be happy to elaborate on that.)

Hiya, friends!

By the way, I’ve just released version 2.0 of Ashley’s Light Fader, which includes a bunch of new features!

~~Some highlights ~~

  • You can now fade between color Kelvin temperatures. (And shout-outs to @damru, @kvikindi, and @ThatBlockyPenguin for requesting this!)
  • You can (optionally) have the script automatically cancel its fade if you turn off the lamp during the fade sequence.
  • And by request for @ronnieSVK: If you set a lamp to fade down to 1%, and if that lamp uses a 0-to-255 brightness scale, the script will infer you’re looking to have the lamp fade down to its lowest level—so the script will automagically fade the light down to 1/255 brightness.

Anyway, the post at the top of this thread has all the deets!

4 Likes

You magical hooman bean!
It works amazingly now, thank you!

My next challenge is with my esphome/libretiny-hacked RGBWW lightbulb that won’t play game.

Because I’ve set color_interlock: false (as I do love having fine grain control over all the colours!), it doesn’t present as a basic colours and a warm/cold slider, but rather colours/warm light slider/cool light slider.

I’m not sure if my next avenue of exploration should be within your script (which, btw is miles beyond my current capabilities, but I can still appreciate its beauty!), or dive deeper into what I can do in esphome in order to instruct the bulb via Kelvin values…

I’ve completely lost the plot here for a moment, so I’ll just say THANKS again for a super useful script! :smiley:

1 Like

@kvikindi Thank you so, so much for your kind words! :rainbow:

For whatever it’s worth, while I have no particular experience with ESPHome/LibreTiny, I have one idea that miiiight potentially offer some options depending on how things pan out—

If you go to your local Home Assistant installation → Developer Tools → States, and if you then type that RGBWW bulb’s entity name in the “Filter entries” box, what’s shown under that bulb’s attributes column?

(By way of example, here’s what’s shown under the attributes column for my patio lamp:)

min_color_temp_kelvin: 2000
max_color_temp_kelvin: 6535
min_mireds: 153
max_mireds: 500
effect_list: None, candle, fire, prism
supported_color_modes: color_temp, xy
color_mode: color_temp
brightness: 255
color_temp_kelvin: 2906
color_temp: 344
hs_color: 27.987, 59.51
rgb_color: 255, 174, 103
xy_color: 0.505, 0.385
effect: None
mode: normal
dynamics: none
friendly_name: Patio Lamp
supported_features: 44

Anyway, it’s mostly the supported_color_modes attribute that’s of interest in this context. And while I’m not making any promises, depending on what your bulb might show for that supported_color_modes attribute, there may be a chance that we miiiight be able to finagle something for this.

1 Like

Alas, it’s only RGBWW in there at the moment… but I’m sure that there is a way for me to wangle this somehow, probably with some lambda magic somewhere… Once I get proper time to look at it, I’m sure I’ll find it (a 1.5 year old is a time sink!).

For what it’s worth, here the state of the lamp from dev tools:

effect_list:
  - None
  - Custom RGBWW Effect
  - DDP
supported_color_modes:
  - rgbww
color_mode: rgbww
brightness: 143
hs_color:
  - 28.383
  - 65.49
rgb_color:
  - 255
  - 167
  - 88
xy_color:
  - 0.524
  - 0.388
rgbww_color:
  - 0
  - 0
  - 0
  - 0
  - 255
effect: None
icon: mdi:floor-lamp
friendly_name: Stand Lamp Light
supported_features: 44
1 Like

Hey Ashley,

Congrats and thank you for the script, it is the by-far best effect that I was able to see, especially for the lamps which doesn’t support transition attribute.

I have (may be a dumb) question / goal. I am trying to use your script to simulate the transition effect - as my lamp doesn’t accept transition key in the service calls. I am trying to adjust the brightness of the floor lamp with a philips hue tap dial switch…

Your script works great with buttons on the switch, like increasing the brightness from 10% to 70% in a second with a press on button 1, etc… very smooth transitions.

But I am also trying to make use of the dial to increase and decrease the light brightness with the turn of the dial. The dimmer switch supports, 3 actions for increase and decrease. Fast Turn Right, Slow Turn Right and Step Turn Right and similar 3 actions for left turns.

My goal was to use your script by creating a custom entity (sensor) which will have some more or less some value to the current brightness of the lamp, and I will be able to use that entity for the endBrightnessEntity .

For example, if the current brightness of the lamp is 40 (0-255 range), I will have 3 custom sensors that I can use with your script - for the endBrightnessEntity value… (to keep 0-255 range)

sensor_increase_fast: current brightness of the light + 50 (so 40 + 50 => 90)
sensor_increase_slow: current brightness of the light + 25 (so 40 + 25 => 65)
sensor_increase_step: current brightness of the light + 10 (so 40 + 10 => 50)

Using your script in 3 different automations for increase, and another 3 automations for the decrease actions…

something like: (only the last line changes for the 6 increase / decrease automations)

service: script.ashley
data:
  lampBrightnessScale: zeroToTwoFiftyFive
  easingTypeInput: easeOutSine
  endBrightnessEntityScale: zeroToTwoFiftyFive
  autoCancelThreshold: 10
  shouldStopIfTheLampIsTurnedOffDuringTheFade: true
  shouldResetTheStopEntityToOffAtStart: false
  shouldInvertTheValueOfTheStopEntity: false
  minimumStepDelayInMilliseconds: 100
  shouldTryToUseNativeLampTransitionsToo: false
  isDebugMode: false
  light: light.floor_lamp
  transitionTime:
    hours: 0
    minutes: 0
    seconds: 1
  endBrightnessEntity: sensor.sensor_increase_fast ## or sensor_increase_slow or sensor_increase_step in each automation

This works ok but not with smooth transtion.

I guess when I turn the dial, the script is called multiple times and that’s why the transtion is not smooth anymore due to parallel executions. It still works but it looks very like linear increase then the smooth increase / decrease that I can get with the buttons.

Can you think of any solution for this kind of a use-case ?

2- I wish we could have used milliseconds in transitionTime :slight_smile:

3- I wish the increase calls were able to get cancelled if there is a decrease (and vice-versa)

Thanks very much.
Marco

1 Like

Hey Ashley,

your script is almost perfect.

I am currently using your super script like below:

  • if there is no presence then start dimming, if there is presence then stop dimming.

Is it possible to restore the brightness level (when I trigger entity from “stopEntity:” ) of the light before the script started dimming it?

I would like to get the effect like below:

  • if there is no presence then start dimming, if there is presence then stop dimming and set light britghness to level before dimming.

alias: Sypialnia - wygaś światło jeśli brak ruchu
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.sypialnia_ruch_presence
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition: []
action:
  - service: script.1699737075083
    data:
      lampBrightnessScale: zeroToTwoFiftyFive
      easingTypeInput: auto
      endBrightnessPercent: 0
      autoCancelThreshold: 10
      endBrightnessEntityScale: zeroToOneHundred
      shouldResetTheStopEntityToOffAtStart: false
      minimumStepDelayInMilliseconds: 100
      isDebugMode: false
      light: light.sypialnia_swiatlo
      transitionTime:
        hours: 0
        minutes: 1
        seconds: 0
      stopEntity: binary_sensor.sypialnia_ruch_presence
mode: single

Hey @PanMarekPL - I’m not entirely sure how to go about this, but my gut instinct tells me to look towards templating somehow, be it through a text/number helper and templating there within?

The way I have got some of my automations set up to go back to a previous state is by setting an action for service->scene create->scene “before”, and then whatever action thereafter (scene change etc.). That way when I want to “recall” the previous state of devices, in the “restore” automation I simply load the scene “before”.

But hopefully you can find something through the text/number helper templating.
I’d probably set it somehow like:
no presence detected → create scene (or write state of x light into a helper/template) → start dimming lights.
And then if there’s suddenly presence detected, then you could run Ashley’s script, using the helper as a value, as per the “Use an entity instead for the end-brightness value”.

Hope this points you towards where you wanna be :slight_smile:

thank you for the suggestion. I created a helper and there I store the value before dimming, and later after detecting motion I restore it.

2 Likes

Hello!
Thank you so much for all your work on this, it looks awesome.

I am trying to implement some long fade in/outs.
Generally it fails if my transition time is more than a few minutes
I have kind of wonky connectivity, I think, so maybe my bulbs are briefly disconnecting?

I see this kind of thing in my automation traces:

"
Ashley’s Light Fader (script.1702486433421) started
(script.1702486433421) turned on
2 minutes later
(light.scarf_light) turned on
Stopped because an error was encountered at December 15, 2023 at 9:24:53 AM (runtime: 1492.89 seconds)

src/app/CommandSender.cpp:271: CHIP Error 0x00000032: Timeout

"

Again, my connections are floaty - but is there a way I can have a graceful recovery from intermittent connection failures?
These errors stop my automation, so no ensuing calls happen.

I have worked around it by just making the Ashley fade the last thing any automation does - but it is inelegant.

Any ideas?

1 Like