Setting condition between sunset and sunrise causes automation to never work

Using the automation editor, I set the trigger to detect if my amcrest IP camera detected motion, with a condition of after sunset and before sunrise.

If the above is met, then a light turns on.

As long as the sunset to sunrise condition is set, it doesn’t do anything. Remove the condition it works fine. But I’d hate to turn on lights during the day.

Any suggestions?

Please post your automation, and I’ll see if I can help.

1 Like

I used the online editor but here is what it spit out.

- action:
  - data:
      entity_id: switch.wemo_insight
    service: switch.turn_on
  alias: Turn on Light if motion detected on ip camera only at night
  - after: sunset
    before: sunrise
    condition: sun
  id: '1509835976986'
  - entity_id: sensor.amcrest_camera_motion_detected
    platform: state
    to: 'True'

did you already figured it out ? i have the same problem

This snippet from the docs works for me but what you posted does not

    condition: or  # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise

I couldn’t figure out how to make my automation work at night ie after sunset until before sunrise the day after until I found your post and realized the order matters.
It works with “after sunset OR before sunrise” (which makes sense as “overnight”) and not the other way around (“before sunrise OR after sunset”) !
Here is what it looks like in the UI :