Clarification on Timer

See:

For your particular case I would recommend option 1, Flag. It would look something like this:

Switch DetectPresence { expire="10m,command=OFF" }
rule "Start detecting presence"
when
    Item main_door changed
then
    if(main_door.state == CLOSED) { // for now there is a bug which may make changed to CLOSED not work
        DetectPresence.sendCommand(ON)
    }
end

rule "Motion sensors or interior doors changed"
when
    Item gMotionSensors received update or
    Item gInteriorDoors received update
then
    if(DetectPresence.state == ON && Presence.state != ON) {
        Presence.sendCommand(ON)
        DetectPresence.postUpdate(OFF) // stop the Expire timer without triggering rule below
    }
end

rule "Stop detecting presence"
when
    Item DetectPresence received command OFF // this does work and is not subject to the bug mentioned above
then
    if(mobile_in_homewifi.state == OFF) {
        Presence.sendCommand(OFF)
        sendMail(...)
    }
end

Since as you describe in your logic, you only switch Presence OFF if your mobile is not on the wifi, why not just use the mobile being on the wifi as your presence detection?

The above doesn’t cover the case though where you open the main door but fail to trip any motion sensors or interior doors. When the Expire binding timer goes off your phone would be on the network but no other event occured to turn Presence ON so it will remain OFF despite your being home.

I would make the event of your phone joining the wifi one of the events that switches Presence to ON and cancels the Timer.

Also, if someone breaks into your house Presence will be set to ON and you will get no alert because you cancel the Timer.