Automation not working when arrived

Hi.

I want to turn off for 10 minutes some lights when i arrived home but only at night starting 20 minutes befor sunset. I create this automation but isn´t working… can someone helpme?

- id: '1643324556094'
  alias: Al Llegar enciende marquesina
  description: ''
  trigger:
  - platform: zone
    entity_id: person.bety
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.luis
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.ricardo
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.rvvstk
    zone: zone.home
    event: enter
  condition:
  - condition: sun
    after: sunset
    after_offset: +00:20:00
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.marquesina_dentro
      - switch.marquesinafuera
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
  mode: single

See if this will correct the problem.

- id: '1643324556094'
  alias: Al Llegar enciende marquesina
  description: ''
  trigger:
  - platform: zone
    entity_id: person.bety
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.luis
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.ricardo
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: person.rvvstk
    zone: zone.home
    event: enter
  condition:
  - condition: sun
    before: sunset
    before_offset: '00:20:00'   <-- make it before sunset
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.marquesina_dentro
      - switch.marquesinafuera
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      entity_id:
      - switch.marquesina_dentro   <- add the switches to turn off
      - switch.marquesinafuera
  mode: single

it is before sunset with the delay of 20 minutos before

That’s your original automation, which is from 20 minutes after sunset.

Does the automation work when you remove the condition?
Set the delay to 10 seconds to test if you havent yet.

Yes with out sun condition it work

Yes, you are right I change it to -00:20:00, with out the sun condition it works, i will try later if now works. the interesting part is that with sun condition it no work even if I come home at midnight

The sun condition stops/starts at midnight.

If you want a generic when dark then you should use the sun elevation instead, something more like:

condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: 2