On door open - Logic problem

With this code the Red LED is always lit when you close the door,so if you leave with the door closed, it will show busy (RED). The green LED is on when door is open for longer than 4 seconds, but the toggle between lights when you close and open the door does not work anymore.