Automation of Light after Sunset

Guys
If you place a condition into your automation that the light can only turn on after Sunset, does that condition last till sunrise ?
The reason I ask is I have a light that turns on after motion & the condition is after sunset, but very early in the morning before sunrise time, the automation does not work. It works fine during the evening before I go to sleep.

- alias: Kitchen light on when there is movement
  trigger:
    platform: state
    entity_id: binary_sensor.wyzesense_778f8588
    to: 'on'
  condition:
  - condition: state
    after: sunset
    after_offset: 01:00:00
  - condition: state
    entity_id: light.kitchen
    state: 'off'
  action:
    service: light.turn_on
    entity_id: light.kitchen
  id: e6d88513c8e44aaf959d79f90b0bf211
- alias: Kitchen light Off
  trigger:
    platform: state
    entity_id: binary_sensor.wyzesense_778f8588
    to: 'off'
    for:
      minutes: 2
  action:
    service: light.turn_off
    entity_id: light.kitchen

Any ideas

Use

    - condition: state 
      entity_id: sun.sun
      state: 'below_horizon'
1 Like

Sorry, do i just add those 3 lines in and leave the rest, can I leave the after_offset ?

Thanks

Check this for conditions based on sun

1 Like

Guys, Please can you check my yaml code :
Light on after motion, only just before sunset :slight_smile:

- id: e6d88513c8e44aaf959d79f90b0bf211
  alias: Kitchen light ON when there is movement
  trigger:
  - entity_id: binary_sensor.wyzesense_778f8588
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: sun.sun      
    state: below_horizon
  - condition: numeric_state
    entity_id: sun.sun
    value_template: "{{ state.attributes.elevation }}"
    below: 2.0    
  - condition: state
    entity_id: light.kitchen
    state: 'off'
  action:
  - entity_id: light.kitchen
    service: light.turn_on