With much frustration, I decided to do a lot of repetitive code.
I was unable to perform the loop as expected, and my bulbs did not support transition.
Here is some automation I have for when I am home, about an hour before the sun goes down, my main light in the living room will increase it’s brightness every 10ish minutes until 5 minutes before, when it’s at full capacity.
I’ve also posted below some failed attempts and the reason I decided to go this route.
Feedback, comments, suggestions are appreciated!
Automation
########################################################
## Gradually increase living room light.
########################################################
- alias: 'Living Room 10'
trigger:
platform: sun
event: sunset
offset: "-1:00:00"
condition:
condition: and
conditions:
- condition: state
entity_id: light.livingroom_lamp_level_3_0
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: 'device_tracker.phone1_s5'
state: 'home'
- condition: state
entity_id: 'device_tracker.phone2_s5'
state: 'home'
action:
service: scene.turn_on
entity_id: scene.LivingRoomLamp10
- alias: 'Living Room 25'
trigger:
platform: sun
event: sunset
offset: "-00:50:00"
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.light.livingroom_lamp_level_3_0.attributes.brightness < 25 }}'
- condition: or
conditions:
- condition: state
entity_id: 'device_tracker.phone1_s5'
state: 'home'
- condition: state
entity_id: 'device_tracker.phone2_s5'
state: 'home'
action:
service: scene.turn_on
entity_id: scene.LivingRoomLamp25
- alias: 'Living Room 50'
trigger:
platform: sun
event: sunset
offset: "-00:30:00"
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.light.livingroom_lamp_level_3_0.attributes.brightness < 50 }}'
- condition: or
conditions:
- condition: state
entity_id: 'device_tracker.phone1_s5'
state: 'home'
- condition: state
entity_id: 'device_tracker.phone2_s5'
state: 'home'
action:
service: scene.turn_on
entity_id: scene.LivingRoomLamp25
- alias: 'Living Room 100'
trigger:
platform: sun
event: sunset
offset: "-00:15:00"
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.light.livingroom_lamp_level_3_0.attributes.brightness < 100 }}'
- condition: or
conditions:
- condition: state
entity_id: 'device_tracker.phone1_s5'
state: 'home'
- condition: state
entity_id: 'device_tracker.phone2_s5'
state: 'home'
action:
service: scene.turn_on
entity_id: scene.LivingRoomLamp100
- alias: 'Living Room 250'
trigger:
platform: sun
event: sunset
offset: "-00:15:00"
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.light.livingroom_lamp_level_3_0.attributes.brightness < 100 }}'
- condition: or
conditions:
- condition: state
entity_id: 'device_tracker.phone1_s5'
state: 'home'
- condition: state
entity_id: 'device_tracker.phone2_s5'
state: 'home'
action:
service: scene.turn_on
entity_id: scene.LivingRoomLamp250
Scenes
- name: LivingRoomLamp10
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 10
- name: LivingRoomLamp25
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 25
- name: LivingRoomLamp50
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 50
- name: LivingRoomLamp100
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 100
- name: LivingRoomLamp150
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 150
- name: LivingRoomLamp250
entities:
light.livingroom_lamp_level_3_0:
state: on
brightness: 250
FAILED ATTEMPT ONE
This one, I feel like had a lot of potential. I think its just my syntax. If anyone knows syntax, I would love feedback!
Script
light_fade_in:
alias: Light Fade In
sequence:
- service: light.turn_on
data:
entity_id: light.livingroom_lamp_level_3_0
brightness: 5
- delay:
seconds: 1
- service: script.turn_on
data:
entity_id: script.plus_five
plus_five:
alias: Add Five to Brightness
sequence:
- service: light.turn_on
data:
entity_id: light.livingroom_lamp_level_3_0
**## Here is the line that is causing me issues... in programming terms, I just want to do the equivilent of "light.brightness += 5"**
**brightness: "{{ states.light.livingroom_lamp_level_3_0.attributes.brightness|int + 5 }}"**
- delay:
seconds: 1
- service: script.turn_on
data:
entity_id: script.light_loop
light_loop:
alias: Light Loop
sequence:
- delay:
seconds: 1
- service: script.turn_on
data:
entity_id: script.plus_five
FAILED ATTEMPT TWO
This one is a little to “jerky” for my liking. It did not feel smooth or natural. Maybe tuning the brightness values and the delay it could be better.
################
# Fade in light
################
light_fade_in:
alias: Light Fade In
sequence:
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 5
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 6
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 7
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 8
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 9
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 10
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 11
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 12
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 13
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 14
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 15
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 16
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 17
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 18
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 19
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 20
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 21
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 22
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 23
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 24
- delay:
seconds: 0.4
- service: light.turn_on
entity_id: light.livingroom_lamp_level_3_0
data_template:
brightness: 25
- delay:
seconds: 0.4