[Custom component] AsusRouter integration

That was actually a choice of mine. The AiMesh status is available from the main router, but in order to create an entity for each node - it was better to create an actual device - so the user will know - this entity is not from the main router. But for all the other sensors, one separate connection should be established. I decided not to go with the automatic “let’s connect to each node for the full set of sensors” - some users might not want this and would prefer avoiding useless network traffic.

But in future I am planning on some improvements on this part as well - e.g. a discovery of nodes - which will give users the possibility to add a node with a single (or a couple of) clicks without a need to provide a username/password again

1 Like

0.18.2 :beetle: Improvements and fixes

2023-01-28

:octopus: GitHub change log ←

:rocket: Features

  • Added fallback API endpoint for connected devices data on x.380.x FW builds
  • Improved data processing for LAN/WAN ports
  • Improved calculation of usage data (CPU, network, RAM and other sensors)
  • Improved device reboot handling

:bug: Bug fixes

  • Fixed LED blinking loop on device reboot
  • Fixed bug with the button module
  • Fixed bug with CPU and network sensors stucking in an unknown state in some cases
  • Fixed bug with partial parental control rules
  • Fixed behaviour on connection errors

:books: Documentation

  • Added links to GitHub release logs for all the documented releases
  • Small cosmetic changes

:package: Dependencies


0.18.3 :bug: A bugfix

2023-01-29

:octopus: GitHub change log ←

:bug: Bug fixes

  • Fixed bug in parental control module

:package: Dependencies

  • Bumped asusrouter library to 0.19.7

:medal_sports: Achivements


:coffee: Support AsusRouter

Monetary support:

  • You can make a donation using the Buy Me a Coffee service
  • Thinking of buying a new Asus router to use with AsusRouter integration? Check the compatibility list in our Docs. If you will use any of the Amazon Associate links, I might get a small (1-3%) bonus from Amazon (usage of the associate links does not change the price of the items for you)

Non-monetary support:

  • Star AsusRouter repository
  • Know a person with an Asus device using Home Assistant but not AsusRouter? Let them know, AsusRouter is cool and has lots of useful features
3 Likes

I just noticed a “gimmick” in my RT-AX68U … is this something you will look at ?
router_ports

@boheme61,

This is a feature of the new 388 FW builds. Actually, the backend library of AsusRouter already supports it. But I did not yet add the new features to the integration. Soon :slightly_smiling_face:

1 Like

ok, so im not totally messed up in my head :slight_smile: … i was wondering when that “appeared” , or whether i just haven’t noticed it before :laughing: … is no hurry, And relax and enjoy your weekend(s)

0.18.3 :bug: A bugfix

is released with a bugfix for the parental control module. The change log is updated up there

1 Like

First of all, thank you for amazing integration!

Are there any plans to support VPN Director rules via the integration? I am trying to achieve “automatic VPN” for certain streaming services and it does work, but switching openvpn on/off is bit slow and delay is very noticeable.

Keeping openvpn tunnels open and just modifying VPN Director rules on the fly could be more than efficient way to control VPN routing on per device basis dynamically.

Just to give you an idea, now I am monitoring Chromecast or Android TV “app_name” attribute changes, if app_name contains “BBC” or “ITVX” automation will switch on the UK VPN tunnel and as VPN Director has these devices routing adjusted, it will direct the Android TV/Chromecast traffic via UK VPN tunnel as expected. Only problem with this approach is 30-45 seconds delay, perhaps due to creation of the tunnel?

Would be extremely cool to dynamically change the routing rules based on apps running on a device basis :wink:

Edit: as there seems to be no API for VPN Director, ssh could do the trick: More Easily Enable/Disable VPN Director Rule | SmallNetBuilder Forums

Edit 2: Can confirm that modifying VPN Director rules via SSH works much faster! It’s a shame SSH from HA to external devices is a hassle as it will definitely keep some users away from this setup. @Vaskivskyi any ideas if the ssh command part or built-in feature to manage VPN Director could be possible to bake in?

Hi @Vaskivskyi,

First off, thank you for working on this great custom integration!

Now… support for RT-AX86U (running Merlin 388.1) seems to be broken for me since upgrading to 0.18.0. When I downgrade back to 0.17.4, everything works/connects fine, but upgrading to 0.18.0/0.18.1/0.18.2/018.3 seems to ALWAYS break this integration’s ability to connect to my router. Was there just a breaking change somewhere that I missed, or is something else going on here? Screenshot below from my Devices & Services page, and paste of error below that. Oh also, I’m running the latest version of Hassio in KVM if that helps.

This error originated from a custom integration.

Logger: homeassistant.config_entries
Source: custom_components/asusrouter/bridge.py:145
Integration: AsusRouter (documentation, issues)
First occurred: 8:59:48 AM (1 occurrences)
Last logged: 8:59:48 AM

Error setting up entry 192.168.1.1 for asusrouter
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 183, in async_request
    json_body = await reply.json()
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 52, in json
    return await super().json(*args, loads=loads, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1119, in json
    return loads(stripped.decode(encoding))
orjson.JSONDecodeError: byte order mark (BOM) is not supported: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 101, in async_run_command
    result = await self.async_request(command, endpoint, self._headers)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 229, in async_request
    json_body = parsers.xml(text=string_body)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/util/parsers.py", line 483, in xml
    data = xmltodict.parse(text)
  File "/usr/local/lib/python3.10/site-packages/xmltodict.py", line 327, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 60, column 19

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 183, in async_request
    json_body = await reply.json()
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 52, in json
    return await super().json(*args, loads=loads, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1119, in json
    return loads(stripped.decode(encoding))
orjson.JSONDecodeError: byte order mark (BOM) is not supported: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/asusrouter/__init__.py", line 30, in async_setup_entry
    await router.setup()
  File "/config/custom_components/asusrouter/router.py", line 609, in setup
    await self.bridge.async_connect()
  File "/config/custom_components/asusrouter/bridge.py", line 145, in async_connect
    await self.api.async_connect()
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 251, in async_connect
    await self.async_identify()
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 344, in async_identify
    ] = await self.async_check_endpoint(address)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 238, in async_check_endpoint
    await self.async_api_load(endpoint)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 400, in async_api_load
    raise ex
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 393, in async_api_load
    result = await self.connection.async_run_command(
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 113, in async_run_command
    return await self.async_run_command(command, endpoint, retry=True)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 114, in async_run_command
    raise ex
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 101, in async_run_command
    result = await self.async_request(command, endpoint, self._headers)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/connection.py", line 229, in async_request
    json_body = parsers.xml(text=string_body)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/util/parsers.py", line 483, in xml
    data = xmltodict.parse(text)
  File "/usr/local/lib/python3.10/site-packages/xmltodict.py", line 327, in parse
    parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 60, column 19

@rg3d, hi! Sorry to hear, that something does not work well for you. I will use your logs to find and eliminate the bug. I will let you know if any more info is needed from you


@lazmo88, hi! I will check whether VPN Director can be controlled using the API, but cannot guarantee anything yet

2 Likes

Any possibility to monitor the daily upload/download? The wan upload/download sensors seems to keep track of the total upload/download.

@h3llrais3r,

Yes, the sensors in integration are cumulative - the value increases unless reset (reset happens at reboot or if the value overflows some maximum value).

You can use the in-build HA Utility meter for this. Just set the reset cycle to 1 day and it will be calculating everything properly for a single day.

@Vaskivskyi Thanks for the feedback. I already had a hourly utility meter setup for the original asuswrt integration. But maybe I thought that this one could have the daily sensor built in… as it’s also available in the UI of the asus interface. But no problem. Will setup the daily utility meter for it. Thanks for your work!

1 Like

Hey, @rg3d. It seems like we will need additional testing since there is some issue with the data obtained from your device that causes the errors. Do you mind opening an issue on GitHub, so it would be easier to track what’s happening?

@Vaskivskyi FYI after update to HA 2023.2 I get this warning

Detected integration that called async_setup_platforms instead of awaiting async_forward_entry_setups; this will fail in version 2023.3. Please report issue to the custom integration author for asusrouter using this method at custom_components/asusrouter/init.py, line 48: hass.config_entries.async_setup_platforms(entry, PLATFORMS)

@sesame26, hey. Thanks for your report. This will be fixed as soon as possible

I’ll try to get an issue added ASAP. Thank you!

0.18.4 :lock: Improvement for HA 2023.2.x

2023-02-03

:octopus: GitHub change log ←open in new window

:bug: Bug fixes

  • Fixed warning on HA 2023.2.x

:books: Documentation


:coffee: Support AsusRouter


:star: Vote to add AsusRouter as native Home Assistant integration

2 Likes

Sorry for the very noob question. Is there a way to display the latest devices connected (preferably) with ip address or device name on lovelace card?

Hey, @Tismo,

Yes, you can do it using e.g. flex-table-card. In this example, the data is sorted by the connection time attribute (by the hidden 1 column)

Code
type: entities
entities:
  - type: custom:text-divider-row
    text: Last 5 Connected Devices
    align: left
    card_mod:
      style: |
        h2.text-divider span {
          background: #1A1A1A;
        }
        :host {
           height: 0px;
         }
  - type: custom:flex-table-card
    sort_by:
      - list-
    entities:
      include: sensor.rt_ax88u_latest_connected
    columns:
      - data: list
        modify: x.connected
        hidden: true
      - data: list
        name: ' Device Name'
        icon: mdi:devices
        modify: x.name
      - data: list
        name: ' Address'
        icon: mdi:ip-network
        modify: x.ip
      - data: list
        name: ' Type'
        icon: mdi:wifi-arrow-up-down
        modify: x.connection_type
      - data: list
        name: ' Time'
        icon: mdi:clock
        modify: |
          var date = (new Date(x.connected)).toJSON();
          var dateRegex = /^([\d-]{10})T.*$/
          var dateData = dateRegex.exec(date);
          var timeRegex = /^.*T([\d:]{8}).*$/
          var timeData = timeRegex.exec(date);

          dateData[1]+" "+timeData[1]
    card_mod:
      style: |
        ha-card {
          background: none;
          padding: 0px;
          spacing: 0px;
        }
Image

image

2 Likes

Thank you so much for your hard work on the integration and your support.

1 Like