[Custom component] AsusRouter integration

No surprise but looks like this was a problem with my router. I tried to access the web interface and it wouldn’t connect. Rebooted it and back to working now. Keep up the great work!

This happens to my router from time to time… This is my second ASUS router and the previous one was even worse. It happens more frequently when I change settings, like adding new entries to the DHCP reservation table.

In the end I’ve set an automation to power cycle (cut power for 30s and then power on again, using a smart switch) the router when I don’t receive data on the integration for a certain time.

This is my automation:

alias: Media centre - Router - Recover when unavailable
description: ""
trigger:
  - id: Restart HTTP service
    platform: state
    entity_id:
      - sensor.router_cpu
      - sensor.router_boot_time
      - sensor.router_ram
      - update.router_firmware_update
    to:
      - unavailable
      - unknown
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - id: Reboot router
    platform: state
    entity_id:
      - sensor.router_cpu
      - sensor.router_boot_time
      - sensor.router_ram
      - update.router_firmware_update
    to:
      - unavailable
      - unknown
    for:
      hours: 0
      minutes: 15
      seconds: 0
  - id: Power cycle router
    platform: state
    entity_id:
      - sensor.router_cpu
      - sensor.router_boot_time
      - sensor.router_ram
      - update.router_firmware_update
    to:
      - unavailable
      - unknown
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition: []
action:
  - service: notify.signal_edward
    data:
      message: >-
        Router unavailable ({{ state_attr(trigger.entity_id, 'friendly_name') }}
        is {{ states(trigger.entity_id) }}).

        {{ trigger.id }}.
    continue_on_error: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - choose:
      - conditions:
          - condition: trigger
            id: Restart HTTP service
        sequence:
          - service: button.press
            data: {}
            target:
              entity_id: button.router_restart_http_daemon
      - conditions:
          - condition: trigger
            id: Reboot router
        sequence:
          - service: button.press
            data: {}
            target:
              entity_id: button.router_reboot
      - conditions:
          - condition: trigger
            id: Power cycle router
        sequence:
          - service: script.media_centre_router_power_cycle
            data: {}
mode: single

And this is the script called by the end (to power cycle the router):

alias: Media centre - Router - Power cycle
icon: mdi:router-wireless-off
mode: single
sequence:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.media_centre_power_strip_socket_1
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.media_centre_power_strip_socket_1
2 Likes

Hi All,

I see those errors sometimes pop up in HA log:

2022-12-27 09:32:02.547 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching wan data: None

2022-12-27 09:32:02.554 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching wlan data: None

2022-12-27 09:32:03.545 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching gwlan data: None

2022-12-27 09:32:03.558 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching parental_control data: None

2022-12-27 09:32:05.544 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching vpn data: None

Asus Router: GT AX 11000

Asus Integration: 0.16.0
Home Assistant 2022.12.8
Supervisor 2022.11.2
Operating System 9.4
Frontend 20221213.1 - latest

Hey, @poudenes,

Could you please check the full log, whether it shows any more info except for those error messages? They just mean the sensors were not able to update on the scheduled time. Since all 5 are at almost the same time, I suppose the integration got disconnected from the router.

  • Did sensors recover after the errors or did they stuck in some state?
  • Were there any more of the same errors afterwards?
  • Can you connect to your device via Web UI?

If all the sensors recovered, there might have been some random bug in the device API, so it did not reply for some time.
If not and your device can be accessed via Web UI, you would probably need to reload the integration and check whether it will be able to connect correctly.
If the Web UI cannot be reached, you will probably need to reboot your router.

Let me know, what you will find.


:hammer: About some cases of device_tracker entities being stuck home

I know about this issue and trying to solve it. Unfortunately, it is not easy to track:

  • it happens with some devices only
  • there is no correlation with the FW type or version
  • even though it happens more with Merlin, some devices with the stock FW also experience it

Soon enough, devices with newer FW (386+) will get the possibility to use another API endpoint for device tracking. Hopefully, this will help with the issue.

