[Custom component] AsusRouter integration

There are many old device_trackers in the list. Canā€™t delete them. Any idea to get rid of those old entities?

@poudenes,

Oh, sorry, I have mixed the models. You really have already reported your one as working :slightly_smiling_face:

There is no way yet to remove the old device_trackers. The idea is that device_trackers are kept, so when a device reconnects - it is handled well. As a result, HA does not allow removing these entities.

I can understand, that some devices are only appearing once in half a year in your local network and then you have some useless trackers.

I think, there is a possibility to allow deleting the old trackers. I will consider it as a feature to implement in the following releases.

1 Like

Its ok. Better to be sure so yes, yes this model is supported :wink:

I play lot with RPi and they connect and disconnect and those are also in HA now. Even when they not in use anymore.

They can be removed to stop HA and edit the core.xxx.xxx files manual. But a tricky wayā€¦
(Do not do this when you not know what youā€™re doing)

Thatā€™s so helpful, thanks. Is there a way to create a toggle switch that has THREE states?
OFF - CHANGING - ON
Itā€™s confusing for less-experienced users to flick the toggle switch from OFF to ON, then to see it switch itself OFF again for a little while, then back ON once the change has taken place? I figured if thereā€™s some way to visualise that the state change is in progress people wonā€™t try clicking the toggle switch multiple times when theyā€™re confused about why itā€™s not doing what they thought it would do.

@spry-salt,

I think, there is no native possibility for HA to have a 3-state switch. And this is something happening to many device-control integrations. HA wants the state to change immediately, but it does not, so the switch goes forth and back until the correct state is actually set.


Unfortunately, the update to 0.13.0 is delayed till the end of the week.

I hope you would agree, that it is better to get a bit more stable release a couple of days later, than a non-tested release faster (and then bugfixes).

4 Likes

0.13.0

:mag: Multiple parental control rules at once

Using new entities and devices parameters of the asusrouter.device_internet_access service, adjust internet access for multiple devices at the same time.

Usage:

entities:
 - device_tracker.device_1
 - device_tracker.device_2
 - device_tracker.device_3

or

devices:
  - mac: 01:23:45:67:89:01
    name: Device/1
  - mac: 01:23:45:67:89:02
  - mac: 01:23:45:67:89:03
    name: Device/3

:loudspeaker: Deprecation warning!

Old entity_id, mac and name parameters are now deprecated and will be removed in version 0.15.0.

Please, check the official documentation for more details: Parental control | AsusRouter (vaskivskyi.com)

:car: Latest connected devices sensor

sensor.{device}_latest_connected

This new sensor provides a datetime object of the last device connected to the router. More details: Connected devices | AsusRouter (vaskivskyi.com)

Its list attribute contains a list of the latest connected devices identities. Number of latest devices in the list can be configured in the AsusRouter options (Operation mode | AsusRouter (vaskivskyi.com)).

:book: New attribute for device identity

Connected device identities got a new attribute connected, showing a datetime since the connection was established.

Identities are used in:

  • Device events (connected, disconnected, reconnected)
  • Connected devices list (devices attribute) of connected_devices sensor
  • List of devices in the new latest_connected sensor.

More on identities: Connected devices | AsusRouter (vaskivskyi.com)

:bug: Bugfix

A nasty bug was fixed, which did not allow the usage of parental control features when the rules list was empty. All the users, which had rules before using them from AsusRouter did not notice it.

Other improvements

  • Code cleanups were made for constants (which helps with maintaining the integration code)
  • A missing string was added to the translations

GitHub release

AsusRouter

In case, you are curious, AsusRouter is not only the integration itself. It consists of the following:

  • Integration (which should be compatible with the latest HA releases and as many versions back as possible)
  • Backend Python library which performs all the communication between integration and your device
  • GitHub repo with the issue tracker
  • This Community thread (including all the nicely formatted release logs and code examples for different usage scenarios)
  • AsusRouter documentation with all the features explained, FAQ and examples

