Again, though, if you just do the “if door first then motion” versus “if motion first then door” then your rules for “someone goes out” will be triggered if you open the door to accept a package or a pizza delivery. That’s why this is all a little more complicated than it seems at first.
@storageanarchy 's suggestion of thread of basing part of the logic on a smart lock solves this if the smart lock can distinguish between the lock being opened with the manual lever on the inside versus being opened from the outside with a code.
In some households, you can also do this with mode but only if you have an “I’m leaving” mode which is different from your “home” mode and is triggered by something else yet again. (I do this at my own house as discussed in the thread on that method. )
There are some other ways to approach it as well. And webcore can definitely be useful once you have laid out your desired set of events to distinguish “coming home” from “leaving home.”
But first, you have to figure out what to do about the door opening when you are not leaving the house!