Production ready Home Assistant packages and helper scripts for monitoring a UniFi gateway with a focus on WAN health, failover visibility, traffic telemetry, VPN status, and webhook based event ingestion.
- WAN config and WAN health via UniFi API
- WAN traffic monitoring via SNMP
- internet health and stability scoring
- failover and outage visibility
- VPN and Teleport status visibility
- WAN event history storage
- webhook ingestion from UniFi Alarm Manager
- event based notification handoff via
unifi_network_monitor_notification
The package itself does not send push notifications directly. Instead, it emits the Home Assistant event:
unifi_network_monitor_notification
This makes the repo portable. You can route notifications in your own stack, for example through:
- Home Assistant automations
- mobile app notifications
- Telegram
- Matrix
- TTS
- JARVIS or any custom event router
A local example bridge is included at:
examples/notifications.local.example.yaml
If you already have your own event driven notification handling, you can ignore that file completely.
packages/network/
internet.yaml
unifi_api.yaml
unifi_helpers.yaml
unifi_traffic.yaml
unifi_vpn_status.yaml
unifi_webhook.yaml
scripts/
udm_cache_update.sh
get_wan_config.sh
get_wan_health.sh
get_vpn_status.sh
wan_event_history_add.sh
wan_event_history_clear.sh
examples/
secrets.example.yaml
notifications.local.example.yaml
secrets/
udm_api.env.example
LICENSE
README.md
Reads WAN config and WAN health from the UniFi API through local helper scripts.
Reads WAN traffic counters via SNMP and derives RX and TX rates and totals.
Builds health, failover, routing and stability logic on top of the raw WAN data.
Provides VPN and Teleport visibility from cached UniFi data.
Receives WAN related webhook events from UniFi Alarm Manager and writes them into Home Assistant helpers, counters, history and a generic event stream.
Defines helper entities and shell commands used by the package.
The package assumes:
- Home Assistant with YAML package support
- the
command_lineintegration - the
snmpintegration - file access to
/config - package files available under
/config/packages/network/ - helper scripts available under
/config/scripts/
The helper scripts use these binaries:
bashcurljqwgetnslookup
Copy these folders into your HA configuration directory:
packages/network/to/config/packages/network/scripts/to/config/scripts/
You do not need to copy examples/ into production.
Those files are only templates.
If you do not already use packages, add:
homeassistant:
packages: !include_dir_named packagesUse examples/secrets.example.yaml as a template.
At minimum, define these values in /config/secrets.yaml:
udm_snmp_host: 192.168.1.1
udm_snmp_community: your-snmp-community
internet_dns_internal_check_command: "nslookup homeassistant.io 192.168.1.1 >/dev/null 2>&1 && echo OK || echo FAIL"
udm_alarm_manager_wan_webhook_id: change-me-randomly
udm_alarm_manager_wan_debug_webhook_id: change-me-randomly
# Optional advanced SNMP OID overrides for WAN traffic monitoring
# These values depend on the gateway model and its interface indexes
# The examples below match a typical dual WAN setup with WAN1 ifIndex 3 and WAN2 ifIndex 5
udm_snmp_wan1_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.3
udm_snmp_wan1_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.3
udm_snmp_wan2_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.5
udm_snmp_wan2_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.5Notes:
udm_snmp_hostis usually your UniFi gateway IPudm_snmp_communitymust match the SNMP configuration on the gatewayinternet_dns_internal_check_commandshould query your internal resolver such as AdGuard Home or Pi-hole- webhook IDs should be random and private
- the OID overrides are optional and only needed if your hardware uses different WAN interface indexes than the example values
Create this file:
/config/secrets/udm_api.env
Use secrets/udm_api.env.example as a template:
UDM_USER='your-udm-username'
UDM_PASS='your-udm-password'
UDM_HOST='192.168.1.1'
UDM_SITE='default'
UDM_SITE_NAME='Default'
UDM_API_KEY='your-optional-integration-api-key'
UDM_TELEPORT_PREFIX='192.168.2.'Notes:
UDM_API_KEYis optional, but useful for certain integration endpointsUDM_SITEis usuallydefaultUDM_TELEPORT_PREFIXis optional and only improves Teleport client detection heuristics
After copying files and creating secrets, restart Home Assistant.
Then check:
- Developer Tools → YAML → configuration check
- Settings → System → Logs
- the states of
sensor.udm_wan_health_raw,sensor.udm_wan_config_raw, andsensor.udm_vpn_status_raw
You do not need external SSH access to your Home Assistant host just to use this repository.
For most users, this is enough:
- File Editor to copy and edit files under
/config - Terminal & SSH or Studio Code Server for optional setup checks and troubleshooting
If you are only copying the files, editing secrets, and restarting Home Assistant, the File Editor is usually enough.
A terminal becomes useful if you want to:
- manually test a script
- verify tool availability
- inspect paths or permissions
- troubleshoot why a raw sensor stays
unknown
This repository is intended to call scripts through bash, for example:
bash /config/scripts/get_wan_health.sh
That means the scripts do not have to be directly executable.
A separate chmod +x /config/scripts/*.sh step is therefore not required.
If you want to verify the scripts before debugging YAML, run:
bash /config/scripts/get_wan_health.sh
bash /config/scripts/get_wan_config.sh
bash /config/scripts/get_vpn_status.shIf one of these commands fails here, Home Assistant will also fail to read it.
If you want a terminal inside Home Assistant, these are the easiest options:
- Terminal & SSH
- Studio Code Server with built in terminal
External SSH access from another machine is optional and not required for this project.
The cache updater logs in against the UniFi gateway and reads WAN, health, VPN and client information. The configured UniFi account therefore needs enough permissions to access those endpoints.
Enable SNMP on the UniFi gateway and make sure:
- the community string matches
udm_snmp_community - the gateway in
udm_snmp_hostis reachable from Home Assistant
This package reads WAN traffic counters via SNMP from the standard interface MIB.
The relevant counters are typically the high capacity octet counters ifHCInOctets and ifHCOutOctets, which are the 64 bit versions of the classic interface byte counters and are better suited for modern links.
The exact WAN OIDs depend on the ifIndex of the WAN interfaces on your gateway.
ifIndex is the per device interface index used by the interface tables, so the final OID instance depends on how your specific hardware numbers its interfaces.
That is why the correct WAN OIDs can differ between UniFi gateway models and even between different interface layouts.
Because of that, this repository keeps the WAN traffic OIDs configurable instead of hardcoding one model specific layout for everyone.
The example values in secrets.example.yaml match a typical dual WAN style setup where:
- WAN1 uses
ifIndex3 - WAN2 uses
ifIndex5
That results in these example OIDs:
udm_snmp_wan1_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.3udm_snmp_wan1_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.3udm_snmp_wan2_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.5udm_snmp_wan2_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.5
These are only examples.
If your gateway uses different interface indexes, override them in secrets.yaml.
The practical way to find the right WAN OIDs is to inspect the interface table on your own gateway with snmpwalk.
A typical workflow looks like this:
Use the interface description table to find the WAN interface indexes:
snmpwalk -v2c -c YOUR_COMMUNITY YOUR_GATEWAY_IP 1.3.6.1.2.1.2.2.1.2You are looking for the entries that correspond to your WAN ports.
Once you know the correct interface index, query the high capacity octet counters for that index:
snmpget -v2c -c YOUR_COMMUNITY YOUR_GATEWAY_IP 1.3.6.1.2.1.31.1.1.1.6.IFINDEX
snmpget -v2c -c YOUR_COMMUNITY YOUR_GATEWAY_IP 1.3.6.1.2.1.31.1.1.1.10.IFINDEXWhere:
1.3.6.1.2.1.31.1.1.1.6=ifHCInOctets1.3.6.1.2.1.31.1.1.1.10=ifHCOutOctets
Example:
udm_snmp_wan1_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.3
udm_snmp_wan1_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.3
udm_snmp_wan2_in_octets_oid: 1.3.6.1.2.1.31.1.1.1.6.5
udm_snmp_wan2_out_octets_oid: 1.3.6.1.2.1.31.1.1.1.10.5If WAN traffic sensors do not update correctly:
- verify that SNMP is enabled on the gateway
- verify that the SNMP community string is correct
- verify that Home Assistant can reach UDP 161 on the gateway
- verify that the OIDs point to the actual WAN interfaces on your device
- compare
snmpgetoutput with live traffic to confirm you selected the right interface
- these OIDs are not secrets, but they are hardware specific configuration values
- the SNMP community string is sensitive and should stay in
secrets.yaml - the OID examples are meant as a starting point, not as universal defaults for every UniFi gateway model
This package expects WAN related events from UniFi Network Alarm Manager and exposes two Home Assistant webhooks:
- production event webhook
- optional debug webhook
Home Assistant webhook URLs follow this pattern:
https://<your-home-assistant-url>/api/webhook/<webhook_id>
Example:
https://ha.example.com/api/webhook/4b4d8f0f2b2f4f4da0e8...
Create at least one UniFi Network alarm for WAN outage and failover related events and attach a webhook action that points to your Home Assistant URL.
This repo is prepared for both:
- a main webhook for real event ingestion
- an optional debug webhook for payload inspection during setup
- Open UniFi Network
- Go to Alarm Manager
- Click Create Alarm
- Choose a WAN or internet related trigger such as WAN offline, outage or failover related events
- Set the scope if UniFi offers one for that trigger
- In Actions, add a Webhook action
- Paste your Home Assistant webhook URL
- Prefer HTTP POST if available so UniFi includes structured payload data
- Save the alarm
- Trigger a test event or use a controlled WAN test and verify the payload arrives in Home Assistant
- Use the main webhook URL with
udm_alarm_manager_wan_webhook_idfor the real production alarm - Use the debug webhook URL with
udm_alarm_manager_wan_debug_webhook_idwhile validating payload structure - Once your payloads look correct, you can keep the debug alarm disabled or remove it
- If you use a reverse proxy, make sure external webhook requests are forwarded to Home Assistant correctly
- If your Home Assistant instance is not directly reachable, place the webhook behind your existing secure public entry point
The webhook logic in packages/network/unifi_webhook.yaml currently looks for values such as:
- event name
- event message
UNIFIwanIdUNIFIwanNameUNIFIwanIsp
From that, it derives:
- WAN1 or WAN2 mapping
- outage versus recovery detection
- helper updates and counters
wan_event_history- the generic event
unifi_network_monitor_notification
Drop your screenshots in a future docs/images/ folder and reference them here, for example:


Suggested screenshot sequence:
- Alarm Manager overview
- Create Alarm dialog
- Trigger selection for WAN or internet events
- Action selection with Webhook
- Webhook URL and POST configuration
- Resulting event in Home Assistant
After restart, validate these points:
sensor.udm_wan_health_rawreturns datasensor.udm_wan_config_rawreturns WAN configsensor.udm_vpn_status_rawreturns JSON rather than fallback only output- SNMP entities such as
sensor.udm_wan1_in_octetsupdate sensor.internet_health_statemoves out ofunknownsensor.wan_event_historyexists- webhook test events update
input_text.udm_last_wan_event
The package emits unifi_network_monitor_notification with payloads similar to this:
title: UDM WAN Event
severity: warning
source: udm_alarm_manager_wan_webhook
message: WAN1 ausgefallen Telekom DSL Provider
push_tag: udm_wan_eventUsually caused by one of these:
- wrong
UDM_HOST - wrong login credentials
- missing
jq,curl,bash, orwget - temporary UniFi overload returning empty API data
Check:
sensor.udm_vpn_status_raw/tmp/udm_cache.jsonUDM_API_KEYif integration endpoints are needed- whether
UDM_TELEPORT_PREFIXmatches your environment
Check:
- SNMP is enabled on the gateway
- the community string is correct
- the host is correct
- the interface indexes and OIDs match your hardware
- Home Assistant can reach UDP 161 on the gateway
Check:
- the webhook ID matches exactly
- Home Assistant is reachable from the UniFi side
- your reverse proxy forwards webhook requests correctly
- the debug webhook receives test payloads
- the alarm action is configured to use the expected webhook URL
Check:
- whether the YAML command really calls
bash /config/scripts/... - whether the script file was saved under
/config/scripts/ - whether Home Assistant was restarted after changing
shell_command - whether the script works manually when started with
bash
This project is licensed under the MIT License.
See LICENSE for details.