Motion Sensor for Dog Door

I want to add a motion sensor to my dog door that will turn on the lights (for 5 minutes) when the dog goes outside between sunset and sunrise.

I have the automation working, but the problem is that if the dog comes back inside the motion sensor is triggered and the lights come on again.

What might I be able to add to the automation to prevent this.

Here is my current automation.

####################################################
#         DOG DOOR LIGHTS OFF  02Nov2021           #
####################################################
- id: "74a2e07a-5a3b-44a8-8a91-ed805da6ea7c"
  alias: "Lights - Patio Lights OFF"
  description: Patio Lights OFF
  trigger:
    - entity_id: binary_sensor.wyze_dog_door
      for: 00:05:00
      platform: state
      to: "off"
      from: "on"
  condition: []
  action:
    - entity_id: switch.patio_light
      service: switch.turn_off
  mode: single
####################################################
#          DOG DOOR LIGHTS ON  02Nov2021           #
####################################################
- id: "5a0de454-4035-4364-9770-d14d73291aac"
  alias: "Lights - Patio Lights ON "
  description: Patio Lights ON
  trigger:
    - entity_id: binary_sensor.wyze_dog_door
      platform: state
      to: "on"
      from: "off"
  condition: []
  action:
    - entity_id: switch.patio_light
      service: switch.turn_on
  mode: single
####################################################
#            END OF CONFIGURATION FILE             #
####################################################

Adding a delay time at the end of your action will create a null period so the automation can’t re-trigger within that time. You could use that as a work-around.

Also, you can easily put both those automations into one.

An alternative is to set a for: on a condition to check the light was off for a certain period before turning it on.

Thanks will give both options a try and see what happens.