ESP8266 keep a relay ON if I'm home, periodic check via wifi...???

So I'm trying to see if its possible to make an esp8266 module check if someone is home via wifi, and if they are home have the esp8266 keep a relay ON, if they aren't pull whatever pin low turning OFF the relay.

I don't have a clue how to even accomplish this, only idea I had was to maybe make a simple android app which pings the esp8266 server page and if the page is visited in the last 30 minutes keep the relay ON. But this is also an issue since I don't know how to make the esp8266 check if its sever page has been visited/pings in the last 30 minutes...

Does anyone have any ideas or suggestions how this could be accomplished no even necessary with the method I mentioned above??

If you can build the Android app, that might work. You could give the ESP a fixed address on your home network and have the app send a GET/POST that periodically. When you are not home, there will be no response to the requests. When at home, the ESP can send a short response and record the time the request was received. It can switch off the relay 30 mins after the time of the last response.

A better way would not need the Android App. When you arrive at home, your phone will auto-connect to your home router, and regularly ping the router after that. It may be possible to query your router to see the last time that the phone was seen on the network. On most or all the routers I have owned, there is a page showing the connected devices, their names and so on. The difficult part may be to get the ESP to query the router to get this information, because most routers request user name and password to gain access to the page.