Simple idea, I’m just hung up on how to implement. I’m using two ISP providers, we’ll call them Cable and 5G. Cable is cheap and reliable but very slow, so it’s mostly a backup provider for when the primary goes down. 5G is about six times as fast but not quite as reliable. I have a router that will automatically switch internet traffic over from one to the other if it’s down; i.e. if 5G is down then all devices that use 5G as the primary connection (most, as it’s set to default) switch over to Cable, and if Cable is down the few devices that use it as primary will switch to the 5G connection.
The issue is that my 5G connection has a bad habit of just going down and not coming back up without me physically unplugging it and plugging back in. So I’ll notice the speeds aren’t great, sites are timing out, etc. and eventually I think to load up Speedtest to see who my ISP is. Cable is fast enough to be the only internet for the gaming consoles, but not for all the streaming devices, tablets, various iot devices, etc.
So, I figure I could get a zigbee smart outlet, have Home Assistant check who the current isp provider is, and if it’s the Cable provider for more than 5-10 minutes, power cycle the 5G modem. I figure I could have a wait/sleep command at the end for an hour or five to keep needless power cycles to a minimum in case 5G just isn’t going to come back up for a while.
I did notice that a traceroute on 5G currently shows the first hop that has a reverse dns that has my isp’s name in it (i.e. 12-something-345-67.myisp.com), so that might work? I have to check that Cable does the same. I’d rather an Automation check if Cable is the provider and if so, reboot; if it’s checking if 5G is the provider and if not, reboot, it’s possible that it’s actually the result of a change upstream causing it to show up differently and thus causing unnecessary reboots.
Anyone do something similar and can provide some pointers?
Some routers have integrations in HASS that allow reading stuff from the router, for example the WAN IP address or DNS servers. I do this for my Asus router.
Thanks! Looks like I’ll be able to make this work. I’ve just gotten into Home Assistant semi recently (end of last year), so if it’s not in the gui, I most likely didn’t know about it.
I have an EdgeRouter which does have an integration, but don’t see how I could get it to work in this particular instance. When 5G goes out, the EdgeRouter still shows a WAN IP for that interface, it just doesn’t work. I didn’t see a way for the integration to report that the router has had to stop sending traffic out a certain WAN port. Plus I plan on upgrading in the near future to something with at least 2.5GB ports, so looks like I’ll be using the EdgeRouter as backup only. Thanks though!
Just an update in case anyone else is trying to get this to work.
Tried coming up with the code myself, didn’t work. Then tried ChatGPT, didn’t work. Asked ChatGPT a second time and got a different suggestion. It suggested I put this in configuration.yaml:
This actually gave me a workable solution, but I wanted to use ip-api.com instead, use the ‘isp’ variable, and only update once every five minutes. I also changed the name to “ISP In Use” so I can quickly find it in the Entities list. Here’s what I used:
sensor:
- platform: rest
name: ISP In Use
scan_interval: 600
resource: http://ip-api.com/json/?fields=isp
value_template: '{{ value_json.isp }}'
Then I set an Automation to use a State as a Trigger, Entity is “ISP In Use”, “To (Optional)” is set to the exact name that’s reported for the Cable ISP (the one that is used if the primary connection is down), with the “For” time set at 11 minutes (since it’s set to update every five minutes, this should give it enough time to check at least twice before deciding the primary 5G connection is down). The Action is to turn off the smart outlet the 5G modem is plugged into, a 20 second wait, then turning the smart outlet on.
Since it’s only triggered on the value changing TO the Cable ISP’s name, it isn’t triggered multiple times if the 5G modem is rebooted but internet does not come back up. It would need to change to something other than the Cable ISP, then back for the Automation to be triggered again (it’s also triggered if Home Assistant is reloaded and the ISP is still Cable, because technically it’s changing from blank to the Cable ISP’s name). This is ideal for me, as if there’s an actual issue with the 5G service it’ll just reboot the modem once and won’t try again.
What you could do is add multiple triggers.
You have for 11 minutes now.
Copy that and make one for 16 minutes.
And one at 21 minutes and so on.
You could also make it trigger every five minutes but I do not recommend this.
I would add a few more triggers, they are “cheap”, won’t affect anything and easy to add.
Yes, but for my use case I don’t want it to do that. If a reboot doesn’t clear the issue, there’s no need to reboot a second, third…four-hundredth time. If this were a remote install that I needed to be able to fix itself for any scenario (including 5G service going down and then needing a reboot hours after the initial outage), I could setup a second automation to run at a specific time each day (say, 2AM) and if it sees the isp is Cable, just reboot immediately. Or reload Home Assistant, that would work too.