Door Sensor with Motion Sensor

Hello,

i have automation to turn small light from 6PM till 6AM if the home door is open

i need to create another automation to turn off the lights when i leave the home using the door sensor
but if i back to the home after 6pm the small light will turn off once i close the door.

can the motion sensor help with this?