You could also make that delay user-configurable like this:
blueprint:
name: Increase light brightness over time
description: |
# Increase light brightness over time
This script increases the brightness of a light over time.
Given the **transition time**, **initial brightness**, **target brightness** and **brightness step**, the script will calculate the number of steps required to reach the target brightness and the delay between each step.
The script will then turn on the light with the initial brightness, wait 5 seconds and then start increasing the brightness by the brightness step every delay between steps until the target brightness is reached.
```text
100% ┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ │
│ ┌─────────┤ ◄ target brightness
│ │ │
│ │ │
│ ┌─────────────────┘ │
│ │ │
│ │ │
│ ┌─────────────────┘ │
│ calculated delay │ │
│ │ │ │
│ │ ┌─────────────────┘ │
│ │ │ │
│ ▼ │ │
│ ┌─────────────────┘ │
│ │ ◄──────────── brightness step │
│ │ │
initial brightness ├─────────────────┘ │
│ │
0% └───────────────────────────────────────────────────────────────────────────────────────────────────┘
0s transition time
```
### Calculations
_steps = (target brightness - initial brightness) / brightness step)_
_delay = transition_time / steps_
domain: script
author: op00
source_url: https://community.home-assistant.io/t/increase-light-brightness-over-time/600349
input:
light_entity:
name: Light Entity
description: "Select the target Light\n\n
_single entity_"
selector:
entity:
filter:
domain: light
multiple: false
transition_time:
name: Transition Time
description: "Select the transition time\n\n
_min is 100 seconds, max is 3600 seconds = 1 hour_"
default: 100
selector:
number:
min: 100
max: 3600
step: 1
unit_of_measurement: seconds
mode: slider
target_brightness:
name: Target Brightness
description: "Select the target brightness\n\n
_default is 100%_"
default: 100
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
initial_brightness:
name: Initial Brightness
description: "Select the initial brightness\n\n
_default is 10%_"
default: 10
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
brightness_step:
name: Brightness Step
description: "Select the brightness step\n\n
_default is 2%_"
default: 2
selector:
number:
min: 2
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
initial_delay:
name: Initial delay
description: "Select the delay before starting the transition in milliseconds\n\n
_default is 5000ms (5 seconds)_"
default: 5000
selector:
number:
min: 0
max: 10000
step: 100
unit_of_measurement: '%'
mode: slider
mode: single
icon: mdi:lightbulb-on-60
variables:
transition_time: !input transition_time
brightness_step: !input brightness_step
initial_brightness_pct: !input initial_brightness
target_brightness_pct: !input target_brightness
light_entity: !input light_entity
initial_delay: !input initial_delay
sequence:
- variables:
target_brightness: '{{(target_brightness_pct * 255 / 100)|round}}'
initial_brightness: '{{(initial_brightness_pct * 255 / 100)|round}}'
required_steps: '{{(((target_brightness_pct - initial_brightness_pct) / brightness_step))|round|int}}'
delay_between_steps: '{{ (transition_time / required_steps)|round|int }}'
- service: light.turn_on
data:
brightness: '{{ initial_brightness }}'
transition: 0
entity_id: !input light_entity
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: {{initial_delay}}
- repeat:
while:
- condition: template
value_template: '{{ state_attr(light_entity, "brightness") | int < target_brightness }}'
sequence:
- service: light.turn_on
data:
transition: 0
brightness_step_pct: '{{ brightness_step }}'
entity_id: !input light_entity
- delay:
hours: 0
minutes: 0
seconds: '{{ delay_between_steps }}'
milliseconds: 0
Sorry if formatting is screwed up, did it on my phone…