[Custom component] AsusRouter integration

I couldn’t find any pattern and yes, the sensors recovers by itself (or at least I couldn’t notice anything with the data).
I’ve restarted my HA yesterday at around 23:45 and until now (around 08:15AM) I don’t have any instance of this error.
I will keep my eyes on this and let you know if I get any new useful info.

1 Like

@Quacked,

guest and connection_type attributes are coming to the device-related events and to the connected_devices sensor in the next release.

Snapshots

image
image


Version 0.12.0 of AsusRouter is expected as soon as I manage to get internet access control per device (block / allow internet connection for a single device) :slightly_smiling_face: But that’s a classified development yet :laughing:


Don’t forget about our new documentation: Home | AsusRouter (vaskivskyi.com) - regularly updated and improved.

Want to support and speed up the development of AsusRouter? Some features require an additional device for tests - you can help with that on BuyMeACoffee.

1 Like

Nice to see the “roadmap”… :slight_smile:

By the way, I have one wish for a future version (or perhaps you have some idea to help me)…
The point is that my router sometimes gets into a non-responsive mode where it stops responding to the web interface (and the Asus app) and also stops updating the sensors on the AsusRouter integration on Home Assistant. This happened a lot to my old router but happened at least once to my new one. On the old one it was easy to me to force into this mode as it happened every time when I add some new device to the DHCP reservation table (I have almost 80 devices listed there today). The new router is not freezing when I play with DHCP table, but still happening with some other cause that is unknown for me right now.
I know I should invest more time trying to investigate this and involve Asus on this, but meanwhile I’d like a way to detect when this happens, so I can power-cycle the router (I’ve a zigbee switch powering my router).

Any ideas?

I think you should be able to use HA automation easily in this case. Just need to find the best trigger.

If all the sensors are stuck with the last known value and do not update, you can try a trigger for any fast-changing state for 5+ minutes (e.g. on the CPU sensor - this one is jumping all the time).

5 min state trigger
trigger:
  - platform: state
    entity_id:
      - sensor.rt_ax88u_cpu
    for:
      hours: 0
      minutes: 5
      seconds: 0

If any sensor becomes unavailable or unknown, you can trigger on this value only. Just do it after at least 2 attempts to update the entity (2+ time intervals for the sensor) - so it won’t be triggered accidentally by a single communication error.

My automation example when some router endpoints crash
alias: RT-AX88U/HTTPD
description: Restart RT-AX88U HTTP daemon when endpoints stop responding
trigger:
  - platform: state
    entity_id:
      - sensor.rt_ax88u_lan_speed
    to: unknown
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - device_id: 56f5591ce56830aca6d783f145197121
    domain: button
    entity_id: button.rt_ax88u_restart_http_daemon
    type: press
mode: single

The first option is, of course, more resource-consuming - automation will be triggered on any change of the state.

1 Like

Morning All - New to HA and New to this integration. Curious on a specific piece of functionality tho:

I have an Asus ZenWifi Ax mesh system:
within the android app I am able to set up family profiles for my kids and link their individual devices to their profiles (computers, tablets, phones, oculus quests).

I use these profiles to automate shutting off internet access during school nights (works great).

During the weekend on occasion we shut off internet access here and there to force them to play outside, clean their rooms, have family dinner etc… since these are ‘on-demand’ I currently would have to load the android app, navigate to their profile and choose to block the internet.

This is a bit complicated for my wife, so when I’m not around she’s kind of stuck.

I have HA loaded onto a wall mounted tablet in my bedroom - would be awesome if I could create a button for each child or family profile and choose to block or restore internet for that child/profile.

Totally unsure if this is possible in the current state of the integration or not. I guess it would be fine even if I had to create a button for each device if there is no integration to the router family profiles.

Anyone have any insight into how I might be able to accomplish this?

With the current integration you certainly could have a button to shut down your Wi-Fi entirely, but this will affect all your devices, including your tablet with your HA dashboard.
You can always have a Wi-Fi network for Parents, another one for your IoT devices, and one for the kids, so you will have plenty of control… this is all supported by your router, and you will be able to control all of this (turn-on/turn-off the individual networks) from Home Assistant.

And looks like v0.12.0 will give you more control for each device connected to your network, but this is still classified info, so you will have to talk to @Vaskivskyi. He is the only one who knows about future here… :smiley:

Separate networks is a great idea… tons of work to implement though; having over 100 devices. Thanks for the idea, certainly something to consider.

@Vaskivskyi I understand 0.12.0 is classified, but any thoughts on about when it would be made available? Trying to weigh out whether I should implement separate networks as suggested or wait for the next release which will give me what I’m looking for here without having to change around my network infrastructure.

So was digging through the documentation and found this: Parental control | AsusRouter

Looks like there supposedly IS a “device_internet_access service”. I tried setting up a button for a device in lovelace (reference type:button section at the bottom):

type: entities
entities:
  - entity: device_tracker.test_device
  - type: divider
  - type: attribute
    entity: device_tracker.test_device
    attribute: ip
    name: IP
  - type: attribute
    entity: device_tracker.test_device
    attribute: mac
    name: MAC
  - type: attribute
    entity: device_tracker.test_device
    attribute: internet_mode
    name: Internet Access
  - type: attribute
    entity: device_tracker.test_device
    attribute: last_activity
    name: Last Activity
  - type: divider
  - type: button
    icon: mdi:power
    name: Control Access
    action_name: state
    tap_action:
      action: call-service
      service: device_internet_access
      data:
        entity_id: device_tracker.test_device
        state: false

however when I test clicking this button I get: “failed to call service device_internet_access/undefined. required key not provided @data[service]. got none”

Am I missing some element in data that this service needs? :flushed: noob here, this is the first time I’m trying to do anything with services.

Hey, @TekDad,

The requested feature (allow / block internet access per device) is really coming in version 0.12.0. And the documentation does already include the description (I have published it yesterday). Please, note that each feature has the minimal integration version specified.

0.12.0 will be released in the following 48 hours (the last tests are almost over) and afterwards you will be able to use the new service. I will also publish an example YAML of how to implement it.

1 Like

Oh I see “AsusRouter >= 0.12.0” - I was jumping the gun a bit. lol. Love the integration, can’t wait for v12!

0.12.0

:mag: Per-device internet control is coming to AsusRouter (using the parental control feature of routers)!

Including a binary_sensor / switch for the global parental control (on / off) with a full list of rules via the list attribute.

Plus new service asusrouter.device_internet_access to create a block rule, disable or remove it.

Here is a small example of how to use it:

Button for a device internet control

Change {connected_device}, {device} and the mac value for the ones you need.

