Sun not working as a trigger for lights

I’m new to Home Assistant and have been getting things figured out well. I have successfully built some automations but this one has me stumped. I’m trying to have some lights turn on in my Family Room when the sun sets. I have the correct Time Zone. If I select the Sun Device as a trigger and Sunset in that trigger as an event nothing happens. If I Run actions the light comes on every time.

So I thought about using the event (sun_next_dusk or sun_next_setting) as a trigger but they don’t allow an offset so by the time the light would come on this north facing room will be impossibly dark. I know there has to be a way to do this but the logic is escaping me. For today the sun_next_dusk is 8:32PM and the sun_next_setting is 7:54PM.

I’ve been trying very hard to figure these things out myself and not be one of those guys but I could really use some help with this one.

Thanks!

If you start a new automation in the GUI, and start by creating a new TRIGGER, there should be a few types of trigger choices displayed. If TIME & LOCATION is selected, you should see a SUN option that can be selected in order to get to the following dialog:

If you don’t get to there. . . I don’t recall if this requires the SUN integration to be installed. It’s been a minute since I went to SETTINGS / INTEGRATIONS and added the SUN integration, but I suppose this is why I did it. [:thunk:]

It should; it’s a simple and reliable trigger.

Post the automation you created that uses a Sun Trigger (in YAML format; not a screenshot of the UI).

BTW, if the automation fails to trigger at sunset, it will produce no traces. I suggest you check the automation’s traces and see if any were produced.

Troubleshooting Automations

Because, as its name indicates, it simply runs the actions of your automation. It doesn’t test the automation’s triggers and conditions so it’s not a comprehensive test.

alias: Family Room Light at Sunset
description: “”
triggers:

  • trigger: sun
    event: sunset
    offset: “-1:00:00”
    conditions:
    actions:
  • type: turn_on
    device_id: 6d10ceaf9a5caf008ebcc46b3f683e52
    entity_id: 45428e54eda1acee6a800c4e92c035e4
    domain: light
    brightness_pct: 50
    mode: single

The Sun is an Integration.

Thanks for your input!

Please post your code formatted properly

f6be36681e0da431418ec7781fb6c62712941803

As @francisp said, edit the automation in YAML mode and post the code using code tags. The forum editor screws up the formatting of YAML code.

What you posted does not look like the complete automation. There is no action: section.

alias: Family Room Light at Sunset
description: ""
triggers:
  - trigger: sun
    event: sunset
    offset: "-1:00:00"
conditions: []
actions:
  - type: turn_on
    device_id: 6d10ceaf9a5caf008ebcc46b3f683e52
    entity_id: 45428e54eda1acee6a800c4e92c035e4
    domain: light
    brightness_pct: 50
mode: single

Sorry still learning.

The automation’s YAML code looks fine.

Check the automation’s traces to see when was the last time it triggered (if ever). For more details about traces, refer to the link in my previous post.

Shouldn’t the offset be "-01:00:00" instead of "-1:00:00", or does it not make a difference?

Doesn’t make a difference.

This works for me

alias: Sunset Lamp On (If Someone Is Home)
description: ""
triggers:
  - entity_id:
      - sun.sun
    from: above_horizon
    to: below_horizon
    trigger: state
conditions:
  - condition: or
    conditions:
      - condition: state
        entity_id: person.nic
        state: home
      - condition: state
        entity_id: person.moose
        state: home
actions:
  - type: turn_on
    device_id: f3d3b6fb6113382fd31e0750367ad7a0
    entity_id: bf6a7b5c1735f8a1f86da3af90f821a0
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - type: turn_on
    device_id: f3d3b6fb6113382fd31e0750367ad7a0
    entity_id: bf6a7b5c1735f8a1f86da3af90f821a0
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 12
      milliseconds: 0
  - type: turn_on
    device_id: c64aa326bb7f47ceadfb5495ae67b199
    entity_id: bb1dc7721011be1654dcb616d54f7f9f
    domain: switch
mode: single

It is useful to make sure that your actions are written correctly. It’s especially helpful with complex actions.

You don’t need both, but since your actions are working let’s not mess with it for now. But come back to this later and we can show you how to make your automation more readable.

If you know what time sunset is, set the offset to trigger in the next hour then come back to look at the trace. Post a screenshot of the trace

1 Like

You can combine devices unless the delay is really necessary and I agree with @stevemann about sunset vs above_horizon

An Example

alias: Sunset ON
description: ""
triggers:
  - event: sunset
    offset: "00:00:00"
    trigger: sun
conditions:
  - condition: state
    entity_id: person.xxxx
    state: home
actions:
  - target:
      entity_id:
        - switch.xxxx
        - switch.xxxx
        - switch.xxxx
    data: {}
    action: switch.turn_on

Suddenly last night it started working. Even before I had a chance to make the changes you suggested. My wife and I were sitting in the Family Room and the lights came on. I did do the software update to 2025.4.2 earlier in the day. Maybe that helped?

Thanks again for all your replies.

Have a great day!