Dawn state trigger not executing wait trigger for sun elevation state

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:

  • platform: state
    entity_id:
    • sensor.sun_next_dawn
      id: dawn
      alias: Dawn
  • platform: sun
    event: sunset
    offset: 0
    id: sunset
    alias: Sunset
    condition:
    action:
  • alias: Dawn or Sunset options
    choose:
    • conditions:
      • condition: trigger
        id:
        • dawn
          alias: Dawn trigger
          sequence:
      • alias: Wait sun elevation -3°
        wait_for_trigger:
        • platform: numeric_state
          entity_id:
          • sensor.sun_solar_elevation
            below: -3
            id: sun elevation -3
            alias: When Sun elevation is -3°
      • 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
          sequence:
      • alias: Wait Sun elevation -3°
        wait_for_trigger:
        • alias: When Sun elevation is -3°
          platform: numeric_state
          entity_id:
          • sensor.sun_solar_elevation
            below: -3
            id: sun elevation -3
      • alias: Outside Lights ON
        action: light.turn_on
        metadata: {}
        data: {}
        target:
        area_id: outside_lights
        alias: Sunset Lights ON
        mode: single

Maybe, make two automation’s, one for lights on and one for lights off

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

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.

The wait runs with sunset as wanted, the dawn wait continues to “wait” till sunset -3° as I see it.

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

Forget about dawn and sunset. Just use Sun elevation.

“below” → going down → light on
“above” → going up → light off

I apologize; I’ll read and learn.

-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.

below means the value is falling, and above means it’s rising.

Also, unformatted code is impossible to read - please do as Tom asked and format your posts.

1 Like

Not sure how in application, however I believe I can decode your meaning and will try.

I will read and learn correcty posting format, before additional posting. I apologize.

“below” means, e.g, going from -3 to -4
“above” means, e.g, from -3 to -2

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”.

Once again, “wait” adds unnecesarry complexity, is less efficient and doesn’t survive an HA restart.

Just trigger on the elevation going “below” or “above” rather than on dawn/sunset and waiting, that’s the HA way.

1 Like

I use sunset and wait a 30min, works perfect.

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.

Using -3° “above” and the automation executed.


Screenshot 2024-09-18 064902

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.

See here as was previously linked for you.

1 Like