Hello. I am new in HA and I have HA running on RPi 4B. How can I manipulate network routing in HA. Note that I cannot make changes to the host’s /etc or anything else because when I reboot the host, the changes I make are gone! This is what I’m trying to accomplish:
I want to be notified on my mobile phone when the any major thing happens within HA, example, when the internet is down.
I have eth0 right now for my main network connection for HA. I will be adding in the future an Internet-only mobile device from my mobile carrier which I can utilize the WLAN0 of the HA host to connect to. When my cable internet goes down, I can switch the default route to the WLAN0 so the SMS alert can be sent out.
The best way to do this is to configure your router to failover to the mobile carrier when the main internet connection is detected as down. How you do this depends on your router.
You can detect the change using this integration:
And automations:
- id: 1a4dc408-76f5-41cf-8b68-c3ec3bcf3c59
alias: 'IP Change'
trigger:
platform: state
entity_id: sensor.myip
action:
- service: notify.telegram_system
data:
title: '⚠️ *Public IP changed*'
message: "From {{ trigger.from_state.state }} to {{ trigger.to_state.state }}"
- id: be05c9a9-b308-4c6e-ad06-a76563ab9332
alias: 'Fibre Outage'
trigger:
platform: state
entity_id: sensor.myip
from: !secret fibre_static_ip
for:
minutes: 30
action:
- service: notify.telegram_system
data:
title: '⛔ *Internet Fibre Outage*'
message: >
WAN has been using 4G data for 30 minutes. Please check the Fibre connection status.
4G Downloaded {{ states('sensor.4g_downloaded') }} MB
4G Uploaded {{ states('sensor.4g_uploaded') }} MB
The trigger will be a little different for that second automation if you don’t have a static public ip. You will have to use a template trigger to check for an ip range.
Say your dynamic IP address for your main internet connection is something like 111.222.333.444 and the first two octets never change (111.222…) and your mobile carrier is something completely different, then you would use:
- id: be05c9a9-b308-4c6e-ad06-a76563ab9332
alias: 'Fibre Outage'
trigger:
platform: template
value_template: "{{ '111.222' not in states('sensor.myip') }}"
for:
minutes: 30
Thanks. I have to figure out how to do this as the router that eth0 of the HA is connected does not have any knowledge of HA’s WLAN which is connected to an internet-only mobile device. I have already figure out how to detect internet outage on eth0 of the HA + I have noip.com as my DDNS provider. If only I can change the routing table within HA, it would be easier. Maybe I don’t have to do this if HA will dynamically route packets to a live connection to the internet - meaning, if eth0 is down, it will automatically send outgoing packets to the internet via wlan0, which is alive…
I know. But the underlying host (RPi) can manipulate routing however, I cannot manipulate it with HA. HA does not want me to touch the host OS! I could either manipulate the Default route or change the metric of the wlan0 to a lower value! Oh well.
RFC: make HA manipulate routing between eth0 and wlan0. Amen.