This is a pretty common use case, and there are a couple of existing threads about it.
Short answer is that there are some devices made specifically to do this. They will ping the Internet, Either a specific URL you select. or on some models just a URL from the company. If the pinging is unsuccessful, then the plug will reboot itself. Some models also allow you to create a timer schedule so it reboots once a day or whatever.
Here’s one of the older threads with links to the devices.
ResetPlug for Modem/Router/Hub - #8 by JDRoberts
That handles the situation where you want it to automatically reboot itself when Wi-Fi is lost.
If you want to be able to force a reboot on demand from outside the house, when your Internet is not working, then you need something like @art_333 mentioned.