Skip to content

This Home Assistant custom integration provides real-time speed test monitoring for UniFi networks. It allows you to track download speed, upload speed, and ping directly within Home Assistant.

License

Notifications You must be signed in to change notification settings

biofects/HA-Unifi-Speedtest

Sponsor Me

🌐 UniFi Speedtest for Home Assistant

πŸ” About

This Home Assistant custom integration provides real-time speed test monitoring for UniFi networks with enhanced dual WAN support. It supports all UniFi platforms including UDM Pro, UDM SE, Cloud Key, and traditional UniFi Controller software, allowing you to track download speed, upload speed, and ping directly within Home Assistant.

πŸ†• v2.2.0: Smart Controller Detection - User-controlled controller type selection with intelligent entity creation based on actual WAN connections.

hacs_badge GitHub Release GitHub Last Commit GitHub Issues License


πŸ’Έ Donations Appreciated!

If you find this plugin useful, please consider donating. Your support is greatly appreciated!

Sponsor me on GitHub

Sponsor Me

or

Paypal

paypal


✨ Features

  • οΏ½ Smart Controller Detection: User-controlled selection between UDM and traditional controller types
  • οΏ½ Intelligent WAN Management: UDM controllers automatically detect multiple WANs, traditional controllers use single WAN
  • πŸ“Š Connection-Based Entities: Only creates entities for actually connected WAN interfaces
  • πŸ”§ Universal Compatibility: Works with UDM Pro, UDM SE, UDM Base, Cloud Key Gen2+, and traditional UniFi Controllers
  • οΏ½ Real-time Metrics: Monitor download speeds, upload speeds, and network latency (ping) for each connected WAN
  • πŸš€ Speed Test Initiation: Start speed tests remotely via Home Assistant (traditional controllers)
  • 🏠 Home Assistant Integration: Full integration with automations, scripts, and dashboards
  • βš™οΈ Clean Naming: Smart entity names based on number of connected WANs (single WAN gets clean names)
  • πŸ”’ Reliable Authentication: Fixed endpoint selection prevents 401/404 errors

πŸ“Έ Screenshots

Configuration

Configure multi-WAN support during setup to enable separate monitoring for each WAN interface:

Multi-WAN Configuration

Dual WAN Monitoring in Action

See how the integration creates separate sensors for each WAN interface, providing individual speed metrics:

WAN 1 Sensors

Monitor your primary WAN connection with dedicated sensors for download, upload, and ping:

WAN 1 Sensors

WAN 2 Sensors

Track your secondary WAN connection independently with its own set of performance metrics:

WAN 2 Sensors

Notice how each WAN interface gets its own sensors, solving the issue where dual WAN setups previously showed identical speeds for both connections.

πŸ— Supported Systems

βœ… UDM Pro / UDM SE

  • Multi-WAN Support: βœ… Full dual WAN detection and monitoring
  • Speed Test Monitoring: βœ… Automatic retrieval of speed test results
  • Separate Sensors: βœ… Individual sensors for each WAN interface
  • URL Format: https://udm-ip (port 443)

βœ… UDM Base

  • Multi-WAN Support: ❌ Single WAN hardware limitation
  • Speed Test Monitoring: βœ… Standard monitoring for single WAN
  • Backward Compatible: βœ… Works exactly as before
  • URL Format: https://udm-ip (port 443)

βœ… Cloud Key Gen2+ with Multi-WAN Gateway

  • Multi-WAN Support: βœ… Depends on gateway model (USG Pro 4, UXG Pro)
  • Speed Test Monitoring: βœ… Full functionality
  • API Support: βœ… Modern UniFi OS endpoints
  • URL Format: https://cloudkey-ip (port 443)

βœ… Traditional UniFi Controller Software

  • Multi-WAN Support: ⚠️ Depends on gateway hardware
  • Speed Test Monitoring: βœ… Full functionality including API-initiated tests
  • Legacy Support: βœ… Enhanced compatibility with older API structures
  • URL Format: https://controller-ip:8443

πŸš€ Installation

HACS Installation (Recommended)

  1. Open HACS in your Home Assistant instance
  2. Click on "Integrations"
  3. Click the three dots in the top right corner
  4. Select "Custom repositories"
  5. Add this repository URL
  6. Select "Integration" as the category
  7. Click "Add"
  8. Find "HA Unifi Speedtest" in the integration list
  9. Click "Download"
  10. Restart Home Assistant

Manual Installation

  1. Download the latest release
  2. Copy the custom_components/ha_unifi_speedtest directory to your Home Assistant's custom_components directory
  3. Restart Home Assistant

βš™ Configuration

  1. Go to Configuration > Integrations
  2. Click "+" to add a new integration
  3. Search for "HA Unifi Speedtest"
  4. Enter the following details:
    • URL: Your UniFi Controller URL
      • UDM Pro/SE: https://udm-ip
      • Cloud Key Gen2+: https://cloudkey-ip
      • Traditional Controller: https://controller-ip:8443
    • Username: UniFi Controller admin username
    • Password: UniFi Controller admin password
    • Controller Type: Select your controller type
      • UDM Pro/SE/Cloud Key Gen2+ - for UniFi OS devices (supports multi-WAN detection)
      • Self-hosted Controller - for traditional UniFi Controller software (single WAN mode)
    • Site (Optional): Site name (default: "default")
    • SSL Verification (Optional): Enable/disable SSL certificate verification
    • Multi-WAN Detection: Automatically enabled for UDM controllers, disabled for traditional controllers
    • Enable Automatic Speed Tests: Schedule regular speed tests
    • Speed Test Interval: How often to run automatic tests (15-1440 minutes)

πŸ“‹ See the Screenshots section above for visual examples of the configuration process and resulting sensors.

πŸ“‘ Sensors

Single WAN Setup

The integration creates three sensors for monitoring network performance:

  • UniFi Speed Test Download Speed (Mbit/s)
  • UniFi Speed Test Upload Speed (Mbit/s)
  • UniFi Speed Test Ping (ms)

πŸ†• Dual WAN Setup

For multi-WAN configurations, separate sensors are created for each WAN interface:

WAN 1:

  • UniFi Speed Test Download Speed WAN (Mbit/s)
  • UniFi Speed Test Upload Speed WAN (Mbit/s)
  • UniFi Speed Test Ping WAN (ms)

WAN 2:

  • UniFi Speed Test Download Speed WAN2 (Mbit/s)
  • UniFi Speed Test Upload Speed WAN2 (Mbit/s)
  • UniFi Speed Test Ping WAN2 (ms)

Additional Sensors

  • UniFi Speed Test Runs: Track total number of speed tests performed
  • UniFi API Health: Monitor integration connection status

🏷️ Sensor Attributes

Each multi-WAN sensor includes additional attributes:

  • interface_name: Physical interface (e.g., "eth9", "eth10")
  • wan_networkgroup: WAN group name (e.g., "WAN", "WAN2")
  • wan_number: Sequential WAN number
  • total_wan_interfaces: Total detected WAN interfaces
  • is_primary_wan: Boolean indicating primary WAN (intelligently determined from routing/config)
  • timestamp: Last speedtest timestamp
  • status: Interface status

Note on is_primary_wan: This attribute now reflects the actual primary WAN as configured in your UniFi controller, not just the first physical port detected. If you've configured a secondary port (like SFP+ port 2) as your primary WAN, that interface will correctly show is_primary_wan: true.

πŸ”§ Services

ha_unifi_speedtest.start_speed_test

Initiates a speed test on your UniFi network.

Note: Only available for traditional UniFi Controller software. UDM Pro users must start speed tests manually via the UniFi Network web interface.

Example Usage:

In Automations:

action:
  - service: ha_unifi_speedtest.start_speed_test

In Scripts:

