Help with Automation of Lights with time specific needs?

I have motion detection setup up to activate a light but would like for this to only happen from 30m before sunset until dawn (no activation during the day basically).

I cant seem to get my head around it…

Is this right?

condition: sun
before: sunrise
after: sunset
after_offset: '-00:30:00'

It is easier to use sun angle

condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: '-6'

This will not activate between dawn and dusk regardless of time of year.

You can also do something like this:

condition:
  condition: template  # 'night' condition: from dusk to dawn, in typical locations
  value_template: "{{ state_attr('sun.sun', 'elevation') < -6 }}"

Here is another discussion on time that is going on now that is relevant.

This has been working fine for me. Turns my outdoor lights on 20 minutes before sunset and off 20 minutes after sunrise.

alias: Outdoor Lights
description: Turn Outdoor Lights on at sunset and off at sunrise
trigger:
  - platform: sun
    event: sunset
    offset: '-00:20:00'
    id: sunset
  - platform: sun
    event: sunrise
    offset: '00:20:00'
    id: sunrise
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - service: switch.turn_on
            target:
              device_id:
                - yourdevice|
           data: {}
      - conditions:
          - condition: trigger
            id: sunrise
        sequence:
          - service: switch.turn_off
            target:
              device_id:
                - yourdevice
            data: {}
    default:
      - service: switch.turn_off
        target:
          device_id:
            - yourdevice
        data: {}
mode: single

Yes that is correct. That condition will only evaluate to true when it is between sunset minus 30 minutes and sunrise. I.e. just before the sun goes down until the sun comes up again.

Although I will note from personal experience, be careful with that automation if that light is in a bedroom, next to a bedroom or on the way to a bathroom that sleepy people sometimes use in the middle of the night :slight_smile: