Skip to content

Commit 0d21eb8

Browse files
committed
Update README and services cleanup
- Revised the README.md to enhance clarity on integration features and usage, including a new section on advanced automations. - Updated the features list to provide a more detailed overview of supported rules and configurations. - Removed the `reset_rate_limit` service from services.yaml and its implementation in system_services.py to streamline functionality. - Added examples for using services in Home Assistant to improve user guidance.
1 parent 5c42e56 commit 0d21eb8

3 files changed

Lines changed: 30 additions & 54 deletions

File tree

README.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010

1111
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/sirkirby)
1212

13-
UniFi Network Rules is a custom integration for Home Assistant that integrates with your UniFi Dream Machine/Router to both provide and help you create useful interactions and automations for your Home Lab. The goal of this integration is to simplify policy and rule management for real world use cases. I built this because I wanted to enable things like screen time controls for my kids, game server access controls, and more with the push of a button in Home Assistant. Functionality that can be shared with anyone in your home.
13+
UniFi Network Rules is a custom integration for Home Assistant that integrates with your UniFi Dream Machine/Router to both provide and help you create useful interactions and automations for your Home Lab. The goal of this integration is to simplify policy and rule management for real world use cases. I built this because I wanted to unlock the power of my UniFi firewall. From simple things like screen time and game server access controls for my kids, to more advanced like getting notified when a critical rule is changed. And most importantly, make all of this easy to use and share with anyone in your home or home lab. I hope you find it useful!
1414

15-
## Features
15+
## What this integration provides
1616

17-
- Switch entities for all rules, including firewall policies (zone-based firewall), traffic/firewall rules (non-zone-based firewall), forwarding rules, traffic routes.
18-
- VPN management including both client and server configurations for OpenVPN and WireGuard.
19-
- Service actions for full backup and restore of all rules that are managed by this integration.
20-
- Service actions for batch enabling and disabling rules by pattern matching rule names or IDs.
21-
- Service actions for deleting rules by ID.
22-
- LED toggle switch for UniFi access points and other LED capable devices to control LED on/off.
17+
### Switches for enabling and disabling rules and configuration
2318

24-
Request a feature [here](https://github.com/sirkirby/unifi-network-rules/issues).
19+
- Firewall policies (zone-based firewall)
20+
- Traffic/firewall rules (non-zone-based firewall)
21+
- Port Forwarding rules
22+
- Traffic Routes & Traffic Route Kill Switch
23+
- QoS rules
24+
- OpenVPN Client and Server configurations
25+
- WireGuard Client and Server configurations
26+
- UniFi Device LEDs
27+
- WLAN SSIDs
2528

26-
## Requirements
29+
### Advanced automations powered by [Custom Triggers](#real-time-triggers-) and [Custom Services](#services)
2730

28-
- A UniFi device running network application 9.0.92 or later.
29-
- A local account with Admin privileges to the network application. Must not be a UniFi Cloud account.
30-
- Home Assistant 2025.2 or later with network access to the UniFi device.
31+
The included [Triggers](#real-time-triggers-) and [Services](#services) provide a framework for building custom UDM automations to cover a wide range of use cases. For example, you can [backup](#3-backup-trigger---save-config-on-important-changes) and [restore](#full-and-selective-restore) all rules when a change is detected, ensure game server port [forwarding rules get disabled](#2-game-server-management---auto-disable-after-hours) at bedtime, [create and maintain an audit log](#1-security-monitoring---alert-on-unexpected-rule-changes) of all UDM configuration changes, and so much more. Get inspired by the many examples below.
32+
33+
> Questions, ideas, help, or feedback? [Discussions](https://github.com/sirkirby/unifi-network-rules/discussions). Errors or bugs? [Issues](https://github.com/sirkirby/unifi-network-rules/issues).
3134
3235
## Installation
3336

@@ -49,35 +52,35 @@ THEN
4952
4. Search for "UniFi Network Rule Manager" and select it.
5053
5. Enter credentials of a local admin user on your UDM and click on the "Submit" button.
5154

55+
### Requirements
56+
57+
- A UniFi device running network application 9.0.92 or later.
58+
- A local account with Admin privileges to the network application. Must not be a UniFi Cloud account.
59+
- Home Assistant 2025.2 or later with network access to the UniFi device.
60+
5261
## Configuration
5362

54-
**Host**: The IP address or hostname of your UniFi Device.
63+
**Host**: The IP address or hostname of your UniFi Device. ex. `192.168.1.1` or `udm.mydomain.com`
5564

56-
**Username**: The local admin account on the UDM.
65+
**Username**: The local admin account on the UDM. ex. `admin`
5766

58-
**Password**: The password for the UDM account.
67+
**Password**: The password for the UDM account. ex. `password`
5968

6069
**Site**: The UniFi site name to connect to (defaults to "default" if not specified).
6170

6271
**Update Interval**: The automatic refresh interval in minutes. Can be longer since updates real-time.
6372

6473
**Verify SSL**: Enable SSL certificate verification (defaults to disabled for self-signed certificates).
6574

66-
## Usage
67-
68-
Once you have configured the integration, you will be able to see the policies, rules, and routes configured on your UniFi Network as switches in Home Assistant. Add the switch to a custom dashboard or use it in automations just like any other Home Assistant switch.
69-
7075
## Services
7176

7277
The integration provides several services focused on managing and automating existing UniFi Network rules:
7378

7479
### Getting Started with Services
7580

76-
There are two main ways to use these services in Home Assistant:
77-
78-
#### Method 1: Using an Input Button Helper with Automation
81+
Here are some examples of how to get started with services in Home Assistant:
7982

80-
This is the simplest method:
83+
#### Example 1: Using an Input Button Helper with Automation
8184

8285
1. Go to Settings → Devices & Services → Helpers
8386
2. Add a Button helper (e.g., "Refresh UniFi Rules")
@@ -106,7 +109,7 @@ mode: single
106109
107110
<img src="./assets/backup_unr_button.png" alt="Backup UNR Button" width="200" />
108111
109-
#### Method 2: Using Scripts with a Lovelace Button Card (More Customizable)
112+
#### Example 2: Using Scripts with a Lovelace Button Card (More Customizable)
110113
111114
First, create a script in your Settings → Automations & Scenes → Scripts:
112115
@@ -135,6 +138,8 @@ name: Backup my Network Rules
135138
icon: mdi:cloud-upload
136139
```
137140
141+
See below for more automation examples using [Services with Triggers](#service-automation-examples).
142+
138143
### Services Reference
139144
140145
| Service | Description | Parameters |
@@ -145,7 +150,6 @@ icon: mdi:cloud-upload
145150
| `unifi_network_rules.bulk_update_rules` | Enable or disable multiple rules by name pattern | `state`: true (enable) or false (disable)<br>`name_filter`: String to match in rule names |
146151
| `unifi_network_rules.delete_rule` | Delete an existing firewall policy by ID | `rule_id`: ID of the rule to delete |
147152
| `unifi_network_rules.refresh_data` | Refresh data for a specific integration instance or all | `entry_id`: (Optional) Specific integration instance ID |
148-
| `unifi_network_rules.reset_rate_limit` | Reset API rate limiting if you hit request limits | None |
149153
| `unifi_network_rules.websocket_diagnostics` | Run diagnostics on WebSocket connections and try to repair if needed | None |
150154
| `unifi_network_rules.force_cleanup` | Force cleanup of all entities in the integration | None |
151155
| `unifi_network_rules.force_remove_stale` | Force removal of stale or broken entities | `remove_all`: (Optional) Remove all entities instead of just stale ones |

custom_components/unifi_network_rules/services.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,6 @@ force_remove_stale:
238238
selector:
239239
boolean:
240240

241-
reset_rate_limit:
242-
name: Reset Rate Limit
243-
description: Reset the rate limiter for the UniFi API connection
244-
245241
websocket_diagnostics:
246242
name: WebSocket Diagnostics
247243
description: Run diagnostics on the WebSocket connection and attempt to repair if needed

custom_components/unifi_network_rules/services/system_services.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,6 @@ async def async_refresh_data(hass: HomeAssistant, coordinators: Dict, call: Serv
4949
LOGGER.debug("Refreshing coordinator for entry %s", entry_id)
5050
await coordinator.async_refresh()
5151

52-
async def async_reset_rate_limit(hass: HomeAssistant, coordinators: Dict, call: ServiceCall) -> None:
53-
"""Handle reset rate limit service call."""
54-
# Reset rate limit for all APIs
55-
for entry_data in hass.data[DOMAIN].values():
56-
if "api" in entry_data:
57-
api = entry_data["api"]
58-
if hasattr(api, "reset_rate_limit"):
59-
try:
60-
success = await api.reset_rate_limit()
61-
if success:
62-
LOGGER.info("Rate limit reset successful")
63-
else:
64-
LOGGER.warning("Rate limit reset failed")
65-
except Exception as e:
66-
LOGGER.error("Error resetting rate limit: %s", e)
67-
6852
async def async_websocket_diagnostics(hass: HomeAssistant, coordinators: Dict, call: ServiceCall) -> None:
6953
"""Run diagnostics on WebSocket connections and try to repair if needed."""
7054
results = {}
@@ -213,10 +197,6 @@ async def handle_refresh(call: ServiceCall) -> None:
213197
async def handle_refresh_data(call: ServiceCall) -> None:
214198
await async_refresh_data(hass, coordinators, call)
215199

216-
# Handle the reset rate limit service
217-
async def handle_reset_rate_limit(call: ServiceCall) -> None:
218-
await async_reset_rate_limit(hass, coordinators, call)
219-
220200
# Handle the websocket diagnostics service
221201
async def handle_websocket_diagnostics(call: ServiceCall) -> None:
222202
return await async_websocket_diagnostics(hass, coordinators, call)
@@ -230,10 +210,6 @@ async def handle_websocket_diagnostics(call: ServiceCall) -> None:
230210
DOMAIN, SERVICE_REFRESH_DATA, handle_refresh_data, schema=REFRESH_DATA_SCHEMA
231211
)
232212

233-
hass.services.async_register(
234-
DOMAIN, SERVICE_RESET_RATE_LIMIT, handle_reset_rate_limit, schema=vol.Schema({})
235-
)
236-
237213
hass.services.async_register(
238214
DOMAIN, SERVICE_WEBSOCKET_DIAGNOSTICS, handle_websocket_diagnostics, schema=vol.Schema({})
239215
)

0 commit comments

Comments
 (0)