Delay on turn off even by physical switch, ZHA, ZBMINIR2

I have ZBMINIR2 with a reed sensor (attached to a door) as a physical switch and a light connected. This device is connected to ZHA works fine.
What i wanted is to delay turning off the light if the reed sensor (door) is triggered. So, if HA turns off the light - turn off immediately, but if a door was open/closed - turn off the light with a delay.

Is it possible to catch an event of physical switch toggling to create an automation?