Join OPNsense
with Home Assistant
!
hass-opnsense
uses the OPNsense
REST API) built-in xmlrpc
service to integrate OPNsense with Home Assistant. A plugin is currently required to be installed in OPNsense for this to work properly.
Initial development was done against OPNsense
21.7
and Home Assistant
2021.10
.
A Discord server to discuss the integration is available, please click the Discord badge at the beginning of the page for the invite link.
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
.
Use of the integration requires an OPNsense
plugin made available on mimugmail repository: https://www.routerperformance.net/opnsense-repo/
First, install the repository:
OPNsense
and issue the following commands:fetch -o /usr/local/etc/pkg/repos/mimugmail.conf https://www.routerperformance.net/mimugmail.conf
pkg update
Then, install the plugin. There are two ways to do it:
OPNsense
web UI, go to System:Firmware:Plugins and install plugin os-homeassistant-maxit
pkg install os-homeassistant-maxit
In Home Assistant
, add this repository to the HACS
installation or clone the directory manually.
In HACS, add this as a custom repository:
https://github.com/travisghansen/hass-opnsense . |
STEP 1 | STEP 2 |
---|---|---|
Then go to the HACS integrations page, search for OPNsense integration for Home Assistant
and install it by clicking on 3 dots on the right side and select Download and click on Download on popup window.
Once the integration is installed be sure to restart Home Assistant
. Restart option available under Developer tools.
Developer Tools Page | Restart Home Assistant Popup |
---|---|
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 it isn't in the list (well-known HA issue), do a 'hard-refresh' of the browser (ctrl-F5) then open the list again.
The official recommendation is that the service user to be created has the admin role.
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 push the file containing the API key and API secret to the browser. It will be in the download folder.
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
- if the SSL certificate should be verified or not (if receiving an SSL error, try unchecking this)API Key
- the API key created previouslyAPI Secret
- the API secret of the API keyFirewall Name
- a custom name to be used for entity
naming (default: use the OPNsense hostname
)Scan Interval (seconds)
- scan interval to use for state polling (default: 30
)Enable Device Tracker
- turn on the device tracker integration using OPNsense
ARP table (default: false
)Device Tracker Scan Interval (seconds)
- scan interval to use for ARP updates (default: 60
)Device Tracker Consider Home (seconds)
- seconds to wait until marking a device as not home after not being seen. (default: 0
)
0
- disabled (if device is not present during any given scan interval it is considered away)> 0
- generally should be a multiple of the configured scan intervalMany 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 it is probably there.
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
, uses a max age of 20 minutes for ARP entries (sysctl net.link.ether.inet.max_age
). This can be lowered in OPNsense from System -> Advanced -> System Tunables
if desired.
Also note that if AdGuardHome
is being used, DNS queries may get throttled causing issues with the tracker. See below for details.
Scan Interval (seconds)
config option))All of the switches below are disabled by default.
service: opnsense.close_notice
data:
# default is to clear all notices
# id: <some id>
service: opnsense.system_halt
service: opnsense.system_reboot
service: opnsense.start_service
data:
service_name: "dpinger"
service: opnsense.stop_service
data:
service_name: "dpinger"
service: opnsense.restart_service
data:
service_name: "dpinger"
# only_if_running: false
service: opnsense.send_wol
data:
interface: lan
mac: "B9:7B:A6:46:B3:8B"
service: opnsense.reload_interface
data:
interface: wan
service: opnsense.kill_states
data:
ip_address: 192.168.0.100
# Will optionally return the number of states dropped for each client
action: opnsense.generate_vouchers
data:
validity: "14400" # seconds
expirytime: "2419200" # seconds. 0 for never
count: 1
vouchergroup: Home Assistant
voucher_server: Voucher Server # Only needed if more than 1 Voucher Server
# Returns the vouchers as action response data
action response data
in an HA script or automationAs mentioned here using AdGuardHome can lead to problems with the plugin. Setting the Ratelimit in AdGuardHome to 0 will resolve this problem.