Anyone had luck with nmap component and modern phones?

It’s scanning for new devices that it can see. So if you were at work and came home, your phone attaching to you home network would be a new device.

no that’s not how its working. I just came home 5minutes ago and i’m showed as home.

Anyway this isn’t relevant, the nmap component is seemingly useless for modern phones, so can anyone recommend a better way to track presence? I looked for some zwave fob or something like that but there doesn’t seem to be much out there! I would like to automate a lot of things on arrival and leaving the property so really do need it!

The thing with nmap is that because the apple and apparently now some android phones go to sleep to conserve battery, nmap can’t see them when they are asleep. The phones need some kind of wake on lan feature.
As far as other methods, all the others I have seen require some app on your phone to track your location. If you don’t have the app running, your phone isn’t telling the system where it is. There is some interesting work going on with BLE trackers, like trackr, but in my opinion, it isn’t there yet. A company called happy bubbles is doing some interesting work, so is trackr. But i’m not happy with the solutions yet.

I’ve tried OwnTracks, nmap, and ping for a Nexus 6P and 5X. Both nmap and ping would have false aways all the time. I originally had issues with OwnTracks as well, but after adding waypoints in the app to use geofences, it’s worked nearly flawlessly with no noticeable impact on battery. The other advantage of it is that it can track other zones as well, e.g. work.

I also have tried using nmap for tracking of my android 7 phone. Finetuning of the interval, running mnap as root didn’t help. Still got a lot of false-aways. I gave up using the network als tracking.

I am now using bluetooth LE (running HA on RPI 3) and a cheap (15 euro) bluetooth LE tag (gigaset g-tag). Works like a charm! (batterylife +/- 1 year and user replaceble)

If you’re on raspberry Pi 3; just buy a bluetooth low energie device like a sporttracker or a simple tag. Attach the tag to your keys and you’re good to go! Still using Nmap for wired devices though.

That gigaset g-tag seems pretty large though for a pocket? As i understand it they can’t be much smaller due to battery?

How quick does it connect when you arrive at the property?, I want to turn on lights inside, handle some other tasks, raise outside light dim levels etc upon arriving

Looks like owntracks may be the best option, it has some additional flexibility like being able to turn on heating if i’m inside a certain radius and such, but it’s constantly pinging back to home right, i would think if there isn’t internet connection or the connection is poor in some places that this would add some load to my device and drain battery. I guess i’ll give it a go and see!

I’ve been using Owntracks with a Droid Turbo since starting with HA and it’s taken a little tweaking with setting the radius. What seemed to make a big difference to me in getting accurate state reporting was adding a iBeacon into the mix after reading this blog post:

As far as battery life, I don’t really see an impact, but I am using a custom ROM and the author does a fair bit of tweaking for battery life. That may be why, but honestly I don’t see it using a whole lot battery time when I look in the battery stats.

Thanks everyone, will try owntracks for now with the pointers mentioned!

kinda depends on the scan interval of the bluetooth component. I’m not using it in “production” right-now due to some problems with my zwave setup. My RPI is right at the entrance of my (small) studio, so I’m willing to bet it will detect my tag even before I have unlocked the door.

Its about 2x2 cm and 5 mm tick. Not the largest item on my keyring. Battery is a single cr3032.

I think the key with presence detection is to use multiple methods at ones, and to assign a separate device in you known_devices.yaml for each method. I have great results using nmap, gps logger, and owntracks on android 7.
(Owntracks is used only because I am not sure if HA can calculate proximity values from anything else.)
I have three separate devices in my known_devices.yaml for my phone and only trigger automations to off when all report ‘not home’, but trigger on when any of the three devices reports ‘home’. (Actually setting a binary sensor to off and on)

No need for any fancy extra hardware.

1 Like

Is there a tutorial somewhere for setting this up? Anything I’ve tried on my iPhone that uses location services absolutely destroys my battery,

Here is how to configure the tracker. Note: for Iphone, I had to go into the bluetooth settings and leave that open while restarting home assistant. Iphones seem to only broadcast while in the bluetooth settings and for me, home assistant seemed to only add Iphones on startup.

If after configuring the device tracker you get an error similar to …

INFO:homeassistant.util.package:Attempting install of pybluez==0.22
Command "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/f1/x1cbc0q53sjc8w8sbvyzw4n40000gn/T/pip-build-p5f2np6x/pybluez/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/f1/x1cbc0q53sjc8w8sbvyzw4n40000gn/T/pip-fqesz8r4-record/install-record.txt --single-version-externally-managed --compile --home=/var/folders/f1/x1cbc0q53sjc8w8sbvyzw4n40000gn/T/tmpzg2q0qx6" failed with error code 1 in /private/var/folders/f1/x1cbc0q53sjc8w8sbvyzw4n40000gn/T/pip-build-p5f2np6x/pybluez/
ERROR:homeassistant.bootstrap:Not initializing device_tracker.bluetooth_tracker because could not install dependency pybluez==0.22

Run these commands to install the missing dependency.

sudo apt-get update
sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
2 Likes

Thanks man, works great!

Hi,

I know this could be an “old” post since nobody writes on it since 1 month ago, but I’m running some tests on my RPi3 to detect all my diferent devices (ios, android 5 &6 and win-pc systems) trough “arp” instead of nmap and right know the success rate is good enough for me as every time, i perform an arp request (around 5 times a day) my andorid 6 is detected as well as my win pc and Ipad.

In the past, I wrote about the possiblity to use arp instead of nmap for presence detection (link below), but someone point out that it could be possible that arp deosn’t detect some devices, as in order to work, the device running the arp command (in my case the RPi3) should have a connection with all the devices to detect, which yes, that’s the theory but in my case even if a new device is registered in my LAN, inmeaiatley can be found through the arp command and I’m not running Pi-hole or something that forces the communication between new devices connected to my network and the Pi.

So do any other have had good results with arp?

Using ARP instead of Nmap

Hi all,

i’m having the best results with arp too.

Before i used HA, i had a script that worked very good with iOS devices.
Since last weekend i activated it again to use with HA as “command_line device tracker”

The script runs as root on a ubuntu 14.04 server every minute and publishes the states to mqtt.

In HA i use mqtt device tracker

- platform: mqtt
  devices:
    person1: home/people/person1
    person2: home/people/person2
    person3: home/people/person3
    person4: home/people/person4

and here’s the script.

#!/bin/bash

# Activate iTunes Sync over WLan for this to work!
# Use fixed IP`s or reservations in DHCP

## Devices to scan
###################
DEVS="
192.168.1.27|xx:xx:xx:xx:xx:xx|person1
192.168.1.78|xx:xx:xx:xx:xx:xx|person2
192.168.1.40|xx:xx:xx:xx:xx:xx|person3
192.168.1.36|xx:xx:xx:xx:xx:xx|person4
"

## Minutes to show device Offline
##################################
MINUTES=10

## iterate over devices
for DEV in $DEVS; do
    case "$DEV" in
    \#*)
        continue
        ;;
    *)
        IP=$(echo $DEV | cut -d '|' -f1)
        MAC=$(echo $DEV | cut -d '|' -f2)
        USER=$(echo $DEV | cut -d '|' -f3)

        # tickle iOS Device
        /usr/sbin/hping3 -2 -c 10 -p 5353 --fast $IP -q >/dev/null 2>/dev/null

        DEVICES=`/usr/sbin/arp -an | awk '{print $4}'`
        if [[ $DEVICES == *$MAC* ]]; then
            echo -n '' > $USER.txt
            mosquitto_pub -h 127.0.0.1 -t home/people/$USER -m "home" -r
        else
            echo 'OFF' >> $USER.txt
            MINOFF=$(wc -l $USER.txt | awk '{print $1}')
            if [ $MINOFF -gt $MINUTES ]; then
                echo "$(tail -n $((MINUTES+1)) $USER.txt)" > $USER.txt # keep not more than MINUTES+1 lines
                mosquitto_pub -h 127.0.0.1 -t home/people/$USER -m "not_home" -r
            fi
        fi
        ;;
    esac
    sleep 1
done

Sometimes (i do it every night via cron) i have to flush the arp cache
ip -s neigh flush all >/dev/null 2>/dev/null

This works perfect for me.

Greetings
Rainer

1 Like

sorry for this old topic @VDRainer

I’m trying to use your script, how do you setup this as ‘command line’ and track it as a device tracker ?

First install hping3 and mosquitto-clients.
apt-get install hping3 mosquitto-clients

For example, the script is saved as nscan.sh in folder /root/scripts/nscan/.
You have to edit the DEVS and the MQTT IP (127.0.0.1 if mqtt runs on the same server) to your needs.

Now there is a cronjob that calls it every minute.
* * * * * cd /root/scripts/nscan; ./nscan.sh

The script publishes the state of the devices to mqtt.

In HA setup the mqtt device tracker with the topics from the script.

device_tracker:
  - platform: mqtt
    devices:
      person1: home/people/person1
      person2: home/people/person2
      person3: home/people/person3
      person4: home/people/person4

BTW, there’s also a custom_component from @return01 for this.

2 Likes

thank you, this will help for sure/

1 Like

This is an old post, but the problem with nmap and sleeping phones remains the same. I have tried to figure out a solution, and I think I might have found one. It requires some changes both in the HA app and in the nmap component, so I have posted it as a feature request. Please have a look at: https://community.home-assistant.io/t/improvement-to-nmap-device-tracking-using-raise-to-wake-to-avoid-false-away/

Could this be a possible approach?