Spent some time loading home assistant supervised so I could check this out on a generic version of linux. I used ubuntu 18.04 for odriod xu4. The following python script does exactly what is required on a standard linux distribution. The default route switches and the home assistant container traffic switches paths. I only tested with pings from the container. At some point I’ll test with the home assistant cloud.
#!/usr/bin/python3
import os
import time
primeNIC = "eth0"
backupNIC = "wlan0"
testHost = "8.8.8.8"
onbackup = False
lowMetric = "50"
highMetric = "200"
os.system("ifmetric " + primeNIC + " " + lowMetric)
os.system("ifmetric " + backupNIC + " " + highMetric)
while True:
response = os.system("ping -I " + primeNIC + " -c 1 " + testHost)
# and then check the response...
if response == 0:
pingstatus = "Network Active"
print("Status "+ pingstatus)
if onbackup == True:
print("Switching back to prime network!!")
os.system("ifmetric " + primeNIC + " " + lowMetric)
os.system("ifmetric " + backupNIC + " " + highMetric)
onbackup = False
else:
pingstatus = "Network Error"
print("Status "+ pingstatus)
if onbackup == False:
print("Switching backup network!!")
os.system("ifmetric " + primeNIC + " " + highMetric)
os.system("ifmetric " + backupNIC + " " + lowMetric)
onbackup = True
time.sleep( 10 )