I created an automation with a dawn entity trigger and sunset event triggers. When either trigger executes, they wait till the sun state is -3° of elevation and turn on or off a light area.
Problem:
The sunset trigger executes waits till the sun elevation state is -3° and turns on the area as it should.
When the dawn trigger executes, waits for the sun elevation trigger and continues to run not turning off lights, trace reports “running”. This causes the next sunset trigger to stop for single execution error. Approximately 30 minutes later the dawn trigger trace reports finished, (runtime 46939 seconds) and turns lights off.
The dawn trigger apparently runs past the dawn elevation waiting till the sunset elevation, then finishes turning off lights.
Thank you for your thoughts, simular experiences.
YAML:
alias: Outside Lights ON-OFF
description: lights off at dawn - lights on sunset - wait till sun -3°
trigger:
Not sure why you use a “wait”, here.
You could just trigger the whole automation on the triggers you defined in the “waits” and use id’s to chose the proper action.
For history; originally I had separate sunset/sunrise automations, and never liked the timing. When dusk/dawn entities arrived, didn’t like that timing. Started experimenting with building blocks and went into that rabbit hole.
To directly answer- I created separate automations to test. The dawn automations behavior is the same, the lights don’t trigger with the dawn sun elevation, instead runs until the sunset sun elevation.
I did try this, the script returned a fail- the call didn’t “wait” as sunset/dawn sun elevation aren’t -3°, I believe. I known just enough not to know, I’ve scratched the surface of HA for many days. If this is what you suggested.
alias: Trigger change test
description: lights off at dawn - lights on sunset - wait till sun -3°
trigger:
platform: state
entity_id:
sensor.sun_next_dawn
id: dawn
alias: Dawn
platform: sun
event: sunset
offset: 0
id: sunset
alias: Sunset
platform: numeric_state
entity_id:
sensor.sun_solar_elevation
below: -3
id: Sun elevation -3
alias: Sun Elevation -3
condition:
action:
alias: Dawn or Sunset options
choose:
conditions:
condition: trigger
id:
dawn
alias: Dawn trigger
condition: trigger
id:
Sun elevation -3
alias: Sun elevation -3° trigger
sequence:
alias: Outside Lights OFF
action: light.turn_off
metadata: {}
data: {}
target:
area_id: outside_lights
alias: Dawn Lights OFF
conditions:
condition: trigger
id:
sunset
alias: Sunset trigger
condition: trigger
id:
Sun elevation -3
alias: Sun elevation -3° trigger
sequence:
alias: Outside Lights ON
action: light.turn_on
metadata: {}
data: {}
target:
area_id: outside_lights
alias: Sunset Lights ON
mode: single
-3 is always below for both dawn and sunset, that’s why I call sunset or dawn first then wait for -3°.
Do you mean: for dawn “above” numeric -3 and sunset “below” numeric -3 for triggers, I haven’t tried that.
I’ve done the mental gymnastics, and I get your & @Tinkerer meaning. I’m thinking the physical horizon and not how code understands it. I read somewheres- below is always a negative number (so “below”) and not representing an phsical action of rising/falling; it’s obvous now. As side note- I did play with sun rising in error.
So, at dawn the value would be rising numerically “above” (not the physical sun action of still being “below” horizon); this would explain the running till sundown. Thank you both, I changed the dawn sun elevation to above -3 and will “wait”.
I’d also point out that it looks (hard to tell as you still haven’t formatted that code) like you’ve got conditions that are checking for more than one trigger id… those won’t ever work.
Thank you for the help Chris @koying awesome, initially I had thought using just elevation as triggers (simple = good), but I didn’t think numerical rising/falling values like temperature for the two -3° “below horizon” each day, so, the trigger wait trigger action idea. Now it’s HA- trigger on elevation, action; from 720.11 seconds to 0.16 runtime.
Thank you @Tinkerer for the “rising/falling” for “above/below” translation (that did it), and, the help despite the @tom_l admonishment. Still not sure about “formatted that code” (I’ll learn)- I just created an automation and saved, that’s where the “code” was generated. The additional trigger ID was an attempt to trigger instead of wait.
@Sandalman I prefer using elevation instead of separate sunrise/set with offset/wait. I didn’t like the wait for this automation off the getgo.
@tom_l I’ll read and learn. I’ve used HA for awhile. I don’t have time for its minutia, but if I ask I’ll learn the language to do so. Thanks for allowing me to get this answered as is.