Help with Automation to Lock Door After 4 Minutes only when it's Closed

I have a Schlage Encode Plus door lock and an Aqara Contact Sensor on my Front Door. I want to have Home Assistant lock the door after a period of time (for example 4 minutes) if the Aqara sensor shows that the door is closed. If the door is still open then I want Home Assistant to wait 4 minutes and then check to see if the door is closed. If it is then lock the door and if it’s not basically keep trying every 4 minutes until the door closes and then lock it. Attached are screenshots of the automation I wrote. Can someone please help me troubleshoot? I’d prefer to do this from the GUI.



Post your automation in YAML format, not as a screenshot.

FAQ Guideline 11 - Format it properly
FAQ Guideline 14 - Screenshots

It wouldn’t let me post the code so I am posting screenshots of the YAML.



I just read the FAQ. I’ll try posting the YAML again instead of a screen shot of the YAML.