Code Monkey home page Code Monkey logo

homeassistant-vyos-router's Introduction

logo

hacs_badge License GitHub all releases

homeassistant-vyos-router

VyOS Rounter is a custom integration for Homeassistant which provides Presence detection as device_tracker functionality for VyOS Router. This integration uses direct HTTP-API from VyOS Router.

To use this integration you need to enable HTTP-API on your VyOS Router.

Installation

First enable HTTP-API on your VyOS Router.

HACS

Add this repository to your HACS installation, then install.

Manual

Download stable release contents from custom_components/vyos, then copy to your home assistant at /config/custom_components/vyos.

Once the integration is installed be sure to restart hass and hard-refresh the UI in the browser (ctrl-F5) if it doesn't appear in the list.

Usage

After VyOS Router is installed, you can add your device from Home Assistant UI.

Open your Home Assistant instance and start setting up a new integration.

To connect to the device you need to provide the following data:

  • url this include https:// protocol and port number :port, for instance https://192.168.1.1:11123
  • api_key the key that you set from VyOS doc MY-HTTPS-API-PLAINTEXT-KEY
  • version_dhcp_server config version of dhcp-server, on vyos-1.4 or lower that doesn't use kea dhcp server, this value is typcally 7. If you're running vyos-1.5 and above with kea, you can use any number higher than 7. If you wish to know your exact number, you could use this command cat /config/config.boot | grep -Eo 'dhcp-server@[0-9]*'
  • verify_ssl whether to use an SSL connection
  • tracker_interfaces this is optional, you can use comma , to specify multiple interface, for example eth0,eth1,wlan0. If you leave it empty, it'll use all interfaces.
  • detection_time How long before considered away or at home in seconds.

After configured the integration, the device entities will be disabled by default. Find the required mac addresses using the disabled entity list, then activate them as needed.

Support

Issues and Pull requests

If you have discovered a problem with the integration or simply want to request a new feature, please create a new issue.

You may also submit pull requests to the repository.

homeassistant-vyos-router's People

Stargazers

 avatar  avatar

Watchers

 avatar

homeassistant-vyos-router's Issues

Presence detection buggy if the ip address is not defined inside `static-mapping`

When ip of the static mapping wasn't defined, only the mac address is defined, the presence detection doesn't work.

While at home, it occasionally reports as at home.
While not home, it always reports as not home.

# set service dhcp-server shared-network-name LAN subnet XXX.XXX.XXX.XXX/XX static-mapping example-1 ip-address 'XXX.XXX.XXX.XXX'
set service dhcp-server shared-network-name LAN subnet XXX.XXX.XXX.XXX/XX static-mapping example-1 mac 'xx:xx:xx:xx:xx:xx'

400 Bad Request

Hi,

I just installed the component, and have it now communicating, to some degree, with the router. The router is in this case 192.168.86.111 and the port is 443
How ever, it is now repeating the following:

`2024-01-23 15:55:43.260 ERROR (MainThread) [custom_components.vyos.router] Unexpected error fetching VyOS - https://192.168.86.111:443 data: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:55:43 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/vyos/router.py", line 203, in _async_update_data
await self.vyos_data.update_devices()
File "/config/custom_components/vyos/router.py", line 134, in update_devices
await static_mapping_co_routine
File "/config/custom_components/vyos/vyosapi.py", line 316, in get_config
raise VyOSApiError(res)
custom_components.vyos.vyosapi.VyOSApiError: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:55:43 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
2024-01-23 15:56:00.925 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py:423: RuntimeWarning: coroutine 'VyOSApi.get_dhcp_lease' was never awaited
self.headers: CIMultiDict[str] = CIMultiDict()
2024-01-23 15:56:00.926 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py:423: RuntimeWarning: coroutine 'VyOSApi.get_present_arp_clients' was never awaited
self.headers: CIMultiDict[str] = CIMultiDict()
2024-01-23 15:57:05.199 ERROR (MainThread) [custom_components.vyos.router] Unexpected error fetching VyOS - https://192.168.86.111:443 data: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:57:05 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/vyos/router.py", line 203, in _async_update_data
await self.vyos_data.update_devices()
File "/config/custom_components/vyos/router.py", line 134, in update_devices
await static_mapping_co_routine
File "/config/custom_components/vyos/vyosapi.py", line 316, in get_config
raise VyOSApiError(res)
custom_components.vyos.vyosapi.VyOSApiError: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:57:05 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
2024-01-23 15:58:08.160 WARNING (Recorder) [py.warnings] <string>:21: RuntimeWarning: coroutine 'VyOSApi.get_dhcp_lease' was never awaited
2024-01-23 15:58:08.161 WARNING (Recorder) [py.warnings] <string>:21: RuntimeWarning: coroutine 'VyOSApi.get_present_arp_clients' was never awaited
2024-01-23 15:58:27.130 ERROR (MainThread) [custom_components.vyos.router] Unexpected error fetching VyOS - https://192.168.86.111:443 data: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:58:27 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/vyos/router.py", line 203, in _async_update_data
await self.vyos_data.update_devices()
File "/config/custom_components/vyos/router.py", line 134, in update_devices
await static_mapping_co_routine
File "/config/custom_components/vyos/vyosapi.py", line 316, in get_config
raise VyOSApiError(res)
custom_components.vyos.vyosapi.VyOSApiError: <ClientResponse(https://192.168.86.111:443/retrieve) [400 Bad Request]>
<CIMultiDictProxy('Server': 'nginx/1.22.1', 'Date': 'Tue, 23 Jan 2024 13:58:27 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '90', 'Connection': 'keep-alive')>
2024-01-23 15:58:28.425 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.11/asyncio/base_events.py:436: RuntimeWarning: coroutine 'VyOSApi.get_dhcp_lease' was never awaited
task = tasks.Task(coro, loop=self, name=name, context=context)
2024-01-23 15:58:28.425 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.11/asyncio/base_events.py:436: RuntimeWarning: coroutine 'VyOSApi.get_present_arp_clients' was never awaited
task = tasks.Task(coro, loop=self, name=name, context=context)

All entities are not_home

Hello again!

My setup:
Vyos 1.3.5
HomeAssistant 2024.1.6

Vyos integration successfully connected and received ip and mac of devices from the local network, but all of them have status 'not_home'.

What I need to provide for diagnostic this issue?

Handle cloned mac addresses.

In normal network it is possible to have devices with the same mac address connected to the network.

For instance, when using an WiFi AP, each devices will get the correct IP address according to their mac address.
But in the arp table, the same mac address (i.e. WiFi AP mac address) could be corresponded to multiple ip address.

In short, arp table could tell if an ip address is connected, but it can't be trusted with providing mac address.

My proposal is,

  1. Get ip from mac address static mapping.
  2. Get ip and mac address from lease table.
  3. Get the connectivity from only ip address from arp table.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.