Manually trigger nmap home scan

Hello there,
Is there a way to trigger a manual nmap scan, only for devices that are home if possible?
I could lower home_interval, but I don’t want to send out too many requests. Anyway, I would trigger this scan when my bluetooth tracker changes to not_home. This way I can use both trackers (WiFi and Bluetooth) in a person and HASS can be almost instantly be aware of me leaving my place.

I know an “alternative” could be to directly run nmap command, parse the output and then execute device_tracker.see, but I’d like to know if there is an easier (and more clean) approach to this.

Thank you!

Hi, this may be too late for you, but you can do this with Shell Command - Home Assistant. The nmap page tells you what commands are sent by default, and I copied that to set up a run_nmap command (excluding the HA server at 192.168.1.144) which then appears as the callable service shell_command.run_nmap

shell_command:
  nmap -oX - 192.168.1.1/24 --exclude 192.168.2.144 -F --host-timeout 5s

Then, call it from s script like this:

run_nmap_scan:
  alias: Run nmap scan
  sequence:
  - service: shell_command.run_nmap
  mode: single
1 Like

Thanks, but that will not update the device trackers.

You’re right, it doesn’t. I’m still pretty new at this, and am now confused. If nmap doesn’t update any trackers, why is it so often mentioned as (part of) a presence detection setup? I wonder what other use cases there are for it.

That’s because the HA component for network device tracking calls nmap directly and parses its output:

1 Like

For those still finding this topic after all this time and are interested in the “alternative” solution that @daniele_athome mentioned, check mine here. There are some steps involved but it works beautifully.

1 Like