test_network_speed:
  sequence:
    - service: ha_unifi_speedtest.start_speed_test
    - delay: "00:02:00"  # Wait for test to complete
    - service: notify.mobile_app
      data:
        message: "Speed test completed. Download: {{ states('sensor.unifi_speed_test_download_speed') }} Mbps"

Lovelace Button:

type: button
name: Start Speed Test
tap_action:
  action: call-service
  service: ha_unifi_speedtest.start_speed_test

ha_unifi_speedtest.get_speed_test_status

Manually refreshes speed test data from your UniFi controller.

πŸ“Š Example Dashboard

type: entities
title: Network Speed Test
entities:
  - entity: sensor.unifi_speed_test_download_speed
    name: Download Speed
  - entity: sensor.unifi_speed_test_upload_speed  
    name: Upload Speed
  - entity: sensor.unifi_speed_test_ping
    name: Ping

HA UniFi Speedtest v2.0.1 - Update Notes

πŸ†• What's New in v2.1.1 (Latest)

πŸ› Bug Fixes

  • UDM Pro Compatibility: Fixed 404 errors on UDM Pro devices that don't support advanced routing endpoints
  • Graceful Fallback: Integration now automatically detects unsupported UDM routing endpoints and switches to controller mode
  • Cleaner Logs: Eliminated repetitive 404 error messages during setup
  • Improved Stability: Better error handling prevents integration setup failures

πŸ†• What's New in v2.1.0

βœ… Intelligent Primary WAN Detection

  • Smart Primary WAN Detection: Now properly identifies the primary WAN interface based on routing tables and network configuration
  • Resolves Dual WAN Issues: Fixes issues where secondary physical ports configured as primary WAN showed incorrect "is_primary_wan" status
  • Multiple Detection Methods: Uses routing table analysis, network configuration, and speed test data to determine the true primary WAN
  • Smart Device Naming: Automatically names devices and sensors as "Primary WAN" and "Secondary WAN" for clarity
  • Backward Compatible: Falls back to previous behavior if advanced detection fails

βœ… Enhanced User Experience

  • Clear Device Names: Devices now show as "Primary WAN" and "Secondary WAN" instead of "WAN" and "WAN2"
  • Improved Sensor Names: Sensors clearly indicate which is primary vs secondary
  • Better Attributes: Enhanced sensor attributes show primary WAN status and interface details

πŸ†• What's New in v2.2.0

βœ… User-Controlled Controller Type Selection

  • No More Auto-Detection: Eliminated confusing automatic controller detection that could misidentify your setup
  • Clear Controller Options: Choose between "UDM Pro/SE/Cloud Key Gen2+" or "Self-hosted Controller"
  • Reliable Endpoint Selection: Always uses the correct API endpoints for your controller type
  • Fixed Authentication Issues: Resolved 401/404 errors caused by incorrect endpoint detection

βœ… Intelligent WAN Interface Management

  • UDM Multi-WAN Logic: UDM controllers automatically check for multiple WAN connections
  • Connection-Based Entity Creation: Only creates entities for actually connected WAN interfaces
  • Clean Single WAN Naming: When only one WAN is connected, gets clean names like "Download Speed" instead of "Download Speed WAN1"
  • Traditional Controller Single WAN: Self-hosted controllers use single WAN mode with appropriate endpoints

βœ… Enhanced User Experience

  • Eliminated Unknown Entities: No more persistent "Unknown" entities that couldn't be removed
  • Better Configuration UI: Clear descriptions help you choose the right controller type
  • Improved Error Messages: More helpful messages when no speedtest data is available
  • Predictable Behavior: Integration behaves consistently based on your controller type selection

βœ… Previous Updates (v1.4.0)

  • Added Poll Control: Configurable poll interval
  • Fixed Compatibility Issues: Resolved UDM and Software-based controller issues
  • Adjusted Initial Run Time: Corrected initial run timing for software controllers
  • Manual Speed Test Button: Added on-demand speed test capability

βœ… Manual Speed Test Button

Add this button to your dashboard for on-demand speed tests:

show_name: true
show_icon: true
type: button
name: Start Speed Test
icon: mdi:speedometer
tap_action:
  action: call-service
  service: ha_unifi_speedtest.start_speed_test

πŸ“Š Available Sensors

  • UniFi Speed Test Download Speed - Download speed in Mbit/s
  • UniFi Speed Test Upload Speed - Upload speed in Mbit/s
  • UniFi Speed Test Ping - Latency in ms

πŸ”§ Compatibility

  • βœ… UDM Pro / UDM SE / Cloud Key - Full support with automatic speed test triggering
  • βœ… Traditional UniFi Controller Software - Full support
  • βœ… Both controller types get fresh speed test data every hour automatically

πŸš€ Quick Setup

  1. Install Integration: Add via HACS or copy files to custom_components/ha_unifi_speedtest/
  2. Configure: Settings β†’ Devices & Services β†’ Add Integration β†’ "HA Unifi Speedtest"
  3. Enter Details: Your UniFi controller URL, username, password, and controller type
  4. Done!: Sensors will appear automatically with hourly speed tests

The integration now works seamlessly with both UDM Pro and traditional UniFi Controllers, providing regular speed test data with proper Home Assistant unit standards.

πŸ”§ Troubleshooting

Common Issues

403 Forbidden Error:

  • Verify your username/password are correct
  • Ensure the user account has admin privileges
  • For UDM Pro: Disable 2FA temporarily or create a local admin user

Connection Refused:

  • Check the URL format matches your controller type
  • Verify the controller is accessible from Home Assistant
  • Check firewall settings

No Speed Test Data:

  • Ensure at least one speed test has been run on your controller
  • Traditional controllers: Use the start_speed_test service
  • UDM Pro: Run a speed test via the web interface first

Primary WAN Detection Issues

The integration now uses intelligent primary WAN detection to properly identify which WAN interface is actually your primary connection, even if you've configured a secondary port (like SFP+ port 2) as your primary WAN.

Primary WAN Detection Methods (in order of priority):

  1. Routing Table Analysis: Checks the default route (0.0.0.0/0) to identify which interface handles the primary traffic
  2. Network Configuration: Looks for explicitly configured primary WAN settings in the UniFi controller
  3. Speed Test Data: Uses the WAN interface with the most recent and complete speed test data
  4. Fallback: Uses the first detected interface (legacy behavior)

If Primary WAN Detection is Incorrect:

  1. Check UniFi Network Settings:

    • Verify that your desired primary WAN is correctly configured in the UniFi Network application
    • Ensure the routing table reflects your intended primary WAN
  2. Check Integration Logs:

    • Enable debug logging (see below)
    • Look for messages like: "Primary WAN determined from routing table: eth9_WAN"
    • The logs will show which detection method was used
  3. Check Sensor Attributes:

    • Go to Developer Tools > States
    • Find your UniFi speed test sensors
    • Check if is_primary_wan is correct on your configured primary WAN

Expected Behavior:

  • The WAN interface you've configured as primary in UniFi should show is_primary_wan: true
  • That interface should have the speed test results
  • Other WAN interfaces should show is_primary_wan: false
  • Devices and sensors will be named "Primary WAN" and "Secondary WAN"

Debug Logging

To enable debug logging, add the following to your configuration.yaml:

logger:
  default: info
  logs:
    custom_components.ha_unifi_speedtest: debug

🀝 Contributing

Feel free to contribute to this project. Please read the contributing guidelines before making a pull request.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

βš– Disclaimer

This integration is not affiliated with Ubiquiti Inc. or UI.com. All product names, logos, and brands are property of their respective owners.

About

This Home Assistant custom integration provides real-time speed test monitoring for UniFi networks. It allows you to track download speed, upload speed, and ping directly within Home Assistant.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages