Maybe an extra automation that checks if the light has switched on (state changed) and also automation state changed and if so turn it off?
so you could add an input boolean:
input_boolean:
automation_flag:
name: flag for automation
initial: off
Then add an automation that turns on the input boolean it when you turn on the automation, and turn off the input boolean at midnight.
- alias: flip boolean when automation runs
trigger:
- platform: state
entity_id: automation.turn_lounge_light_on_elevation__25__after_4pm
to: 'on'
from: 'off'
- platform: time
at: '00:00:00'
action:
- service_template: >
input_boolean.turn_{{ 'on' if trigger.platform == 'state' else 'off'}
entity_id: input_boolean.automation_flag
Then lastly, this automation:
- id: '1505977024304'
alias: Turn Lounge Light On Elevation < 25° & after 4PM
trigger:
- below: 25
entity_id: sun.sun
platform: numeric_state
value_template: '{{ state.attributes.elevation }}'
- platform: time
at: '16:00:00'
condition:
- after: '16:00:00'
before: '22:00:00'
condition: time
- condition: template
value_template: '{{states.sun.sun.attributes.elevation < 25}}'
- condition: state
entity_id: automation.turn_lounge_light_on_elevation__25__after_4pm
state: 'on'
for:
minutes: 5
- condition: state
entity_id: input_boolean.automation_flag
state: 'off'
action:
- service: light.turn_on
data:
brightness_pct: 75
entity_id: light.lounge
kelvin: 3100
So, it should only execute on days that it isn’t turned on.
1 Like
Thinking I can delete this?
- condition: state
entity_id: automation.turn_lounge_light_on_elevation__25__after_4pm
state: 'on'
for:
minutes: 5
No because we need to give the flag a buffer zone. I’m not sure the boolean will be set by the time the first automation is complete because of multi-threading.
1 Like
You know I just realised, the sun NEVER goes down here after 8:09PM, so 1.5 hours before then is 6:39PM so I can just adjust the 4PM-10PM trigger to 7PM and then as long as it’s after 7PM when I reactivate it I’m in the clear.
Sometimes the simplest solution is the best LOL.
1 Like