Check for Internet Connection?

Is there any easy way of checking for an internet connection and handling things differently based on the result? I use hubduino and an esp8266 to read when someone buzzes my apartment door (and separately to buzz them in if I say to), it works great. It opens a virtual contact sensor when the buzzer wire goes live, which tells alexa routines to trigger an announcement in every room that someone is at the door. Because the notification through alexa is cloud triggered, nothing would happen if my internet went out. I have zigbee chimes I could use locally, but they're much less pleasant to hear than the voice notification -- Ideally if the internet was out, it would trigger the chimes, but if it wasn't out, it would trigger alexa. Thoughts on how to do this?



How about this? [RELEASE] Web Pinger

1 Like

Hmm, that might do it, but I'd have to hope no one rings my door within 5 minutes of losing the internet! Maybe I could set something up on the router side to signal hubitat when it has no internet...

How often do you loose Internet? If you have frequent outages and lots of people droping over, 5 minutes would likey be unacceptable. If 5 minutes truely is too long, have a look through the code. You can probably adjust it to be shorter. The 5 minutes was likely chosen to not overwhelm the HE hub.

1 Like

To build on above, you could fork or adjust the code that is here

line 92 has the options, you could add 1 or 2 or whatever

line 210 has the part where it takes that value and creates the schedule

If the values are adjusted, especially to 1 minute, I would test, test, test to make sure the short time period didn't cause issues for the hub. Use as is with logging turned on and see how much time each run takes. Be aware of other situations that could cause delays during a run that might extend a run time. 1 minute could be short enough that a delay could have the process run into the back of the previous run and then compound.

I very infrequently lose wifi, so five minutes is not the end of the world, it's just not an ideal setup either. I also agree proactively pinging the internet from my hub all day just in case it happens to be the one or two times a year I lose wifi is less than elegant. Two options for offloading this responsibility that I can think of, 1) some router magic to flip a switch when the internet goes out (I'm waiting on my new router so no idea what my options are on my new one) and more obviously, and probably what I'll do, is make a second virtual switch tied to the esp8266 and just ping the internet once a minute from the door buzzer device itself. It's not doing much of anything while waiting for a signal on the buzzer or parsing hubitat events to know to buzz someone in, so can just tell it if its not connected, open "no internet contact sensor," if it is connected open "internet contact sensor" and then make rules to trigger alexa in one case and the obnoxious zigbee chime in the other case.

EDIT: Actually, rather than doing the logic on the board with two virtual contact sensors, which limits this new knowledge to the door app itself, I'll make a global virtual switch called "Internet" and have it toggle based on the polling from the door buzzer, then handle the same alternate notifications with different smart rules, this way other devices can reference the internet switch too down the line.

You can use another of Bryan's fabulous programs, called "Web Pinger".