Help Doorbell Camera as Motion Detector re-triggers itself when the light goes off

Hi I have got an automation that uses my Amcrest Door Bell motion detection binary sensor to turn on an outside light after sunset. The light Stays on for x mins, when the light goes off, the camera see this as motion and triggers the light back on.

How do I add a delay so that the binary sensor is not seen until x mins has past.

  description: Turn On Side Lights If Motion Detected
  trigger:
  - entity_id: binary_sensor.doorbell_camera_motion_detected
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: or
    conditions:
    - after: sunset
      after_offset: -00:30:00
      condition: sun
    - before: sunrise
      before_offset: -00:30:00
      condition: sun
  action:
  - data: {}
    entity_id: switch.side_lights
    service: switch.turn_on
  alias: Turn Off Side Lights when motion ends
  description: ''
  trigger:
  - entity_id: binary_sensor.doorbell_camera_motion_detected
    for:
      minutes: 1
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data: {}
    entity_id: switch.side_lights
    service: switch.turn_off

Kind regards Dave

Add condition that the light has been off greater than 2 seconds

OR

Maybe that automation had not been triggered in 1 minute 2 seconds

There are several ways to accomplish that. One way is to turn off your first automation when its triggered and then turn it back on the last thing you do in your second automation:

add this last in your first automation:

  - service: automation.turn_off
    entity_id: automation.turn_on_side_lights_if_motion_detected

and then last in your second automation add:

  - delay: 0:05 
  - service: automation.turn_on
    entity_id: automation.turn_on_side_lights_if_motion_detected

I put the delay to 5 seconds in my example but you might have to change that depending on how long it takes for your light to switch off.

Thanks, I will try this tonight.

I did not know that you could turn automatons on & off in Yaml

Thanks for taking the time to reply.

Seem to work but it was raining last light so the rain kept triggering the sensor, might need to fit a PIR

Thanks for a solution