Use OpenHAB to restart internet connect

I have a Raspberry Pi and I like to use it for HA. The first thing I’d like to do is have my Pi restart my internet hardware if it goes down for any reason. The HA software needs to restart the hardware given a trigger from an external source…the software which would monitor the network. What sort of hooks does OpenHAB have that would handle such an external trigger. I’ve not settled on the monitoring software, so I’d like to know what capabilities with respect to OpenHAB that I should have.


I’m restarting my Internet connection if it’s down. I’m not doing it on my rpi3 where openhab runs, but you could do it on the same machine where openhab runs.

A simple approach is to run a cron job every 5-15 mins or so, do a PING, and if the connection is down do a restart.


#Your nic                                           

# These lines won't really tell if internet is up/down
# Check anyway, but not acting on it at the moment
IS_UP=`cat /sys/class/net/${INTERFACE}/operstate`
echo "$IS_UP"

# Ping twice just to be sure
/bin/ping -c 2
/bin/ping -c 2
if [ $? -ge 1 ]; then
  echo "Network down :("
  #Run some scripts here like:
 /etc/init.d/network restart
 /etc/init.d/restart some service
  exit 1
  echo "Network up! :)"
  exit 0

You could do this in openhab with execbinding, read status and then restart or do actions within openhab.

Regards, S

What I need to do is restart my network hardware when the internet connection goes down. Not just a particular computer. This script may come in handy anyway as my computers don’t always reconnect when the internet connection comes back up.

“My Break-Dancing days are over, but there’s always the Funky Chicken” – The Full Monty

Hi again!

So my suggestion is the following:

  1. Us a bash/shell script to determine when internet is down (the above pings googles dns-server to see if you get a response).
  2. Use openhab to invoke the shellscript with the execbinding, this can be done using cron rules or similar in openhab
    (personally i prefer to check this outside openhab).
  3. If openhab detects using execbinding and your shellscript that the internetconnection is down, you can trigger a new shell script via openhab to restart that computer. Or if you have wall-plugs or similar, have openhab turn the power off and on again on the particular hardware. If you want to restart the computer/hardware with a shell-script you can do this over ssh. Just google “Invoke remote command using ssh” or similar.

Regards S

Just don’t use Wi-Fi wall plugs to power off and on your router! :joy:

1 Like

Actually, I have no choice, as my network hardware has no switch.

But its not a computer. Its my Apple AirPort that will need to be restarted. It has not on/off switch. I’ll have it connected to a wall plug and I’ll need to toggle that wall plug. So my shell script will determine the state of the connection. If the connection is down, it needs a way to tell OH to toggle that wall plug.


Like I said above, take a look at the execbinding.

You can read the result of the shellscript in openhab, and then write a rule that depending on the state of the command
you can issue sendCommand to turn off and on your wallswitch from openhab.
The shellscript part is in other words only to determine if your internet connection is alive. This could perhaps be done in some other way (Like using http-bining and access some page), it’s just my suggestion on how to do this.

Myself I use Z-wave wallplugs, and they can be controlled from openhab. But there are several different technologies that would work, like knx, wifi, x10 etc.

Regards S

May be off topic, my RPi3 will never reconnect to wifi if router goes down for some reason/ rebooted
Is that normal or just happening to me?

I’ve never seen it happen to any of my RPi3’s. You might want to check on an RPi3 forum for help troubleshooting that one.