/home-assistant-custom-components-opnsense-ruleswitch

Public repo for custom component development

Primary LanguagePythonMIT LicenseMIT

opnsense ruleswitch

GitHub Release GitHub Activity License

pre-commit Black

hacs Project Maintenance BuyMeCoffee

Discord Community Forum

opnSense Rule Switch Component

This component is written to toggle opnSense firewall rules on (enabled) or off (disabled).
One my question why in the world would someone want to do this from HA. Simply put, I only use it to change the vpn use by my chromecast.

FORK from https://github.com/dgshue/home-assistant-custom-components and nagyrobi/home-assistant-custom-components-pfsense-ruleswitch Thanks for their work on that.

Pre-Reqs

Managed rules

With the new plugin on version 20.1.5 for the firewall API, it adds a new menu item under the "Firewall" section called "Automation" under that is the "Filter" and "Source NAT" menu items. You create your firewall rule under "Filter", then you need to get the UUID of this rule (I just looked at the config.xml Although there is a search parameter you can use with the API). Now, these firewall rules are above all other rules, even floating. (so the order of execution for the firewall rules goes: Automation->Floating->Interface)

The rules shown here are the one under the automation tab, not the normal rules.

This component will set up the following platforms.

Platform Description
switch Switch firewall rules on or off.

Installation

  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called opnsense_ruleswitch.
  4. Download all the files from the custom_components/opnsense_ruleswitch/ directory (folder) in this repository.
  5. Place the files you downloaded in the new directory (folder) you created.
  6. Restart Home Assistant
  7. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "opnsense ruleswitch"

The configuration shall be moved to use flow, in the mean time you need to add that to your configuration.yaml

switch:
  - platform: opnsense_rule
    host: https://192.168.1.1/api
    api_key: PFFA1sdfsdfkjied21
    access_token: AectmsfdfsdfdsfsfdsfdsdffdsbZEu6gzboxd5adUbbrejFZae1u5
    rule_filter: HomeAssistant

Configuration is done in the UI

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines

Credits

This project was generated from @oncleben31's Home Assistant Custom Component Cookiecutter template.

Code template was mainly taken from @Ludeeus's integration_blueprint template