Skip to content
Proyek

Tentang

Integrasi OPNsense dengan Home Assistant.

Proyek lainnya

Cara angka ini diukur

479 bintang34 Fork +2 dalam 24 jam

Pertumbuhan bintang terukur

dalam 24 jam
+2
dalam 7 hari
+2
dalam 15 hari
+4
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

GitHub Downloads GitHub Latest Downloads GitHub Release GitHub Release Date GitHub Activity Coverage License hacs discord

hass-opnsense

Join OPNsense with Home Assistant!

hass-opnsense uses aiopnsense as the backend client library to integrate OPNsense with Home Assistant.

Source and releases for aiopnsense:

A Discord server to discuss the integration is available. Click the Discord badge at the beginning of the page for the invite link.

OPNsense Firmware Requirements

  • Requires OPNsense Firmware 25.1+
  • For OPNsense Firmware 25.1 through 26.1.0, the integration remains supported, but Firewall and NAT rule switches are not available.
  • With OPNsense Firmware 26.1.1+, Firewall and NAT rule switches are available as well.

Table of Contents

Installation

This integration replaces the built-in OPNsense integration which only provides device_tracker functionality. Be sure to remove any associated configuration for the built-in integration before installing this replacement.

The deprecated OPNsense Home Assistant plugin is no longer supported or used by hass-opnsense.

In HACS, add this as a custom repository: https://github.com/travisghansen/hass-opnsense.

STEP 1 STEP 2
image image

Then go to the HACS integrations page, search for OPNsense integration for Home Assistant and install it by clicking on the 3 dots on the right side, selecting Download, and clicking Download on the popup window.

image

image

Once the integration is installed, be sure to restart Home Assistant. Restart option available under Developer tools.

Developer Tools Page Restart Home Assistant Popup
image image

Manual Installation

Copy the contents of the custom_components folder to the Home Assistant config/custom_components folder and restart Home Assistant.

Configuration

Configuration is managed entirely from the Home Assistant UI. Simply go to Configuration -> Integrations -> Add Integration and search for OPNsense in the search box.

Firewall Entry

Choose Firewall entry to add a Firewall entry for each Node's own non-VIP IP address or hostname. This is the full integration: telemetry, interfaces, services, gateways, firmware, optional CARP data, actions, and switches follow the selected sync options. Existing entries remain Firewall entries automatically and require no migration.

CARP VIP Entry

Choose CARP VIP entry for the shared CARP VIP IP address or hostname when you want read-only CARP visibility. A CARP VIP entry follows the active responder and exposes only the CARP entities described in CARP VIP Entities and Limitations. Configure each physical node separately with a Firewall entry; the CARP VIP entry does not replace Firewall entries.

Recommended CARP Topology

Use one Firewall entry per physical node and add the optional CARP VIP entry for the shared endpoint:

Node A non-VIP IP/hostname       -> full Firewall entry
Node B non-VIP IP/hostname       -> full Firewall entry
Shared CARP VIP IP/hostname      -> optional read-only CARP VIP entry

Firewall entries are required for complete monitoring because a VIP endpoint cannot prove the health of a standby node.

OPNsense User

The official and simplest recommendation is that the service user to be created has the admin role.

In OPNsense, create a new admin role user (or choose an existing admin user) and create an API key associated to the user. When creating the API key, OPNsense will download the file containing the API key and API secret to the computer. It will be in the download folder.

Granular Sync

Either at the time of install or in the integration options, Granular Sync can be enabled. There, choose the categories to sync with HA as desired. If enabled, the OPNsense user can have more narrow permissions.

At minimum, the following permissions are required:

  • Lobby: Dashboard
  • Status: Interfaces
  • System: Firmware

The list of what other permissions are needed for the Granular Sync Options and for the Actions can be reviewed here.

VPN Status Access provides sensors for instances visible in live status. Configuration Access adds the configured inventory and switches. See VPN permissions for the privileges to grant for each VPN type.

Basic Configuration

Option Required Default Description
URL ✅ The full URL to the OPNsense UI (ie: https://192.168.1.1). Supported format is <scheme>://<ip or host>[:<port>]
Verify SSL Certificate True If the SSL certificate should be verified or not (if receiving an SSL error, try unchecking this)
API Key ✅ The API key of the OPNsense user created previously
API Secret ✅ The API secret of the API key
Firewall Name Uses the OPNsense hostname A custom name to be used for device and entity naming
Enable Granular Sync Options False See Granular Sync Options

Options

Option Default Description
Scan Interval (seconds) 30 Scan interval to use for state polling
Device Tracker Mode Disabled • Disabled
• Track all detected clients
• Track only selected clients
Device Tracker Scan Interval (seconds) 150 Scan interval to use for Neighbor entry (ARP and NDP) updates
Device Tracker Consider Home (seconds) 0 Seconds to wait until marking a Tracked client as Away after no Presence evidence is found:
• 0 : Disabled (if a Tracked client has no Presence evidence during any given scan interval it is considered Away)
• > 0 : Should be a multiple of the Device Tracker Scan Interval
Enable Granular Sync Options False See Granular Sync Options

Entities

Many entities are created by hass-opnsense for statistics etc. Due to the volume of entities, many are disabled by default. If something is missing, be sure to review the disabled entities as it is probably there.

Binary Sensor

  • System Notices present (the circle icon in the upper right of the UI)
  • Firmware updates available

Sensor

  • System details (name, version, temp, boot time, etc.)
  • pfstate details
  • CPU details (usage, load, cores)
  • mbuf details
  • Memory details
  • Filesystem usage
  • Interface details (status, stats, pps, kbs, etc.) [speeds are based on the Scan Interval (seconds) config option]
  • Gateways details (status, delay, stddev, loss, address)
  • CARP VIP status (aggregate)
  • CARP Interface status
  • DHCP Leases. Under Status Access, the Replacement repair keeps registered DHCP lease sensors for interfaces missing from the lease data.
  • OpenVPN and Wireguard server and client stats
  • IPsec phase 1 (IKE) connection status and traffic counters
  • IPsec phase 2 (child SA) status with configured and negotiated traffic selectors, and traffic counters
  • Certificates
  • vnStat Metrics
  • Speedtest last and average results (download, upload, latency)
  • Unbound DNS Query Stats (queries, Blocked and Dropped per minute and over 24 hours, Blocked share, blocklist size, top domains, recently Blocked queries) [all disabled by default; polled every 60 seconds once enabled; needs Unbound statistics enabled in OPNsense]

Switch

All switches are disabled by default

  • Firewall Rules - enable/disable rules (requires OPNsense Firmware 26.1.1+)
  • NAT Rules - enable/disable rules (requires OPNsense Firmware 26.1.1+)
  • Services - start/stop services
  • VPN Servers and Clients - enable/disable instances
  • IPsec Connections - enable/disable connections
  • Unbound blocklists - enable/disable blocklists

Device Tracker

Entities are created for Tracked clients (machines on the network, identified by MAC address) to show whether they are connected to the network. This feature is disabled by default and can be enabled in the Options once the integration is installed.

The options flow supports three modes:

  • Disabled
  • Track all detected clients
  • Track only selected clients

The selectable client list is built from the Firewall's current ARP and NDP Neighbor entries, so only recently seen clients appear automatically. Clients that are not currently visible can still be added manually by MAC address.

See Device Tracker Guide for setup details, ARP and NDP behavior, and troubleshooting.

CARP VIP Entities and Limitations

A CARP VIP entry creates only these read-only entities:

  • active responder: the name of the Node currently answering through the VIP;
  • CARP VIP status: aggregate CARP status reported by that active responder;
  • CARP VIP state: one state sensor for each virtual IP keyed by VHID and subnet.

A CARP VIP entry does not expose node hardware telemetry, firmware/update entities, general interfaces, services, gateways, VPN, DHCP, firewall/NAT, SMART, disks, temperatures, device trackers, actions, or switches. The VIP cannot prove standby-node health; configure a Firewall entry for each Node when complete monitoring is required.

The persistent CARP maintenance switch remains on Firewall entries. Enabling maintenance through the VIP can move the VIP; a later disable request could then reach the other Node. Use the Node's own Firewall entry when changing maintenance mode.

DNS Query Stats privacy

The DNS Recently Blocked sensor and opnsense.get_dns_queries include client names (usually DHCP host names) and the domains they queried. Attributes of the DNS Recently Blocked and top-domain sensors are not recorded in history. Diagnostics mask these clients and domains.

Actions (Services)

  • opnsense.close_notice: Close any open notices
  • opnsense.system_halt: Halt the OPNsense system
  • opnsense.system_reboot: Reboot the OPNsense system
  • opnsense.start_service: Start an OPNsense service
  • opnsense.stop_service: Stop an OPNsense service
  • opnsense.restart_service: Restart an OPNsense service
  • opnsense.send_wol: Send a Wake-on-LAN magic packet
  • opnsense.reload_interface: Reload an OPNsense interface
  • opnsense.kill_states: Kill all states for an IP address
  • opnsense.run_speedtest: Run a speed test and return action response data
  • opnsense.get_vnstat_metrics: Get vnStat metrics and return action response data
  • opnsense.get_dns_queries: Get recent Unbound DNS queries, filtered by action, client or search text, and return action response data (the Firewall keeps its last 1,000 queries)
  • opnsense.generate_vouchers: Generate Captive Portal vouchers
  • opnsense.toggle_alias: Toggle, enable, or disable an alias
  • opnsense.toggle_interface: Toggle, enable, or disable an interface (OPNsense 26.7.6+)

How to use action response data in an HA script or automation

Replacing OPNsense Hardware

Hardware replacement may change a number of OPNsense areas including interfaces, services, gateways, disks, and others.

When a Firewall entry reports a Hardware ID mismatch, Home Assistant offers a fixable repair (the Replacement repair). Confirm it once the replacement hardware is reachable and is the intended Node. The repair selectively reconciles the registry with the replacement's entities: matching entities and devices retain their registry identity and customizations, entities absent from the replacement are removed, and new entities are created.

The repair preserves the URL, credentials, and options. A retry marker makes an interrupted repair resumable. Dashboards and automations remain intact for preserved entity IDs; review references to entities removed during reconciliation.

If Speedtest results cannot be read, the repair keeps existing Speedtest registry entries and reconciles the other readable entities. The kept sensors stay unavailable until the integration is reloaded after the results can be read again. If the Firewall confirms the Speedtest plugin is missing, the repair removes its sensors.

Contributing

Contributions are welcome. See CONTRIBUTING.md for the development setup and pull request process, CODING_STANDARDS.md for the code and test standards, and GLOSSARY.md for the terms used in this project.

Jelajahi proyek terkait

Memuat…