Sunrise/Sunset Trigger not working

I am new to Home Assistant automation and I just cannot figure out what is wrong with my automation to turn lights on/off based on sunset/sunrise. It never triggers.
I have tried to use elevation as well but that didn’t work either. I have searched the net for a solution but everything I found gives examples for how sunrise/sunset used to work.
I have already checked that Time and Zone are set correctly.
Please give me some pointers on what I’m doing wrong.
Thanks in advance.

Here is my script:

alias: Turn Off/On Outside and RV lights
description: Turn Off/On Outside and RV lights
trigger:
  - platform: sun
    event: sunrise
    offset: "+15:00"
    id: Sun-Sunrise
  - platform: sun
    event: sunset
    offset: "-15:00"
    id: Sun-Sunset
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Sun-Sunrise
        sequence:
          - type: turn_off
            device_id: 700619e2f2474e99d97f29xxxxxxxxxx
            entity_id: 07417eb48f20900e27873axxxxxxxxxxx
            domain: light
          - type: turn_off
            device_id: 1012de7d9066e1e815ef2xxxxxxxxxxx
            entity_id: 21c381e1ec06d8e6e7898c0axxxxxxxxx
            domain: light
      - conditions:
          - condition: trigger
            id:
              - Sun-Sunset
        sequence:
          - type: turn_on
            device_id: 700619e2f2474e99d97f296xxxxxxxxx
            entity_id: 07417eb48f20900e27873a0xxxxxxxxxx
            domain: light
            brightness_pct: 40
          - type: turn_on
            device_id: 1012de7d9066e1e815ef2axxxxxxxxxx
            entity_id: 21c381e1ec06d8e6e7898cxxxxxxxxxxx
            domain: light
            brightness_pct: 75
mode: single

First things first, confirm the automation is not disabled.

If it never triggers then there will be no traces recorded. Can you confirm that there are, in fact, no traces recorded around the times of sunrise and sunset?

Yes, the automation is enabled and there are no Traces recorded.

Any related error/warning messages in the Log?

I beleive you need to use this format for your offset.

offset: "-00:45:00"

I have a similar setup but have made two automations, one for sunrise and one for sunset.
not sure about the offset you use tho, -15:00, is this 15 minutes or hours.
I use -00:15:00

No log errors/warnings related to this automation.

Thank you. I will try that.

Thank you. Will give it a try.

tested your automation just now with offset “-00:15:00” and it worked.

How did you test it right now? I thought I have to wait until sunrise/sunset to see if it triggers.

Although it’s normal to express the offset value in this format HH:MM:SS the suggestions to change -15:00 to -00:15:00 don’t explain why this failed:

sunset here was 20 minutes away lol, so I copied your automation and used one of my devices (smartplug), then waited for the sunset, perfect timing!

Got it. I thought you had a trick up your sleeve. Thanks again.

you’re welcome.

So how does that explain your reported failure for a Sun Trigger employing elevation?

Post the version of Sun Elevation Trigger you created that failed to work.

Here is the trigger based on elevation:

alias: Turn On RV lights
description: Turn On RV lights
trigger:
  - platform: numeric_state
    entity_id:
      - sun.sun
    attribute: elevation
    below: -4
condition: []
action:
  - type: turn_on
    device_id: 1012de7d9066e1e815xxxxxxxxx
    entity_id: 21c381e1ec06d8e6e78xxxxxxxxx
    domain: light
    brightness_pct: 75
mode: single

maybe try below: -4.0 instead of -4?

I have another automation that uses the sunrise/sunset that also doesn’t work.
It takes a notification from a Reolink doorbell that a person is detected, or a push button action(used it for testing, rather than manually triggering the Reolink), then it checks if is during the night and if it is, it will turn on the front door lights.
The automation right now triggers regardless of the night/day. I had the same time format error -15:00, I corrected it to -00:15:00 but still turns on the lights even thought is already 9:30 in the morning.

Here is the automation:

alias: Turn on Yolink Entry Light after Person detected and at night -40%
description: Turn on Yolink Entry Light after Person detected and at night-40%
trigger:
  - type: turned_on
    platform: device
    device_id: eb080ea803e08xxxx
    entity_id: 27174b2e4463d7xxxxxx
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - input_button.person_detected
    to: null
condition:
  - condition: sun
    after: sunset
    after_offset: "-00:15:00"
    before: sunrise
    before_offset: "00:15:00"
action:
  - if:
      - condition: state
        entity_id: input_boolean.visitor_present
        state: "off"
    then:
      - type: turn_on
        device_id: e4bc4f238923xxxx
        entity_id: af3109b53e2xxxx
        domain: light
        brightness_pct: 40
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
          milliseconds: 0
      - type: turn_off
        device_id: e4bc4f238923xxxx
        entity_id: af3109b53e2xxxx
        domain: light
        enabled: false
      - if:
          - condition: state
            entity_id: input_boolean.visitor_present
            state: "off"
        then:
          - type: turn_off
            device_id: e4bc4f238923xxxxx
            entity_id: af3109b53e2xxxxx
            domain: light
mode: single

That’s fine and effectively the same as what I use in my automations (it has been working flawlessly for at 3 years).

platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: -4

Why it failed for you is unclear (and I don’t have the time to discover the reason).


The suggestion to change -4 to -4.0 is moot; they’re the same value and not handled differently.


I tested this moments ago:

platform: sun
event: sunset
offset: "-05:11"

Sunset in my area is in 5 hours and 11 minutes and the automation triggered successfully.

Therefore -15:00 is understood as 15 hours before sunset. Owing to the way sunset is computed, 15 hours prior to the moment when it’s computed produces a time that has already passed. Therefore the automation is never triggered.

FWIW, this also triggers 5 hours and 11 minutes before sunset. However, the Automation Editor doesn’t display it properly in visual mode.

platform: sun
event: sunset
offset:
  hours: -5
  minutes: -11