switch:
  - platform: template
    switches:
      internet_{connected_device}:
        friendly_name: Internet/{Connected Device}
        unique_id: internet_{connected_device}
        value_template: >
          {% set ns = namespace(
            mac = "01:23:45:67:89:ab"|upper,
            list = state_attr("switch.{device}_parental_control", "list"),
            internet = true
          ) %}
          {# Find whether #}
          {% for element in ns.list %}
            {% if element.mac == ns.mac and element.state == "block" %}
              {% set ns.internet = false %}
            {% endif %}
          {% endfor %}
          {{ ns.internet }}
        turn_on:
          service: asusrouter.device_internet_access
          data:
            entity_id: device_tracker.{connected_device}
            state: disable
        turn_off:
          service: asusrouter.device_internet_access
          data:
            entity_id: device_tracker.{connected_device}
            state: block

Alternative - you can set the service state to remove instead of disable - this way rule will be removed from the list, not just disabled. Might be useful in case you are on the limit of the number of rules (32 / 64 depending on the router model).

:books: Other changes

  • Device-related events are getting connection_type and guest attributes.
  • The same attributes are added to the device list of connected_devices sensor.
  • The new documentation is added to the integration.
  • We are finally changing the last place not to use the correct AsusRouter naming - in the integrations list (it was still ASUS Router there).
  • Deprecated asusrouter.service_reboot is now removed.

:loudspeaker: The new version is available in HACS in 3… 2… 1… Now

Release 0.12.0 :mag: Per-device internet control / parental control and new documentation :books: · Vaskivskyi/ha-asusrouter (github.com)


:beer: Want to support the development? Help me with getting an additional device for all the needed tests or Buy Me a Coffee

3 Likes

Sounds great!
But sadly “Unknown error” for me when configuring the integration. I might try on a clean HA installation later.

disregard, router restart and able to configure now.

1 Like

A bug fix for users of 3- and 4-band routers (with 5 GHz-2 and 6 GHz networks) - the connection_type attributes should work well now.

Release 0.12.1 :bug: Bug fixes and small improvements · Vaskivskyi/ha-asusrouter (github.com)

I am sorry for when some bugs are happening to the users. Unfortunately, this can occur with the features, not supported by my test device. I am trying to fix all the bugs reported as soon as possible.

2 Likes

Oooof. So excited v12 came out - My Enable/Disable toggles are now working per device!

Here is what I have:

type: custom:collapsable-cards
title: 'Ryan: Mobile'
cards:
  - type: entities
    entities:
      - entity: device_tracker.ryan_s_note20_3
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: connection_type
        name: Connection Type
      - type: divider
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: ip
        name: IP
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: mac
        name: MAC
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: internet_mode
        name: Internet Access
      - type: divider
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: last_activity
        name: Last Activity
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: rx_speed
        name: Inbound Speed
      - type: attribute
        entity: device_tracker.ryan_s_note20_3
        attribute: tx_speed
        name: Outbound Speed
      - type: divider
      - type: button
        icon: mdi:power-on
        name: Enable Access
        action_name: toggle
        tap_action:
          action: call-service
          service: asusrouter.device_internet_access
          data:
            entity_id: device_tracker.ryan_s_note20_3
            state: disable
      - type: button
        icon: mdi:power-off
        name: Disable Access
        action_name: toggle
        tap_action:
          action: call-service
          service: asusrouter.device_internet_access
          data:
            entity_id: device_tracker.ryan_s_note20_3
            state: block

I then tried to use the code snippet you provided in post [Custom component] AsusRouter integration - #211 by Vaskivskyi

        switch:
        - platform: template
          switches:
            internet_device_tracker.ryan_s_note20_3:
              friendly_name: Internet/device_tracker.ryan_s_note20_3
              unique_id: internet_device_tracker.ryan_s_note20_3
              value_template: >
                {% set ns = namespace(
                  mac = "aa:11:aa:22:aa:33"|upper,
                  list = state_attr("switch.device_tracker.ryan_s_note20_3_parental_control", "list"),
                  internet = true
                ) %}
                {# Find whether #}
                {% for element in ns.list %}
                  {% if element.mac == ns.mac and element.state == "block" %}
                    {% set ns.internet = false %}
                  {% endif %}
                {% endfor %}
                {{ ns.internet }}
              turn_on:
                service: asusrouter.device_internet_access
                data:
                  entity_id: device_tracker.device_tracker.ryan_s_note20_3
                  state: disable
              turn_off:
                service: asusrouter.device_internet_access
                data:
                  entity_id: device_tracker.device_tracker.ryan_s_note20_3
                  state: block
    show_header_toggle: false

This didn’t change anything in my lovelace card, I get no syntax errors, but I also dont get any button or control displaying to allow me to control internet access to the device. Not sure exactly what this snippet of code is actually supposed to do.

Would be AWESOME if I could just create a profile button for each child which when toggled would enable/disable internet for ALL of their devices, instead of having to control each device individually with its own lovelace card.

Hey,

Thanks for your feedback and sorry for my late feedback.

It is true that my router IP doesn’t change so I’m gonna use the IP.
For the local DNS, what do you use and where is it installed? I’m using Adguard Home directly on my Asus AX88U router installed with amtm and it works nice, though I’m not sure that it’s the fastest way to answer DNS requests (other way would be to install Agdguard on my home server and foward all DNS requests to it but kinda afraid of having a lower bandwith for my other stuff like the cameras, etc…).

Other question, I’m using wireguard VPN on my asus and amtm. Do you think possible to add in your addon some switches to turn on/off the wireguard item, check the status, check amtm/addon upgrade and launch said upgrade (might be too hard for the last one since some addons ask for some user input)? I’m willing to add some monitoring of my servers and all in HA and the router is a good idea, specially to reset wireguard in case the status is down (sometimes happens when my other router is down).

Thanks again!

anyone have any idea if or how to get the following:

tap_action:
          action: call-service
          service: asusrouter.device_internet_access
          data:
            entity_id: device_tracker.ryan_s_note20_3
            state: block

to support multiple entities? Maybe something like this:

tap_action:
          action: call-service
          service: asusrouter.device_internet_access
          data:
            entities: 
              - device_tracker.ryan_s_note20_3
              - device_tracker.ryan_laptop_work
            state: disable

Currently the proposed “entities” does not work, doesn’t cause any errors, but never actually changes the state of internet access to either of the 2 devices defined.

Not an expert in this but think you need entity_id instead of entities in your second code snippet to allow for multiple entities…

yeah I tried that, you get a 'duplicated mapping key ’ syntax error when you include more than 1 ‘entity_id’.

1 Like

Figured it out - for those looking for similar functionality.

  1. Create an automation for Enabling Internet and for Disabling Internet (2 automations)
    1a. Click ADD ACTION (you do not need to set up triggers or conditions unless you want to)
    1b. Choose the service: AsusRouter: Device Internet Access Control
    1c. Enable Entity and choose the appropriate device
    1d. Choose the appropriate state. Block to block access, Disable to grant access
    1e. Create additional actions with the above steps for each of the devices you want to include in the single button click from lovelace


    (in my setup above, I have 2 devices being controlled in this individual automation. I have another automation with the same settings, just a different state of ‘disable rule’ which is used to enable internet access to the same 2 devices)

  2. Create a button on your lovelace dashboard for enabling and disabling internet (2 buttons)

**Enable Code**
type: button
show_name: true
name: Enable Internet
show_icon: true
icon: mdi:account-check
show_state: true
tap_action:
  action: call-service
  service: automation.trigger
  service_data:
    entity_id: automation.internet_grant_ryan

**Disable Code**
show_name: true
show_icon: true
type: button
name: Disable Internet
icon: mdi:account-cancel
show_state: true
tap_action:
  action: call-service
  service: automation.trigger
  service_data:
    entity_id: automation.internet_block_ryan

image
This gives me 2 functional buttons, which when clicked will either enable or disable internet access to both my cell phone and work laptop.

I plan to replicate this so that I have an enable button and disable button for each of my children so I have single click access to turn internet on/off for their groups of devices.

@Vaskivskyi awesome integration!

5 Likes