Test for connectivity to MAC address

I would like to set up an automation to cycle the power on a relay based on whether a network device is connected on the local LAN.

But, I would prefer to use the device’s MAC address to eliminate any possible change in IP address causing failure in the future.

Can anyone help with this?

I imagine an NMAP-type scan based on MAC address.

Thank you!

You can use the NMAP tracker integration combined with device tracker integration

Then set your automations based on presence

You can also consider using ping with hostname if that’s possible, that’ll also prevent issues with changing IP addresses, and is going to be more efficient.
Or simply setting a static for the device on your router

Thank you so much.

If ping would be more efficient, I can do that with either hostname or static ip.

In case anyone is interested, this is the code I used to get this to work.

I’m sure it is primitive by the standards of the experts here, but it’s more than I could create a couple weeks ago:

alias: THR316-Attic State is off
description: ""
  - platform: state
      - binary_sensor.ping_thr316_shelly1
    from: null
    to: "off"
      hours: 0
      minutes: 10
      seconds: 0
  - alias: Unable to ping THR316
    condition: state
    entity_id: binary_sensor.ping_thr316_shelly1
    state: "off"
      hours: 0
      minutes: 2
      seconds: 0
  - service: notify.notify
      message: Ping lost to 125THR316-Attic
      title: HA Notify
  - service: notify.notifier_name
      message: THR316 Attic Lost Connectivity
  - service: notify.mobile_app_iphone
      message: test notification
    enabled: true
  - service: switch.turn_off
    data: {}
      entity_id: switch.shelly_shsw_1_e8db84d6d456
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: switch.turn_on
    data: {}
      entity_id: switch.shelly_shsw_1_e8db84d6d456
mode: single