Motion Detector with YAMA (Yet Another Motion Automation)

Hard to understand, as in YAML, indents tell the story.
How to help us help you - or How to ask a good question.

That said without looking at your code, if you create an automation that triggers on the first sensor, has a wait-for-trigger #2 and then does your other thing. You have the flowchart in that paragraph already, just do all the things in an automation.