They are still updated. It’s sometimes it can’t get the info. There are no errors more than this.

the sensors are updating.

I’ve started seeing errors at startup, I’ve tried removing my custom switch definitions but the errors still occur. Any thoughts on what I’m missing greatly appreciated.

Log Details (ERROR)

This error originated from a custom integration.

Logger: custom_components.asusrouter.router
Source: helpers/update_coordinator.py:201
Integration: AsusRouter ([documentation](https://asusrouter.vaskivskyi.com/), [issues](https://github.com/Vaskivskyi/ha-asusrouter/issues))
First occurred: 18:56:08 (1 occurrences)
Last logged: 18:56:08

Error fetching gwlan data: ("Wrong value deny of type <class 'str'>", None)

and

Log Details (ERROR)

Logger: homeassistant.components.switch
Source: custom_components/asusrouter/entity.py:125
Integration: Switch ([documentation](https://www.home-assistant.io/integrations/switch), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+switch%22))
First occurred: 18:56:08 (2 occurrences)
Last logged: 18:56:09

* Error adding entities for domain switch with platform asusrouter
* Error while setting up asusrouter platform for switch

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 615, in _async_add_entity original_icon=entity.icon, File "/config/custom_components/asusrouter/entity.py", line 132, in icon if self.is_on: File "/config/custom_components/asusrouter/entity.py", line 125, in is_on return self.coordinator.data.get(self.entity_description.key) AttributeError: 'NoneType' object has no attribute 'get'

Can you please check, whether there is any more trace data in the full HA log? For the first error:

Error fetching gwlan data: ("Wrong value deny of type <class 'str'>", None)

I suppose, before getting such errors, you have changed some of the guest network settings?

Thank you, I’ll check when it next happens. There are a couple of guest networks, what settings might affect this?

Here is data from the full log, hopefully it’s helpful.

2022-12-29 00:42:43.508 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching gwlan data: ("Wrong value deny of type <class 'str'>", None)
2022-12-29 00:42:43.622 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.asusrouter
2022-12-29 00:42:43.658 ERROR (MainThread) [homeassistant.components.switch] Error adding entities for domain switch with platform asusrouter
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 615, in _async_add_entity
original_icon=entity.icon,
File "/config/custom_components/asusrouter/entity.py", line 132, in icon
if self.is_on:
File "/config/custom_components/asusrouter/entity.py", line 125, in is_on
return self.coordinator.data.get(self.entity_description.key)
AttributeError: 'NoneType' object has no attribute 'get'
2022-12-29 00:42:43.662 ERROR (MainThread) [homeassistant.components.switch] Error while setting up asusrouter platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 615, in _async_add_entity
original_icon=entity.icon,
File "/config/custom_components/asusrouter/entity.py", line 132, in icon
if self.is_on:
File "/config/custom_components/asusrouter/entity.py", line 125, in is_on
return self.coordinator.data.get(self.entity_description.key)
AttributeError: 'NoneType' object has no attribute 'get'

and

2022-12-29 02:52:43.848 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching wan data: None
2022-12-29 02:52:44.849 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching vpn data: None
2022-12-29 02:53:13.848 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching wlan data: None
2022-12-29 02:53:13.850 ERROR (MainThread) [custom_components.asusrouter.router] Error fetching parental_control data: None
2022-12-29 02:53:13.853 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{{ state_attr("switch.rt_ac86u_parental_control", "list") | list | count > 0 }}")' for attribute '_attr_available' in entity 'switch.internet_DEVICENAME'
2022-12-29 02:53:13.862 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{% set ns = namespace(
name = "DEVICENAME",
list = state_attr("switch.rt_ac86u_parental_control", "list"),
internet = true
) %} {# Find whether #} {% for element in ns.list %}
{% if element.name == ns.name and element.state == "block" %}
{% set ns.internet = false %}
{% endif %}
{% endfor %} {{ ns.internet }}")' for attribute '_state' in entity 'switch.internet_DEVICENAME'
2022-12-29 02:53:13.864 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{{ state_attr("switch.rt_ac86u_parental_control", "list") | list | count > 0 }}")' for attribute '_attr_available' in entity 'switch.internet_DEVICENAME2'
2022-12-29 02:53:13.865 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{% set ns = namespace(
name = "DEVICENAME2",
list = state_attr("switch.rt_ac86u_parental_control", "list"),
internet = true
) %} {# Find whether #} {% for element in ns.list %}
{% if element.name == ns.name and element.state == "block" %}
{% set ns.internet = false %}
{% endif %}
{% endfor %} {{ ns.internet }}")' for attribute '_state' in entity 'switch.internet_DEVICENAME2'

Thanks for the logs!

I have already found the issue. It will be fixed either today or tomorrow and I will publish a new release with the fix

:hammer_and_wrench:

1 Like

Thanks very much!

Sorry, there is a small delay with the release. But it will be ready before the end of the year :christmas_tree:

Too many distracting factors coming and going this time of the year

1 Like

0.16.1 :family_man_girl_boy: Guest WLAN bugfix

2022-12-31

:bug: Bug fixes

  • Fixed bug with the block by MAC settings of the Guest WLAN networks (report #C319)

:boom: Breaking

  • macmode attribute of Guest WLAN switches / binary sensors changed to string instead of boolean. More details on the possible values here

:package: Dependencies

  • Bumped asusrouter library to 0.15.2

:hatching_chick: Github / HACS

  • Updated the supported device list in GitHub Readme


:fireworks: 2022 results

2022 was full of achievements for AsusRouter. Even though it appeared only this year, the integration has already functionality covering most of the use cases for home routers.

And even more features and improvements are coming in 2023. Including the most-awaited support of AiMesh features. Stay tuned :tv:

Obviously enough, this is the last release of AsusRouter this year :slightly_smiling_face:

:christmas_tree: Happy New Year!


: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
6 Likes

Thanks for your continious support of this briliant integration! Have a nice newyears eve and all the good fortune for 2023.

1 Like

Thank you and happy new year!

This integration doesn’t produce the error messages at startup any more. However it still produces the error messages if the router stops responding (or maybe it’s if the dns service on the router stops running, because I’m using names to connect to local services not IP addresses).

For example today the log shows something bad happened. The nextdns service stopped running (don’t know why, there’s no logging info) and then a couple of minutes later the httpd service was restarted maybe by your integration?

Jan 1 14:10:22 service-event: /jffs/scripts/service-event restart httpd

I’ve increased the router logging level to see if I can get more info if it happens again. It’s happened several times in the past few weeks when nextdns stops working for no obvious reason, so I have a bash script that tries to restart it every 5 minutes. I don’t know if your integration and the nextdns service have some incompatibility?

Hey, AsusRouter by default is not pushing anything to the device, including anything connected to the running services. It can restart HTTP daemon, but only when you click the corresponding button button.{device}_restart_http_daemon.

From the integration point of view, it just connects to the device and asks for the status (for all the entity values). If a connection cannot be established, it will try once more. Only pressing buttons or switches is actually sending something to the device.

So whatever has happened to HTTPD - that is on the device itself.

Do you by any chance use Merlin 388.1? I have noticed problems with HTTPD on my RT-AX88U with the latest Merlin and an AiMesh device connected. The HTTP Daemon is regularly stucking, which causes problems with integration and also does not allow to access the Web UI of the router.

Thanks that’s a very helpful explanation. Mine is v386.7.2 but I do have a mesh configuration, maybe that’s a factor.

:loudspeaker: Announcement time

I think you were waiting for it

Spoiler

3 Likes

Awesome! Your work and this integration are very much appreciated. Thank you.

:loudspeaker: AsusRouter will support the new WiFi 7 routers

With the new RT-BE96U and GT-BE98 models announced, it’s also time for our announcement.

Regardless of the number of changes Asus will introduce to the FW of new devices, AsusRouter will support them as soon as enough data is available.

1 Like