I had this problem a while ago and looked into this solution:
Otherwise I would think an appropriately rated relay connected to the RasPi GPIO to switch the power to the modem would be easy enough.
Remember, you only need to switch the 12v DC, (usually), for the modem, not the 110v AC of the mains, so mains isolation is not a problem.
It should then be as simple as pinging Google every few minutes and triggering the GPIO on a run of 3 failures, (for example).
Both of these look like perfectly reasonable solutions, and I think I could buy all the parts needed to make it for under $5, including shipping, on AliExpress. But I'll have to wait 1-2 months for them to arrive. Or even longer, since the order won't even be processed for another 1-2 weeks due to Lunar New Year celebrations halting virtually all business in China.
The cheapskate in me wants to do this method. But it's far enough out of my depth of knowledge that I'm not even sure I'm adding the right parts to my shopping cart. I'd hate to wait the 2 months for the parts to arrive only to realize that I got the wrong things or I can't get it to work.
I don't have any training or experience with wiring circuit boards to things. And I don't know much about switches and relays and circuits and... electronics or electricity in general, I guess.
In the end I set the computer up with a shutdown schedule, had it automatically boot on power on, and then used a timer switch to shut down the power to it and the modem for 15 mins every day at a time I wasn't likely to be using it.
It ran flawlessly this way for years.
That won't work for me. It goes out sporadically. Sometimes it goes a few days without an outage. Other days I have multiple outages within an hour or two of the previous one. So only cycling the power once per day won't be robust enough for me.
Another alternative would be a ZigBee adapter for a RasPi along with a ZigBee controlled power switch, then you're not reliant on WiFi if it's provided by the modem/router.
Also, you didn't mention, if your modem takes alternative firmware then maybe there's a facility in that to test/reboot.
My modem and router are separate devices, so I can power-cycle the modem without losing local WiFi. I've been happily running custom DD-WRT firmware on my router for years, but I never thought of looking for custom firmware for my modem. I guess I always imagined it as a "dumb" or "black box" signal relay between my router and my ISP. It's an Arris SURFboard SB6190.
I didn't know what a ZigBee was so I looked it up and it appears to just be a smart plug. I actually bought a smart plug recently, but it was a Christmas gift for someone else. I got a really good deal on it (only $1!) but I thought I'd never want to use one, because I didn't want it snooping on me and phoning home without my knowledge/consent. Do you happen to know if smart plugs in general, or the ZigBee specifically, snoop and phone home about stuff? I guess there's not much data that could be gathered from a smart plug, assuming it doesn't have a (potentially hidden) microphone or camera. I think the only things it could know about are just the times/schedule when it is on or off, and perhaps the name of my SSID and nearby SSIDs. But even so, I don't like the idea of internet-connected devices which report on me to their overlords (says the guy with multiple Android devices and multiple Windows 10 PCs in his household...).
This looks like the middle ground as far as convenience and cost goes, considering I already have the RasPi. But it's still slightly on the spendy side when you account for not only the smart plug but also the USB adapter for the RasPi. Looks like it's going to be somewhere in the range of $35-50. To be honest, the ZigBee method seems kind of like the worst of both worlds. Kind of spendy compared to using a simple relay, but still enough DIY jerry rigging that I'm not confident about the process.
So that said, looks like this unit might actually do what you want. Seems a little pricey but depends on how bad you want it.
Yes, that does look like exactly the kind of thing I want. It is a bit pricey, but I suppose that's the convenience cost of having everything done for me and being able to get it right away.
After thinking about it for a while (while typing this up) I've decided to go with both of the extremes, which I guess averages out to the perfect middle ground.
I see I neglected one important aspect of the problem I'm facing, which is that losing my internet connection isn't just a problem for me when I'm away from home. The reason this is a problem anytime I'm not immediately available to spring into action is because I also keep my RasPi connected to at least one cryptocurrency peer-to-peer network in which I can be penalized or deemed less trustworthy if someone tries to connect to my device and it doesn't respond. It's not making me rich, but it's earning me a decent amount of money simply for keeping a device running/connected that I'm already leaving running/connected 24/7 anyway as my personal media server and whatnot.
So this internet outage issue is a problem even when I'm at home: any time I'm sleeping, or outside doing housework, or even when I'm inside doing something (such as taking a shower) that makes me unlikely to notice or unable to respond right away when there's an internet connectivity problem. The issue can strike at any time and the consequences are not just "oh darn I can't listen to my music right now, I guess I'll have to be bored." It can actually "cost" me money in the form of missing out on opportunities to earn cryptocurrency.
So I ordered the ezOutlet3 because it's a finished product I can get from Amazon (2-day shipping!) and then I can start enjoying relative peace of mind very soon. I don't like the fact that it appears to phone home to some 3rd party server which they claim is only to help relay the connection between their device and the smartphone app. And I don't like how expensive it is.
But I'm also planning to order the parts to make my own solution following the instructions linked to by 4wd or wraith808. That way I won't feel stressed if it takes 3 months to arrive. And I can figure out how to put all the pieces and wires together and program it to behave the way I want to at a leisurely pace, without time pressure. And if it ends up for one reason or another that I ordered the wrong parts or I can't get it to work, then I'm only out an additional $5 and I won't be filled with regret about having to buy the ezOutlet3 anyway after months of waiting for the other things. But if I do end up getting it to work the way I want to, then maybe I can sell the ezOutlet3 on eBay to help recoup some of the costs.