yeah, gonna to that indeed, but i wait now untill its offline again to provide you the info
I had free time this week so I think I managed to get it right this time and created a sensor to accurately track the status of the aimesh devices. Fingers crossed. Apparently when a node is offline, it disappears from cfg_device_list. So we have to query and track the status of the device using that.
Tracking by ip is not reliable if you don't have a static one. So the guaranteed way is to track by MAC address which is totally static.
I will explain the steps to create this sensor in Home Assistant but this needs more testing in different conditions. If you use this method and notice something is wrong, please let me know.
First of all, we have to query the router to get the cfg_device_list values. There are a couple of options to do that but I found that the most reliable one is using SNMP.
You can publish this value extending your snmp agent using merlin fw.
create a file aimesh.sh with content:
Bash:
#!/bin/sh
nvram get cfg_device_list
place this file into /jffs/scripts/snmp/ folder. If it doesn't exist, just create the folder.
give executable permission to the file:
create or edit snmpd.conf.add file inside /jffs/configs by adding below line
Code:
extend .1.3.6.1.2.1.25.1.28 aimesh /bin/sh /jffs/scripts/snmp/aimesh.sh
Go to webui of the router and enable snmp.
Now the router should be advertising this value with the snmp agent.
The good thing about this method is you don't need to query the router. It consumes less resources and there is one less point of failure.
You have to find the OID for this value now. You can use any mib browser to do that.
The OID might be the same or different from mine.
Mine is
.1.3.6.1.2.1.25.1.28.3.1.1.6.97.105.109.101.115.104
Next is to create a SNMP sensor in the home assistant.
I will just paste my configuration
YAML:
# #AIMESH STATUS
- platform: snmp
host: 192.168.1.1
baseoid: .1.3.6.1.2.1.25.1.28.3.1.1.6.97.105.109.101.115.104
name: "Aimesh Devices"
accept_errors: true
default_value: 0
version: 2c
value_template: '{{ (value.replace("<", " ").replace(">", " ").lstrip()).split(" ") }}'
scan_interval: 35
Next create two "input_text" helpers for each of your nodes.
One is for storing MAC address the other is for storing the last known ip of your node.
input_text_node1_mac
input_text_node1_ip
input_text_node2_mac
input_text_node2_ip
Get the MAC address of your nodes from cfg_device_list and enter them into appropriate mac input texts manually.
Now create a template sensor for each of your nodes. This template sensor is the one that will give the final status of the node. It will check cfg_device_list and native device tracker of asuswrt integration to indicate the status of the node.
YAML:
- sensor:
# Aimesh Status Sensor for Node 1
- name: "Aimesh Node1 Status"
unique_id: "Aimesh Node1 Status"
icon: >-
{% if is_state('sensor.aimesh_node1_status', 'Wireless Backhaul') %}
mdi:wifi
{%elif is_state('sensor.aimesh_node1_status', 'Ethernet Backhaul') %}
mdi:ethernet
{%else%}
mdi:close-network-outline
{%endif%}
state: >-
{% if states('input_text.node1_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node1_lan_asuswrt', 'home') %}
Ethernet Backhaul
{% elif states('input_text.node1_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node1_lan_asuswrt', 'not_home') %}
Wireless Backhaul
{%else%}
Offline
{%endif%}
attributes:
ip: >-
{% if not is_state('sensor.aimesh_node1_status', 'Offline') %}
{% set master_list = states('sensor.aimesh_devices').replace('[','').replace(']','').replace("\'",'').replace(' ', '').split(',') %}
{% set master = namespace(device=[]) %}
{% for x in master_list|batch(4) %}
{% set master.device = [x] + master.device %}
{%endfor%}
{% for x in master.device %}
{% if states('input_text.node1_mac') in x %}
{{master.device[loop.index0][1]}}
{%endif%}
{%endfor%}
{%else%}
{{ states('input_text.node1_ip') }}
{%endif%}
availability: >
{{ not 'unavailable' in
[ states('sensor.aimesh_devices') ] }}
# Aimesh Status Sensor for Node 2
- name: "Aimesh Node2 Status"
unique_id: "Aimesh Node2 Status"
icon: >-
{% if is_state('sensor.aimesh_node2_status', 'Wireless Backhaul') %}
mdi:wifi
{%elif is_state('sensor.aimesh_node2_status', 'Ethernet Backhaul') %}
mdi:ethernet
{%else%}
mdi:close-network-outline
{%endif%}
state: >-
{% if states('input_text.node2_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node2_lan_asuswrt', 'home') %}
Ethernet Backhaul
{% elif states('input_text.node2_mac') in states('sensor.aimesh_devices') and is_state('device_tracker.node2_lan_asuswrt', 'not_home') %}
Wireless Backhaul
{%else%}
Offline
{%endif%}
attributes:
ip: >-
{% if not is_state('sensor.aimesh_node2_status', 'Offline') %}
{% set master_list = states('sensor.aimesh_devices').replace('[','').replace(']','').replace("\'",'').replace(' ', '').split(',') %}
{% set master = namespace(device=[]) %}
{% for x in master_list|batch(4) %}
{% set master.device = [x] + master.device %}
{%endfor%}
{% for x in master.device %}
{% if states('input_text.node2_mac') in x %}
{{master.device[loop.index0][1]}}
{%endif%}
{%endfor%}
{%else%}
{{ states('input_text.node2_ip') }}
{%endif%}
availability: >
{{ not 'unavailable' in
[ states('sensor.aimesh_devices') ] }}
Now we have the active status of the nodes. But I wanted store the last known ip to the ip attribute of the sensor to reboot via ssh in case it shows offline but pingable.
An automation like that will do the trick to store the last known ip to the input text ip of the node.
YAML:
alias: Store Aimesh Last Known IP Addresses
description: ''
trigger:
- platform: state
entity_id: sensor.aimesh_node1_status
id: aimesh_node1_ip_change
for: '00:00:20'
to: Offline
- platform: state
entity_id: sensor.aimesh_node2_status
id: aimesh_node2_ip_change
for: '00:00:20'
to: Offline
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: aimesh_node1_ip_change
sequence:
- service: input_text.set_value
target:
entity_id: input_text.node1_ip
data_template:
value: '{{trigger.from_state.attributes.ip}}'
- conditions:
- condition: trigger
id: aimesh_node2_ip_change
sequence:
- service: input_text.set_value
target:
entity_id: input_text.node2_ip
data_template:
value: '{{trigger.from_state.attributes.ip}}'
default: []
mode: parallel
max: 10
This should be it. Let me know how that works out for you.