By the way, you might have noticed that for some feature requests I am answering ā€œit is not possible yetā€. The reason is - I donā€™t have devices compatible with some features (including AiMesh, Aura RGB, support of 2.5 Gb/s and 10 Gb/s ports, support of 5 GHz-2 and 6 GHz wireless bands). As a result, some features are either not available yet or are only partially available. If I get the supported device - I will implement them as well.

I am quite sure, AsusRouter easily can replace the native Web UI and mobile app. Just need some time for all the development. :honeybee:

Support AsusRouter development

AsusRouter is my free time project. You can support its development using the Buy Me a Coffee service :coffee:

4 Likes

Thank you for the update! As always, this is working quite well. Below I am attaching code of how I implemented the new sensor.asusrouter_latest_connected information into a card, including some templating of how to convert the timestamp into something thatā€™s easily readable. If someone else has a better method to convert the timestamp into 12hr or 24hr syntax, please post it!

I am also attaching a screenshot of the card using the following code (note: I have my settings set to ā€œ10 Recently Connected Devicesā€ rather than the default of 5).

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.asusrouter_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
    # Below shows an example of how to convert the timestamp 
    # into 'human' readable format - easier methods might 
    # be available (if so, post your code)
      - data: list
        name: ' Time'
        icon: mdi:clock
        modify: |-
          if(x.length == 0){"-"} else {
            var date = new Date(x.connected);
            String(date.getHours()).padStart(2,'0')+":"+
            String(date.getMinutes()).padStart(2,'0')+" "+
            (String(date.getMonth()+ 1).padStart(2,'0'))+"/"+
            date.getDate()+"/"+
            date.getFullYear()
          }
    card_mod:
      style: |
        ha-card {
          background: none;
          padding: 0px;
          spacing: 0px;
        }

Edit: Adding code and screenshot for the ā€˜Collapsible Cardā€™:

type: entities
entities:
  - type: custom:fold-entity-row
    padding: 0
    head:
      entity: sensor.asusrouter_latest_connected
      name: ASUS Router - 5 Recently Connected Devices
      icon: mdi:lan-check
    entities:
      - type: custom:flex-table-card
        sort_by:
          - list-
        entities:
          include: sensor.asusrouter_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: |-
              if(x.length == 0){"-"} else {
                var date = new Date(x.connected);
                String(date.getHours()).padStart(2,'0')+":"+
                String(date.getMinutes()).padStart(2,'0')+" "+
                (String(date.getMonth()+ 1).padStart(2,'0'))+"/"+
                date.getDate()+"/"+
                date.getFullYear()
              }
        card_mod:
          style: |
            ha-card {
              background: none;
              padding: 0px;
              spacing: 0px;
            }
show_header_toggle: false

6 Likes

@SpicyLimes, cool! Thanks for sharing! :+1:


The same thing differently

You can also convert the datetime to the JSON string and then use regex on it. On the positive side - the JSON time string is in ISO format - so no additional operations are needed to get the correct month number.

# Convert to JSON
# E.g. "2022-11-29T06:03:05:220Z"
var date = (new Date(x.connected)).toJSON();
# Get date - everything before T in JSON
var dateRegex = /^(\d{4})-(\d{2})-(\d{2})T.*$/
var dateData = dateRegex.exec(date);
# Get time - first 3 groups after T. Or you can use one more for 3 digit ms
var timeRegex = /^.*T(\d{2}):(\d{2}):(\d{2}).*$/
var timeData = timeRegex.exec(date);

# Output
dateData[1]+"-"+dateData[2]+"-"+dateData[3]+" "+
    timeData[1]+":"+timeData[2]+":"+timeData[3]

It does not really make code smaller but allows separating output from the processing. So in order to adjust it, one just needs changes in the last part and put 6 values in any needed order.

image


Those who do not care about changing format from ISO to anything else can take date and time as the whole thing:

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]

image

1 Like

