Now that I have the basics working I want to add some automation to simulate a sunset and sunrise, maybe a solar noon. The esp32 is controlling my light, it is the on/off timer and dimmer. I have it set to return to 80% from lights out as the light is too damn bright. Getting it to ramp slowly up to 100% was easy. Getting it to stop at a adjustable value I could set from the home screen was something eles. After a few hours playing around this is the automation that I got:
Code: Select all
- id: '1610574859252'
alias: Test Light Sun Rise
description: ''
trigger:
- platform: time
at: input_datetime.test_light_on_time
condition: []
action:
- type: turn_on
device_id: 9a6a92804a0aa266950c3a6ee14a29a4
entity_id: light.test_light
domain: light
brightness_pct: 1
- repeat:
until:
- condition: template
value_template: '
{{ states(''input_number.maximum_brightness'') | float <= ((states.light.test_light.attributes.brightness)/2.55) | float }}'
sequence:
- type: brightness_increase
device_id: 9a6a92804a0aa266950c3a6ee14a29a4
entity_id: light.test_light
domain: light
- delay: 00:02:00
mode: single
- id: '1610616240469'
alias: Test Light Sun Set
description: ''
trigger:
- platform: time
at: input_datetime.test_light_off_time
condition:
- condition: device
type: is_on
device_id: 9a6a92804a0aa266950c3a6ee14a29a4
entity_id: light.test_light
domain: light
for:
hours: 0
minutes: 0
seconds: 1
action:
- repeat:
until:
- condition: device
type: is_off
device_id: 9a6a92804a0aa266950c3a6ee14a29a4
entity_id: light.test_light
domain: light
for:
hours: 0
minutes: 0
seconds: 1
sequence:
- type: brightness_decrease
device_id: 9a6a92804a0aa266950c3a6ee14a29a4
entity_id: light.test_light
domain: light
- delay: 00:02:00
mode: single
It's greasy but it kind of works. I have a few helpers: "input_datetime.test_light_on_time" and "input_datetime.test_light_off_time" to trigger the automation, and "input_number.maximum_brightness" to stop before 100%. For testing purposes I'm using an extra esp32 and it's status led as my test light.
Code: Select all
light:
- platform: monochromatic
name: "test_light"
output: test_light
output:
- platform: ledc
id: test_light
frequency: 1220 Hz
pin: GPIO2
inverted: false
min_power: 0%
max_power: 100%
The brightness of the light is 0-255, but I wanted it to be adjustable by a slider in %, so there is a bit of math in the template. I need to tweak the step somehow to smooth out the transition, and increase the accuracy. I also want to adjust the delay from the home screen so I can adjust the time of the effect. The default dim step is 10%, so I get about 10 steps from 0 to 100, 2 minuets a step translates to roughly 20 minuet transition.
Is anyone doing this in a more graceful way? Or see something obvious that I do not?
A few edits because I first tried to type this up and copy things from the file editor on my cell phone before I sat down at the keyboard.