Slowly increase brightness over 1 hour until certain brightness is reached

Hey,

I just got Home Assistant a week ago and am a complete noob. My setup is IKEA Tradfri light bulbs via Sonoff Zigbee 3.0. My Home Assistant is currently on Core 2024.5.1, Supervisor 2024.04.4, Operating System 12.2 & Frontend 20240501.0 if thats important.

What I’ve been trying to do since a few days is creating an automation that will slowly increase the brightness in 1% steps starting 1 hour before sunset. The lights should take one hour until their specified brightness is reached and then stop increasing the brightness.

This is my Yaml-Code:

alias: Neue Automatisierung
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
condition: []
action:
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            device_id: 9b97b17b6ab1976025fab16ac00dded4
          data:
            rgb_color:
              - 130
              - 17
              - 255
            brightness_step_pct: 1
            transition: 3600
      until:
        - condition: state
          entity_id: light.stehlampe_klein_licht
          attribute: brightness
          state: 60%
mode: single

The light is increasing brightness but it won’t stop at 60% but continue to increase to 100%.

Does someone know a possible fix for that?

i suspect the issue is that the .turn_on call to inrease by 1% is not synchronous. so it’s cycling through to 100 super fast…

why do you have both the transition time set for 1hr as well as the repeat?
can you not set the brightness target to 60% and 1 hr transition and do it in 1 call and not have the repeat?

something like this?

alias: Neue Automatisierung
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
condition: []
action:
  - service: light.turn_on
    target:
      device_id: 9b97b17b6ab1976025fab16ac00dded4
    data:
      rgb_color:
        - 130
        - 17
        - 255
      brightness_pct: 60
      transition: 3600

btw… i’ve heard that there are sometimes issues for some bulbs in setting the rgb and brightness ramp at the same time. i don’t know because i don’t have a color changing smart bulb. but if so you might need to do the rgb color setting separately than the brightness call.

1 Like

You might want to consider this:

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.

5 Likes

nice. i didn’t know about that… if your lights don’t natively support transition, that’s a good option!

1 Like

Thanks bunches for the shout-out, @MaxK!

And as the author of that script, I’d like to offer for @LePaulinat0r (or for anyone else on this thread) that if you might have any questions about setting up the script or the like, I’d be more than happy to chime in.

3 Likes

Hey @armedad, thanks for the suggestion! I’ve tried it just now however the light doesn’t seem to be getting any brighter at all anymore that way while in the app it shows that the brightness has increased to 60%. Weird.
I’ll try the Light Fader and see if that works.

it doesn’t change slowly over the hour?
remember you set it to ramp for an hour… which is a very slow ramp…

I’d try these two things just to test… these are faster ramps but still slow enough to test

alias: Neue Automatisierung
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
condition: []
action:
  - service: light.turn_on
    target:
      device_id: 9b97b17b6ab1976025fab16ac00dded4
    data:
      brightness_pct: 60
      transition: 30

and also this:

alias: Neue Automatisierung
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "-01:00:00"
condition: []
action:
  - repeat:
      sequence:
        - service: light.turn_on
          target:
            device_id: 9b97b17b6ab1976025fab16ac00dded4
          data:
            rgb_color:
              - 130
              - 17
              - 255
            brightness_step_pct: 1
            transition: 10
        - delay:
            hours: 0
            minutes: 0
            seconds: 10
            milliseconds: 0
      until:
        - condition: state
          entity_id: light.stehlampe_klein_licht
          attribute: brightness
          state: 60%
mode: single

if either of those ramp slowly, then it will lead to a solution…

1 Like

Hey, oh, I set the transition to 10 secons at a specific time for the test and thanks again for two new scripts!

While in the app the brightness slider is working wonderfully now (it’s automatically increasing slowly instead of ramping straight up to 60%), it won’t stop at 60% and the light bulb still refuses to actually get any brighter.
When I manually set the brightness slider to 60% however then the light is suddenly getting brighter.

I’ve tried the Light Fader tho and that way it’s working! Yay! I guess the IKEA bulbs just may not support this initially.
So also thank you to @MaxK and @handcoding!

1 Like

that is strange, but glad you have a working solution!

1 Like

Oh, that’s music to my ears—yay for all this!