[Custom component] AsusRouter integration

Thanks for the quick reply and the explaination.

Iā€™m checking my router temperatures, so i wonder, would it be possible to have mesh points temperatures shown in HA? Now only connection status is shown, and temperatures of main router. Checking mesh temps is not easy, since i must ssh into mesh and see temp with command.

Hello,

Getting temperature from the AiMesh nodes requires a direct connection to them. You can do it by just setting up one more AsusRouter instance with your node IP as host (username and password for all the nodes is the same as for the main AiMesh router). When setting up, select AiMesh node mode - it will only create sensors useful for nodes (including CPU, RAM, temperature monitoring), but will not create any duplicated device trackers and so on.

image

Ahhā€¦ so easy it is! And iā€™ve been already wondering where is above window with device mode selection (i searched, but didnā€™t find in my existing router settings), but i didnā€™t want to ā€œannoyā€ you with thatā€¦ now i see that itā€™s part of initial router addingā€¦ I didnā€™t add anything because HA found my mesh points by itself, but only connection status was created. Now all sensors are there.

So, itā€™s best to manually add each router/mesh i have in my networkā€¦

Many thanks for explanation!

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!