travisghansen / hass-opnsense

OPNsense integration with Home Assistant
194 stars 25 forks source link
hass hassio hassio-integration home-assistant home-automation opnsense opnsense-firewall

Build Status hacs_badge

hass-opnsense

Join OPNsense with Home Assistant!

hass-opnsense uses the built-in xmlrpc service and OPNsense REST API) to integrate OPNsense with Home Assistant. This project is currently a proof-of-concept and may fail to work at any time.

Initial development was done againt OPNsense 21.7 and Home Assistant 2021.10.

Overview

Installation

This integration currently 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 installation requires a plugin on OPNsense and a custom integration in Home Assistant.

OPNsense Plugin

To use the integration you need to install an OPNsense plugin made available on mimugmail repository: https://www.routerperformance.net/opnsense-repo/

First you need to install the repository:

fetch -o /usr/local/etc/pkg/repos/mimugmail.conf https://www.routerperformance.net/mimugmail.conf
pkg update

Now you need to install the plugin, you have two ways to do it:

HomeAssistant Integration

In Home Assistant, add this repository to your HACS installation or clone the directory manually.

HACS Installation

In HACS, add this as a custom repository: https://github.com/travisghansen/hass-opnsense then go to the HACS integrations page, search for OPNsense integration for Home Assistant and install it. Once the integration is installed be sure to restart Home Assistant.

Manual Installation

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

Configuration

Configuration is managed entirely from the UI using config_flow semantics. Simply go to Configuration -> Integrations -> Add Integration and search for OPNsense in the search box. If you can't find it in the list (well-known HA issue) you need to do a 'hard-refresh' of the browser (ctrl-F5) then open the list again, you'll find it there.

OPNsense

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

Config

Options

Entities

Many entities are created by hass-opnsense for stats etc. Due to to volume of entities many are disabled by default. If something is missing be sure to review the disabled entities as what you're looking for is probably there.

Binary Sensor

Device Tracker

ScannerEntity entries are created for the OPNsense arp table. Disabled by default. Not only is the feature disabled by default but created entities are currently disabled by default as well. Search the disabled entity list for the relevant mac addresses and enable as desired.

Note that by default FreeBSD/OPNsense use a max age of 20 minutes for arp entries (sysctl net.link.ether.inet.max_age). You may lower that using System -> Advanced -> System Tunables if desired.

Also note that if you are running AdGuardHome DNS queries may get throttled causing issues with the tracker. See #22 for details.

Sensor

Switch

All of the switches below are disabled by default.

Services

service: opnsense.close_notice
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  # default is to clear all notices
  # id: <some id>

service: opnsense.file_notice
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  notice: "hello world"

service: opnsense.system_halt
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present

service: opnsense.system_reboot
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present

service: opnsense.start_service
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  service_name: "dpinger"

service: opnsense.stop_service
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  service_name: "dpinger"

service: opnsense.restart_service
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  service_name: "dpinger"
  # only_if_running: false

service: opnsense.send_wol
data:
  entity_id: binary_sensor.opnsense_localdomain_pending_notices_present
  interface: lan
  mac: "B9:7B:A6:46:B3:8B"

Known Issues

AdGuardHome

As mentioned here using AdGuardHome can lead to problems with the plugin. Setting the Ratelimit in AdGuardHome to 0 will resolve this problem.