Interesting - so the JSON coding would be a more ā€˜efficientā€™ way of doing it. Makes sense to me - any chance you know how to convert it to 12-Hour formatting? I donā€™t mind using 24-Hour time (Iā€™ve had to get used to it over the last few years while digging into more tech related subjects), but it would be nice to have it in 12-Hour time (I live in America where we like to do things differently than the rest of the world
:roll_eyes: haha - standard vs. metric, 12h vs. 24hr time, etc.)

Edit: Also, after replacing my original conversion code with yours, I am setting a 6 hour difference in time (i.e.; Original Code: 14:00 hours vs. Your Code: 20:00). Not sure how that is even possible.

Hi, just trying HA 2022.12.0.b0 and itā€™s giving an error, in case this is useful for you.

Logger: homeassistant.util.package
Source: util/package.py:98
First occurred: 7:47:28 PM (3 occurrences)
Last logged: 7:47:36 PM

Unable to install package asusrouter==0.12.0: ERROR: Cannot install asusrouter==0.12.0 because these package versions have conflicting dependencies. ERROR: ResolutionImpossible: for help visit Dependency Resolution - pip documentation v23.0.dev0 [notice] A new release of pip available: 22.3 ā†’ 22.3.1 [notice] To update, run: pip install --upgrade pip

@SpicyLimes,

Oh, I have lost the time zone, as I see now.

Then, unfortunately, it becomes more complicated

Code #1
var utc = new Date(x.connected);
var diff = (new Date()).getTimezoneOffset() / 60;
var date = new Date(utc.setHours(utc.getHours() - diff)).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]
Code #2
var utc = new Date(x.connected);
var diff = (new Date()).getTimezoneOffset() / 60;
var date = new Date(utc.setHours(utc.getHours() - diff)).toJSON()
var dateRegex = /^(\d{4})-(\d{2})-(\d{2})T.*$/
var dateData = dateRegex.exec(date);
var timeRegex = /^.*T(\d{2}):(\d{2}):(\d{2}).*$/
var timeData = timeRegex.exec(date);
dateData[1]+"-"+dateData[2]+"-"+dateData[3]+" "+
  timeData[1]+":"+timeData[2]+":"+timeData[3]

For am/pm time, I think, you should be able to use this code. But even more steps are needed.

Code #3
var utc = new Date(x.connected);
var diff = (new Date()).getTimezoneOffset() / 60;
var date = new Date(utc.setHours(utc.getHours() - diff)).toJSON()
var dateRegex = /^(\d{4})-(\d{2})-(\d{2})T.*$/
var dateData = dateRegex.exec(date);
var timeRegex = /^.*T(\d{2}):(\d{2}):(\d{2}).*$/
var timeData = timeRegex.exec(date);
var ampm = (Math.floor(timeData[1]/12)) ? "pm" : "am";
var hours = timeData[1] % 12 > 0 ? timeData[1] % 12 : 12
dateData[1]+"-"+dateData[2]+"-"+dateData[3]+" "+
  hours+":"+timeData[2]+":"+timeData[3]+" "+ampm

@spry-salt,

Thanks for your report! I will check it out

1 Like

Hey, people,

Some of you have already noticed, that from 2022-12, HA will mark Python 3.9 as deprecated and to be removed completely in 2023-2. The question is, whether AsusRouter should still support Python 3.9 up till HA 2023-2 release or should we drop it already now and optimize some code for both integration and the backend library?

First let me say ā€˜thank youā€™ for the integration and the work you put in on it.

For those systems running HAOS, Python should already be 3.10. Iā€™m fine with dropping 3.9 support, but we will need to hear from others.

Iā€™m running HAOS, so either way is fine with me.

:loudspeaker: Version 0.13.1 of AsusRouter is already available in HACS. Please, check it out - it should work with HA 2022-12 without any problems with dependencies.

1 Like

This is absolutely perfect - thank you!

Perfect, many thanks.

:cactus: AsusWRT 388.x

Probably you have already noticed, that lots of 802.11ax routers started receiving updates to the latest 388.x firmware, with some new features and some changes to the old ones. :bomb:

For me and AsusRouter as well, the plan is to fully support these builds. And the first new feature, coming to the integration from branch 388 will be the support of WireGuard :airplane:

:boom: Merlin

Since Merlin 388.1 is already out of beta, I am glad to announce, that AsusRouter will fully support it! :tada:

The only minor problem is for temperature sensors for WiFi modules, which are unavailable because of one more change in the routersā€™ API endpoint. This will be fixed in the next release (but the fix itself is ready now). :thermometer:

:hammer: Native

The native 388 builds of AsusWRT are already supported as much as possible. :wrench:

The only problem you will experience for now - OpenVPN clients and servers are broken. This is connected to a completely new way of working with VPN released in 388. :open_book: The fix is already planned.

:spiral_calendar: Calendar

  • Fix for OpenVPN on native builds

    I will try to implement the new VPN features as soon as it is possible. But you know, Decembers are a bit of a busy time, so letā€™s say closer to the end of January. :calendar:

  • WireGuard support

    I donā€™t have any experience with WireGuard, so understanding and implementing the new feature will require some time. But since the feature is fully supported by my testing device, the currently expected timeframe is January-February

  • No-spoiler alert

    Some new cool features are also expected in AsusRouter at the beginning of the year. I am quite sure, you guys will like it. :boom:


Achivements

A bit about what AsusRouter has already achieved:

  • :mag: We have at least 579 active installations of AsusRouter among users sharing their usage data with HA Analytics. On October 29, we had 528 installations. Looks like we are progressing and AsusRouter is actually useful.
  • :spider_web: In the last 26 days (since the AsusRouter documentation page was published) at least 284 users have visited it. You know, this one: documentation
  • :desktop_computer: AsusRouter supports at least 32 different models of routers.

As usual, please donā€™t be afraid to suggest new features and report bugs. All the reports are welcome and if possible all of the issues are solved. You can fill in a report in AsusRouter GitHub or here.

There is always a way to make AsusRouter even better. Letā€™s do it.


:coffee:

You can always support the development of AsusRouter using the BuyMeACoffee service:


:christmas_tree:

Have a nice holiday time!

1 Like

:christmas_tree: Holidays are coming

and with holidays, guests are relatives are coming for visits to our places. Connecting to our WiFi andā€¦

ā€¦ adding tons of device_trackers to HA which we will never actually use.

Happened to you? I can easily relate. And now the new version of AsusRouter is here to help you with the HA mess.

0.14.0 :christmas_tree: Holidays-ready release

:mag_right: New asusrouter.remove_trackers service

Probably, you have noticed, that you cannot just easily remove entities, even if the device did not appear online for a long time. This is done by purpose - device trackers are watched all the time (so HA will notice when it appears online again).

With the new service, you can mark unwanted entities as non-watched. This will allow you to remove the entities.

Please, keep in mind:

  • only offline device_trackers will be actually marked as non-watched
  • if you reboot HA before removing the entities, they will become watched again

Detailed description.

:thermometer: Temperature support for Merlin 388

Now, that Merlin 388.1 is officially released as stable, AsusRouter is adding support for the new way of reporting WiFi module temperatures.


Release

Already available in HACS


:book: Might be interesting

If you are interested in what else is planned for AsusRouter, please refer to this post.

:exclamation: Deprecation remainder

Please, donā€™t forget about the active deprecation warning for some parameters (entity_id, mac and name) of asusrouter.device_internet_access service. More details were here. They will be removed in version 0.15.0 and should not be used anymore.

:books: Help me improve the documentation

Your suggestions on how to improve AsusRouter documentation are always welcome.

Found an error or something missing? Let me know - so I can fix it.


:gift: :christmas_tree:

2 Likes

Is the service asusrouter.remove_trackers only for entities created with devices, or would we be able to remove entities that show the MAC addresses? I tried using the service on entities without an associated device, but am still not able to remove it after. Maybe Iā€™m doing something wrong?

Thanks again for your awesome work and continued development of this awesome integration!