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

I want to use this method, but we have four mobile phones involved. If the last leaves the house; arm the alarm. (Is already in place for disable the heating so nothing special. After some minutes an nmap scan will do it’s job)
But if armed, and the front door or garage door is opened; I want to check if any of the mobile phones arrives at home before the alarm triggers. It looks like your solution works with only one device, is that correct? Can it be used with multiple devices?

Just create 4 binary sensors each targeted by their own IP Address

In your automation you can either check the status if each one or make a binary sensor group containing all of your phone NMAP sensors.

If the group is ‘off’, all phones have left the house
If the group is ‘on’, at least one phone is in the house

I explicitly force my command_line sensors (the command line ones) to reload whenever any exterior door in my house opens (once a minute for 5 minutes)

Just create an automation that calls command_line.reload when you want to force the NMAP binary sensor to update outside of the normal scan_interval