[Custom component] AsusRouter integration

@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

:stuck_out_tongue: :loudspeaker:

image

2 Likes

0.19.0 :earth_africa: Port forwarding

2023-02-05

:octopus: GitHub change log ←

:lock: Requirements

  • Minimum Home Assistant version bumped to 2023.2.0

:rocket: Features

  • Finished code optimization to fulfil most of the HA Core requirements
  • Added Port forwarding features (feature request #136):
  • Added Media bridge mode (feature request #494):
    • The mode supports all the features of the Access point, but creates device trackers only for devices connected via wire

:books: Documentation

  • Added new Port forwarding documentation
  • Updated supported devices

:package: Dependencies

  • Bumped asusrouter library to 0.20.0

:hammer: Other changes

  • Refactored all the integration code

:open_book: Did you know?

  • In 7 days (next Sunday), it would be exactly 1 year since the first version of the AsusRouter backend library was released. Celebrating soon :stuck_out_tongue:
  • There are already 723 active AsusRouter installations as per HA Analytics
  • We already got 82 votes to add AsusRouter to HA Core

:coffee: Support AsusRouter

  • Do you want more features to be added to AsusRotuer? Some of the features require an additional testing device. You can help me in getting one → via Donate on Buy Me a Coffee service

Also:

2 Likes

I have an automation showing a notification when devices not in my whitelist reconnects. The notification includes IP, name, mac, connection_type and guest. Yesterday I suddenly got 3 notifications with ‘None’ as IP, ‘8C:86:1E:xx:xx:xx’ as name, ‘8C:86:1E:xx:xx:xx’ as MAC and guest as False. image

This got me startled for many reasons:

  1. I can’t remember anyone using an Apple device on my network ever (Google says 8C:86:1E is Apple).
  2. It was not connected to my guest network. All my visitors use the guest network.
  3. Why did it say None instead of showing IP and MAC address both as name and MAC? It was also not long enough on my network for me to actually see it being connected in router web page. Even though it notified me 3 times within an hour.

So… any ideas? :slight_smile:

Automation
alias: "Notify on reconnection to WiFi"
description: ""
trigger:
  - platform: event
    event_type: asusrouter_device_reconnected
  - platform: event
    event_type: asusrouter_device_connected
condition:
  - condition: template
    value_template: >-
      {% set allowlist = state_attr("sensor.asusrouter_allowlist", "list") %}

      {% set name = allowlist | selectattr('1', 'eq',
      trigger.event.data.mac.upper()) | map(attribute='0') | list | first |
      default(none) %}

      {{ name is none }}
action:
  - service: notify.persistent_notification
    data_template:
      message: >-
        {{trigger.event.data.ip}} | {{trigger.event.data.name}} |
        {{trigger.event.data.mac}} | {{trigger.event.data.connection_type}} | {%
        if trigger.event.data.guest == True %} Guest: Yes {% else %} Guest: No
        {% endif %} 
      title: A device has reconnected to WiFi
mode: queued
max: 100

Hey, @Quacked,

That’s strange, but here are a couple of things which I can explain from the AsusRouter point of view:

  • When the user provides no name for a device and the device itself gives no name, the name has the same value as mac - that is the feature of the library to avoid missing names and related issues.
  • Absence of the IP can be explained by the fact, the device did not really connect to the network - either did not provide the correct password or just did not finish auth process. This would explain why it only notified in AsusRouter but you did not actually see it in the connected devices list in the Web UI - that was hit and run only, not an actual connection.

Actually, if you live in some neighbourhood where your WiFi coverage extends your property, and your network is not hidden - that might happen - some devices like to scan available networks around in order to check whether they can be used before the user actually tries to connect.

I would say, that is the most convincing explanation. If the device would actually connect - it would obtain an IP address and would probably send its name - e.g. Apple sends at least iPhone/iPad and so as a generic name if not other set by the user.

But you might want to watch your network just in case.

Thank you. I assumed the event required an authenticated connection and not just an attempt of one. Is it possible to identify if it is actually able to connect so I can have a separate notification for that? I live in an apartment building and I guess there will be plenty of times where someone tries to login to my WiFi by mistake (I prefer not to hide SSID).

I saw a brief appearance of an unexpected MAC address recently. Discovered that it was for the wifi interface of a mesh node. Weird thing is that that node is connected to the main router by ethernet (wired) so I wouldn’t expect its wifi interface to try to connect to the main router.

@Quacked, actually it just notifies of any device, that the router has added to the list of connected. Why it does things in this way I don’t know. Actually, if you would be lucky, you would also see it in the Web UI - the source for data is the same as AsusRouter is using

You can update your automation to ignore devices without IP - that would avoid such cases as you had


@spry-salt,

Yes, AiMesh nodes are actually trying different connections from time to time. Especially if wired backhaul is 1 Gb/s and wireless can go faster

Hi there @SpicyLimes. Could you post the yaml for this setup? Thanks in advance!

@Vaskivskyi thank you for all your work on the integration!

I’ve had it working for 2 days, and then after rebooting my Home Assistant, I’m now getting errors on this only:

Logger: homeassistant.config_entries
Source: custom_components/asusrouter/bridge.py:459
Integration: AsusRouter (documentation, issues)
First occurred: 7:18:53 PM (3 occurrences)
Last logged: 7:21:22 PM

Error setting up entry 192.168.1.1 for asusrouter
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 26, in async_setup_entry
    await router.setup()
  File "/config/custom_components/asusrouter/router.py", line 748, in setup
    await self._init_sensor_coordinators()
  File "/config/custom_components/asusrouter/router.py", line 980, in _init_sensor_coordinators
    available_sensors = await self.bridge.async_get_available_sensors()
  File "/config/custom_components/asusrouter/bridge.py", line 241, in async_get_available_sensors
    SENSORS: await self._get_sensors_ports(),
  File "/config/custom_components/asusrouter/bridge.py", line 505, in _get_sensors_ports
    return await self._get_sensors(
  File "/config/custom_components/asusrouter/bridge.py", line 459, in _get_sensors
    data = await method()
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1223, in async_get_ports
    return await self.async_get_data(
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1120, in async_get_data
    await self.async_monitor(_monitor)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 443, in async_monitor
    result = process(raw, time=monitor.time)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 640, in _process_monitor_ethernet_ports
    data = raw["portSpeed"]
KeyError: 'portSpeed'

Some assistant would be amazing.

Many thanks.

Hey, @hk21x,

It seems, that one of the API endpoints (the one reporting LAN/WAN ports status) is not responding. That happens with some devices. You can try rebooting your router and then reloading integration - it should work again

Of course, this is not a fix, but a shortcut. I will fix the code producing the error and it will be released in the next integration update (sometime this weekend)

I am sorry that you are experiencing this issue

Rebooted. You’re a superstar - thank you.

1 Like