Custom Component: Openwrt / OpenVPN

This component creates switches for the OpenVPN configurations that exist on your OpenWRT router. Activating a switche starts/stops the corresponding openvpn configuration on the router.
Requirements are the same as for the “luci” device tracker, i.e. luci-mod-rpc

source: https://gitlab.com/koying/ha_luci_openvpn

2 Likes

Thanks for this work :+1:

Works perfectly on OpenWrt 19.07.3

I have upgrade HA today and see this in log :

2021-04-09 22:17:54 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for ha_luci_openvpn doing I/O at custom_components/ha_luci_openvpn/__init__.py, line 134: self.routerRpc = OpenWrtRpc(
2021-04-09 22:17:54 ERROR (MainThread) [homeassistant.setup] Error during setup of component luci_openvpn
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 240, in _async_setup_component
    result = await task
  File "/config/custom_components/ha_luci_openvpn/__init__.py", line 72, in async_setup
    data = hass.data[DATA_KEY + "_" + p_config.get(CONF_HOST)] = LuciRPC(p_config)
  File "/config/custom_components/ha_luci_openvpn/__init__.py", line 134, in __init__
    self.routerRpc = OpenWrtRpc(
  File "/usr/local/lib/python3.8/site-packages/openwrt_luci_rpc/__init__.py", line 31, in __init__
    self.router = OpenWrtLuciRPC(host_url, username, password,
  File "/usr/local/lib/python3.8/site-packages/openwrt_luci_rpc/openwrt_luci_rpc.py", line 61, in __init__
    self._refresh_token()
  File "/usr/local/lib/python3.8/site-packages/openwrt_luci_rpc/openwrt_luci_rpc.py", line 69, in _refresh_token
    self.token = self._call_json_rpc(auth_url, 'login',
  File "/usr/local/lib/python3.8/site-packages/openwrt_luci_rpc/openwrt_luci_rpc.py", line 206, in _call_json_rpc
    res = self.session.post(url,
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1266, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 214, in putrequest
    return _HTTPConnection.putrequest(self, method, url, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 150, in protected_loop_func
    check_loop()
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 139, in check_loop
    raise RuntimeError(
RuntimeError: I/O must be done in the executor; Use `await hass.async_add_executor_job()` at custom_components/ha_luci_openvpn/__init__.py, line 134: self.routerRpc = OpenWrtRpc(

I don’t have skills to help…

have you planned to update the component ?

Thanks to this component :+1:

Updated on gitlab

1 Like

All is perfect :+1:

Thanks :heart:

Edit: Just realised that it does work despite the errors in the log! Not sure why they’re there but if it works, it works. Thank you!

This is exactly what I was looking for, thank you for putting this together!

I can’t seem to get it running, OS 2021.9.6, I get the following errors:

2021-09-12 21:17:20 ERROR (MainThread) [homeassistant.helpers.integration_platform] Unexpected error importing luci_openvpn/recorder.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 33, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 524, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 529, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.ha_luci_openvpn-master.recorder'
2021-09-12 21:17:20 ERROR (MainThread) [homeassistant.helpers.integration_platform] Unexpected error importing luci_openvpn/group.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 33, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 524, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 529, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.ha_luci_openvpn-master.group'
2021-09-12 21:17:20 ERROR (MainThread) [homeassistant.helpers.integration_platform] Unexpected error importing luci_openvpn/media_source.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 33, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 524, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 529, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.ha_luci_openvpn-master.media_source'
2021-09-12 21:17:20 ERROR (MainThread) [homeassistant.helpers.integration_platform] Unexpected error importing luci_openvpn/system_health.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 33, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 524, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 529, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.ha_luci_openvpn-master.system_health'
2021-09-12 21:17:20 ERROR (MainThread) [homeassistant.helpers.integration_platform] Unexpected error importing luci_openvpn/logbook.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 33, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 524, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 529, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.ha_luci_openvpn-master.logbook'

Im sort of new to HA, is this on me or does it need an update?

Since “SwitchDevice” is deprecated, renaming it to “SwitchEntity” in init.py fixes failed setup in Core Release 2022.2.0b0 · home-assistant/core · GitHub

from homeassistant.components.switch import (
DOMAIN,
SwitchEntity,

1 Like

Is there a chance that you may extend this to wireguard. unfortunately i am not a programmer
thanks

This is more-or-less deprecated.

See Chris Browet / ha_luci_config · GitLab for a generalization of the concept

Related: