Issue with sunset automation

Hey everyone,

I would like to turn on the porch light when there is movement after sunset until sunrise, now with code it works until midnight. I add some more conditions like sunrise etc. but none of them work, can someone give me a hint. I used some code from the forum but those are not working as well.

  • id: ‘72057594178191520’
    alias: Buitenverlichting aan
    initial_state: true
    trigger:
    • entity_id: sensor.aeotec_zw100_multisensor_6_burglar_2
      from: ‘0’
      platform: state
      to: ‘8’
      action:
    • entity_id: switch.fibaro_system_fgs222_double_relay_switch_2x15kw_switch
      service: homeassistant.turn_on
      condition:
    • after: sunset
      condition: sunPreformatted text

Thank in advance,

André

Use the sun state as condition instead:

- alias: Motion Detection - Kitchen Light on
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0001656f12
    to: 'on'
  condition:
    condition: state
    entity_id: sun.sun
    state: below_horizon  
  action:
    service: light.turn_on
    entity_id: light.kitchen