Good work!
A “not-so-important” question: is it possible to add tab to output? I mean, i also tried same output (name, ip, mac), but since names are not same length it gets harder to read ip and mac, so it would be nice if adding tab were possible. Or, perhaps, aligning name to left and ip+mac to right…
Now i’m getting picky, right?
Possible, but it would become even uglier with code
Maybe, it could be written better, but this is a fast-working solution.
{% set ns = namespace(devices = [], max_length = 0, max_tabs = 0) %}
{# Process the list of strings into the list of dicts #}
{% for item in state_attr('sensor.rt_ax88u_connected_devices', 'devices') %}
{%- set attrs = item.split("/") %}
{%- set mac = attrs[0] %}
{%- set ip = attrs[1] %}
{%- set name = item.replace((mac + "/" + ip + "/"), "") %}
{%- set device = [dict(mac = mac, ip = ip, name = name)] %}
{%- set ns.devices = ns.devices + device %}
{# Save the maximum length of device names #}
{%- if name|length > ns.max_length %}
{%- set ns.max_length = name|length %}
{%- endif %}
{% endfor %}
{# Sort #}
{%- set ns.devices = ns.devices|sort(attribute="name", case_sensitive=true) %}
{%- set ns.max_tabs = (ns.max_length / 8)|int %}
{# Output #}
{% for device in ns.devices %}
{{- device.name }}
{%- set tabs = (device.name|length / 8) | int %}
{%- for tab in ['\t']|batch(ns.max_tabs - tabs + 1, '\t') %}
{%- for el in tab %}
{{- el }}
{%- endfor %}
{%- endfor %}
{{- device.ip + '\t' + device.mac }}
{% endfor %}
Snapshot
I use the Flex table card for another use cases, but that probably could be used for what you are trying to achieve. It’s quite flexible, you can add more columns, sort, filter, etc…
@Vaskivskyi thanks! That’s VERY nice look!
But, it seems that mushroom card must have some sort of bug…? since that nice look is only in developer tools, while in mushroom template card those extra tabs are not shown, so it gets from your nice look above to this (note i changed yours “…batch(ns.max_tabs - tabs + 1” to “…batch(ns.max_tabs - tabs + 3” for more space between name and ip, but result is the same):
Ii did some searching, but it sems that “template cards” are pretty scarse for HA, since i can’t find anything usefull rather that mushroom card.
@EdwardTFN thanks, i’ll check out. Although quick look doesn’t look proimising, since sensor “sensor.rt_ax88u_connected_devices” has all entities under one single attribute (devices),so it’s hard to easy them. But, card will prove usefull in the future.
Try this:
type: custom:flex-table-card
title: Connected devices
entities:
include: sensor.rt_ax88u_connected_devices
columns:
- data: devices
name: MAC
modify: x.split('/')[0]
- data: devices
name: IP
modify: x.split('/')[1]
- data: devices
name: Name
modify: x.split('/')[2]
It worked for me:
Just noticed you want the columns in the reverse order, so try this instead:
type: custom:flex-table-card
title: Connected devices
entities:
include: sensor.rt_ax88u_connected_devices
columns:
- data: devices
name: Name
modify: x.split('/')[2]
- data: devices
name: IP
modify: x.split('/')[1]
- data: devices
name: MAC
modify: x.split('/')[0]
UAU! Thanks a lot! That looks outstanding!
I wish i would be as siklled programmer as you, guys… but, a man can’t have it all, correct? I’m more in electronics hardware then in software.
EDIT: i play with this addon a bit and i managed to sort entites alphabetically - just add
sort_by: [devices+]
to main code.
To alter font size css code is used:
css:
table: 'width: 100%;font-size: 12px; line-height: 15px;'
th: 'font-size: 20px;'
tr td: 'border: 1px solid red;'
Above code sets font of devices to 12px, line height to 15px and font in line “NAMES” to 20px. ANd adds a border around all devices list.
nice card, indeed!
I was able to incorporate the list for the ‘Connected Devices’ entity into a ‘Fold Entity Row Card’ using the ‘Flex Table Card’. I was only able to get this to work because of the specific config settings that can be used with the ‘Flex Table Card’, so thanks to the creator of that card as well as the HA-ASUS Router integration! Screenshot and code below…
type: entities
entities:
- type: custom:fold-entity-row
padding: 0
head:
entity: sensor.asus_router_connected_devices
icon: mdi:router-wireless
tap_action:
action: none
entities:
- type: custom:flex-table-card
sort_by:
- devices+
entities:
include: sensor.asus_router_connected_devices
columns:
- data: devices
name: ' Device Name'
icon: mdi:devices
modify: x.split('/')[2]
- data: devices
name: ' Address'
icon: mdi:ip-network
modify: x.split('/')[1]
- data: devices
name: ' MAC'
icon: mdi:barcode-scan
modify: x.split('/')[0]
card_mod:
style: |
ha-card {
box-shadow: none;
background: none;
}
Love it.
I understand those are in seconds. But please help specify unit on the UI somewhere - no need to keep the users guessing.
I’ll add the units
Will be available with the next release
This just made my day! Thank you!
I’ve been manually going in and disabling these entities one-by-one since it has been causing so many issues with my Kasa Devices’ connectivity (don’t ask - long story that has nothing to do with your Integration).
Looking forward to it!
[BREAKING] With version 0.9.0 (when released), the devices
attribute of the Connected devices
sensor will change the format from a list of strings to a list of dictionaries. As a result, you will need to correct your templates.
I am attaching new versions you will need instead of the 2 types of code we discussed before.
Template with tabs alignment
{% set ns = namespace(
devices = state_attr('sensor.rt_ax88u_connected_devices', 'devices'),
max_length = 0,
max_tabs = 0)
%}
{# Save the maximum length of device names #}
{% for item in state_attr('sensor.rt_ax88u_connected_devices', 'devices') %}
{%- if item.name|length > ns.max_length %}
{%- set ns.max_length = item.name|length %}
{%- endif %}
{% endfor %}
{# Sort #}
{%- set ns.devices = ns.devices|sort(attribute="name", case_sensitive=true) %}
{%- set ns.max_tabs = (ns.max_length / 8)|int %}
{# Output #}
{% for device in ns.devices %}
{{- device.name }}
{%- set tabs = (device.name|length / 8) | int %}
{%- for tab in ['\t']|batch(ns.max_tabs - tabs + 1, '\t') %}
{%- for el in tab %}
{{- el }}
{%- endfor %}
{%- endfor %}
{{- device.ip + '\t' + device.mac }}
{% endfor %}
Flex Table Card
type: entities
entities:
- type: custom:fold-entity-row
padding: 0
head:
entity: sensor.rt_ax88u_connected_devices
icon: mdi:router-wireless
tap_action:
action: none
entities:
- type: custom:flex-table-card
sort_by:
- devices+
entities:
include: sensor.rt_ax88u_connected_devices
columns:
- data: devices
name: ' Device Name'
icon: mdi:devices
modify: x.name
- data: devices
name: ' Address'
icon: mdi:ip-network
modify: x.ip
- data: devices
name: ' MAC'
icon: mdi:barcode-scan
modify: x.mac
card_mod:
style: |
ha-card {
box-shadow: none;
background: none;
}
You will need to update the code in a similar way only after updating to 0.9.0
Cool.
Much better now.
So, here we go, 0.9.0 is released:
IMPORTANT! A breaking change for the devices
attribute of the Connected devices
sensor as discussed above. Please, check 2 messages before for the new code examples.
A new possibility - to select a custom update interval for different sensors independently.
Device trackers got many new updates:
- you can now disable them;
- select their own update interval, independent from all other sensors;
- one nasty bug was fixed, so fewer errors in your HA logs and fewer freezes of the integration.
Many code optimizations to faster work on it and decrease the time for bug fixes.
The full release notes are available here: Release 0.9.0 Breaking change Update intervals for different sensors and device trackers customizations · Vaskivskyi/ha-asusrouter (github.com).
The update is already available via HACS.
0.9.0 working great, thanks for the update.
Was reading through the GitHub notes and you can add model 4G-AC55U to your list as the component works perfectly on this model with stock firmware (sorry, should have let you know that sooner)
Quick slightly off topic Q…anyone know if is it possible to sort the Flex Table Card by IP Address?
As the same field is used for the three columns I don’t think the sort key will make any difference.
But I believe it always sort the first column (if no other instruction), then you can move IP for the first column. Is that OK?
I managed to sort by IP by having a hidden copy of that in the first column.
I still using the old version, but my card looks like this:
type: custom:flex-table-card
title: Connected devices
entities:
include: sensor.rt_ac88u_connected_devices
columns:
- data: devices
name: IP_hidden
modify: x.split('/')[1]
hidden: true
- data: devices
name: Name
modify: x.split('/')[2]
- data: devices
name: IP
modify: x.split('/')[1]
- data: devices
name: MAC
modify: x.split('/')[0]
sort_by:
- devices