Automation not triggering: Zone trigger and Sun condition

Hi,

I have set an automation to turn on the light when someone gets back home after sunset and before sunrise but it won’t trigger.

Here is the code:

alias: Welcome Home
description: Run welcome home automations
trigger:
  - platform: zone
    entity_id: person.xxx
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.yyy
    zone: zone.home
    event: enter
condition:
  - condition: sun
    before: sunrise
    after: sunset
action:
  - type: turn_on
    device_id: ac7954f610e522ec095f3498fe2e862f
    entity_id: light.entrance
    domain: light
    brightness_pct: 40
mode: single

I can see the state of the triggers and condition being met in the logbook:

[xxx] was at home
20:00:42 - 21 minutes ago
[Sun] set
19:18:00 - 1 hour ago

But the light is not turned on. When I click on execute manually, the light is turned on.
I set this up with the GUI so the device and entity are correct.

Any idea?

Thanks
Alessandro

Those two conditions can never be satisfied. After sunset today, is always after todays sunrise Look into using sun condition below_horizon. Good luck

1 Like

Yes ok I see what you mean. It’s not clear how to do that with the GUI however:

I changed the condition to:

condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon

Will it work?

Thanks again

I’m a newbie but I would have thought all you needed something like this instead

condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon

In the GUI it looks like this - you’re effectively checking the state

thanks we crossed our response that’s what I did in the meantime. I will try that tomorrow if it works…

What exactly is the use of the Sun condition in the GUI?

To make it confusing for new users ? :joy:

No seriously there appear to be uses for the Sun object like defining offsets, checking elevation etc but for the simple use case that you need just check the state

yep ok, got it, thanks :slight_smile: