Automation doorsensor

i have a automation for the door open then the light go on.
how can i make this work between sun down en sun rise .

alias: voordeur
trigger:

  • entity_id: binary_sensor.voordeur
    from: ‘off’
    platform: state
    to: ‘on’
    condition: []
    action:
  • data:
    entity_id: switch.hal
    service: homeassistant.turn_on
  • delay: ‘60’
  • data:
    entity_id: switch.hal
    service: homeassistant.turn_off

First, whenever you post YAML code or logs, please follow the instructions at the top of the page so it is formatted correctly. If you don’t it’s very difficult to read, and especially difficult to spot common problems like indentation issues.

But to answer your question, add a sun condition like the following:

condition:
  condition: state
  entity_id: sun.sun
  state: 'below_horizon'

Oké thanks.
I don’t know that.
Sorry my English is not so good
But is this condition to start when the sun is down and finish when the sun is up?

See Sun component documentation.

Yes. The sun.sun entity’s state will be ‘below_horizon’ starting at sunset and ending at sunrise.

I think what you want is:

alias: voordeur
  trigger:
    platform: state
    entity_id: binary_sensor.voordeur
    from: 'off'
    to: 'on'
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  action:
    - service: switch.turn_on
      entity_id: switch.hal
    - delay: 60
    - service: switch.turn_off
      entity_id: switch.hal

thanks it works