Automation to turn lights on when home

Hi there, I am new to HA, Im plugging away and getting there, with no programming experience, a great learning curve.
I am trying to automate the turn on some lights before sunset and off again after a delay when we are home. Using Life360 for tracking me and my wife
I cannot get my automation to work, I have read and read about doing this but must be missing something somewhere, can someone assist Please? My Yaml
automation:

  - alias: 'Lights on when at home after sunset'
    trigger:
      - platform: state
        entity_id: group.all_devices
      - platform: sun
        event: sunset
        offset: -00:45
    condition:  
      condition: and
      conditions:
        - condition: sun
          after: sunset
        - condition: state
          entity_id: group.all_devices
          state: 'home'
    action:
      - service: homeassistant.turn_on
        entity_id: group.all_lights
      - delay: '04:00:00'
      - service: switch.turn_off
        entity_id: group.all_devices

If the intention is to turn on the lights 45min before sunset only when people are home, try this:

  - alias: 'Lights on when at home after sunset'
    trigger:
       - platform: sun
         event: sunset
         offset: "-00:45:00"
    condition:  
      - condition: state 
        entity_id: group.all_devices
        state: 'home'
    action:
      - service: light.turn_on
        entity_id: group.all_lights
      - delay: '04:00:00'
      - service: light.turn_off
        entity_id: group.all_lights

I haven’t tested it but it is very similar to one I have. I hope it works.

Thanks for the fast response, WOW, I think I see where I went wrong, sun condition was in triggers and conditions, no neeed to do it twice.
Will see if it works in a couple of hours

Unless you live near the equator, you’ll likely want to use the sun elevation instead. Forty five minutes before sunset is a very different light level on the longest day compared to the shortest day :wink:

Thanks for the heads up, will try your suggestion tomorrow night.

Thanks for the help, got everything working now.
Now to try to get the next automation working.