Read MAC address from known_devices.yaml

Hello,
I have some devices listed under known_devices.yaml.
They show up in HA under device_tracker
However, the mac address is not listed in the state attributes even though it is defined in the known_devices.yaml.

lyra_xx1:
  name: Lyra 1
  mac: XX:XX:XX:XX:XX:XX
  icon: mdi:access-point-network
  picture:
  track: true

I want to find the ip address of the device using the mac address in an automation.
Right now, I am doing this in a very complicated way.
My way currently:
device tracker detects the device in “home”
calls a shell command to run a sh script located in a local folder

get_ip: /bin/sh /config/"Bash Scripts"/ip_from_mac.sh

ip_from_mac.sh

#!/bin/sh
arp -n | grep -w -i "$1" | awk '{print $1}' > /config/"Bash Scripts"/ip.txt

the script takes manually entered MAC address in an automation as variable to search the ARP table and write the result in a file called ip.txt.

HA uses file sensor to read the ip.txt and writes these to the input_text.

This way is awfully complicated.
If there was a way to store stdout of the shell command or read MAC address from the known_devices.yaml, it would be a lot simpler.

Any advice to make this simpler for me?

You sure? Running

{{ states.device_tracker | selectattr("attributes.mac") | map(attribute="attributes.mac") | list }}

in template designer gives me a list of every device that is tracked by device_tracker and has a MAC address.

{{ states.device_tracker | selectattr("attributes.ip") | map(attribute="attributes.ip") | list }}

Does the same for IP addresses.


Unfortunately, it doesn’t seem to work for me.
I use Asus-wrt integration to populate the device_tracker.
Maybe, this integration doesn’t record MAC addresses. However, they are listed under known_devices.yaml. Hmm, weird.

That’s … interesting. How about Entity view in Developer Tools. I see IP and MAC there, too:

grafik

image
no mac or ip listed

So, it could depend on the Device Tracker integration you use, because mine is AVM Fritzbox and your’s AsusWRT. You could temporarily switch to NMap to check, if this changes things.

Yeah, I suspected as such.
But, it is weird that MAC address is listed under known_devices.yaml but not exported to the HA state attributes with Asuswrt integration unlike your AVM Fritzbox. Should I open a bug report or something I wonder?

I suggest waiting for the next release of HA, because there has been a commit after 2021.2.3, which obviously (I am not familiar with Python) addresses this.

I didn’t know that.
Next month then

It has been addressed like you said.
But now it has a different problem. It cannot accurately detect wireless aimesh nodes. It produces weird MAC addresses.