Identify people by mobile phone



As part of home security automation, I want NR over RasPi to detect presence/absence of family members by presence of their mobile phones in the network.

I created a file with list of names and MACs:


I'm trying to create flow, so not much to share at the moment. I got stuck with adding users to the flow context.
The idea is:

  1. Read the CSV file and add every line as key:value item of dictionary people into flow context.
  2. Read arp table and check MAC presence.
  3. On user status change - do something.

So for point 1 I use file read node which passes to the function node each line as message.
The function is:

if (msg.payload == "") return;
var people = flow.get("people") || {};
var kv = msg.payload.split();
people.kv[0] = kv[1]; // Should be legal way to add an item to dict
flow.set("people", people);
msg.payload = flow.get("people");
return msg;

Accordingly to this thread, the people dict in the flow context should grow with each new message.
However, I get this message:

"TypeError: Cannot set property '0' of undefined"

Please, point me the error.
Thank you.



Two issues:

  1. You are not passing any arguments to the split function, so it won't know how you want to split the string. If the rows in your file are comma-separated, you should use:

    var kv = msg.payload.split(",");
  2. The code people.kv[0] means look up the kv property of the people object, then reference the first element of that property.
    You want to use the value of kv[0] as the name of the property to set in the people object. To do that, you have to use the alternative syntax for referencing object properties:

    people[kv[0]] = kv[1];


Bingo, Nick!
Thank you very much!

Fixed code:

if (msg.payload == "") return;
var people = flow.get("people") || {};
var kv = msg.payload.split(",");
people[kv[0]] = kv[1]; 
flow.set("people", people);


I was reading on the Home Assistant Forum the other day about a new module someone over there has released that solves a lot of the Presence/Away options with detection using BLE and mobiles.

Interestingly he has written the whole thing as a bash script that will run on as little as a Pi Zero W - you might want to check it out as it could be good inspiration or maybe just something to call through an exec node


1 Like


Thank you Craig, interesting reading and idea.
It seems to be very personal perception regarding speed of detection, distance, response, price, etc. mentioned in that thread.
For my case, detection of wifi presence is the cheapest, reliable, fast (less than 10 sec), and short-distance method. I just have one more hardware trick to add to software solution: one must touch something to open a door and off the alarm.



Yep there are tradeoffs - but the take away is that if you are trying to use Presence detection for critical things such as door locking when leaving a house etc then you had better get it right. This guy has gone through a lot of iterations (after building on a fairly robust solution that everyone in HA was using for a long time).

The beta testing he has done with a group of early adopters seems to have found and isolated most of the edge cases where people are normally tripped up




Just a heads up that many (including myself) have had problems trying to use ARP with mobiles for this purpose. Generally it has just not worked well. Firstly nowadays phones do not connect to the wifi quickly on coming into range if they have not been used for a while, it can take minutes for this to happen, this is a battery saving feature. Secondly the phone will disconnect after a while of non-use (also battery saving). Thirdly because ARP may not be quick to respond to changes as phones come or go.



This is absolutely true. I run customised ARP and other checks on mobile devices and they are terribly unreliable.

You need NFC detection or physical buttons for reliability. NFC tokens can be reliable.



With an android phone, it is often possible to use the cell id of your "home cell" (and also to detect almost certainly your absence).

Entering the home zone, triggers a wifi scan, so it would waste battery only for a few least for me, it works. Also, i improved this approach with rssi analysis and motion detection, so that the door unlocks, when i'm only 2-3m away (i hope :).



Home cell might cover a couple of km. Depends on the cell service frequency and whether you are in a big city or a rural area. Triangulating cell id's would work better if you have access to the data. I'm guessing that would only be possible on (hacked?) Android devices.

Not sure how quick that happens on some devices. Might depend on configuration.

Only useful when the phone actually wakes up.

Yes, I use a magnetic door sensor and PIR detectors.

I gave up on presence detection other than these 2. I think that, if I were serious about it, I'd use NFC with tokens attached to people's keyrings.



Not sure what your home network products are, but if it’s of interest - I’ve achieved something similar with my UniFi set up, as there’s a dedicated UniFi node for NR that can be used to make API calls to the UniFi controller, where all clients are registered.

This allows me to search for family members by their device name, Mac or IP address

Also as the UniFi provides me with a VPN too, I use NR to notify me if anyone connects remotely.

There’s loads more I could probably do, based on the amount of information returned, but sadly my NR skills are still developing :grin:



Ah, I'm glad you reminded me of that, I need to try it now that I have my Pi3 set up as I now run the Unifi controller on that.



I’ll love to see some of the flows you come up with .

I had started this thread ( Flow example for UniFi node) to try and gather more examples, so if you are up for it, it’ll be good to create a resource for others.



I assume that even using UniFi you are reliant on the phone being connected to the wifi. Therefore again when the phone disconnects after a period of non-use it will not be visible, and after being away from the home then on return it may not reconnect for some time.



This works on android devices running tasker, automagic and maybe more. No need for a "hack".

As soon as the phone changes the active cell, it triggers the event in automagic.

Why do you think that?

This requires you an additional item carrying around.
Also you have to install an NFC reader outside (or use an expensive long range reader).
And for things like opening the garden gate or lights on approach, nfc does not work.



With so many background tasks running on these devices nowadays, I’m not seeing much fall off the network. And if they do, it’s not for very long. Certain times might be more, e.g when the phone is put in to do not disturb, or if the low battery/save process kicks in.

But for me it is just one of my checks, I have motion sensor too, that at tell me if someone is moving in the house, sockets to tell me if certain appliances are on and also when the house alarm is disabled/enabled it will record who did it and lets me know. Plus the house has cameras too that can send a photo when movement seen

Not perfect by any stretch, still very much a work in progress - but it informs me of data that can allow me to make a good guess - and much of my focus is just on identifying someone when they are first seen..



For me this seems to vary quite a bit with phone types. Some seem more aggressive than others in switching off wifi. Also it has got more aggressive with later versions of Android (don't know about Apple phones at all).
I have just carried out some tests (using ping to the phone) on my Moto G5 running Android Oreo. I woke it up to make sure it was connected then left it alone, not in do not disturb mode.
After 4 minutes it disconnected.
Five minutes later it reconnected for six seconds.
Thirty seconds later it reconnected for four minutes.
Six minutes later it reconnected for five seconds.
Ten minutes later it reconnected for six seconds.
Fifteen minutes later it reconnected for five seconds.
and so on. As you can see, using this to determine whether I was in the house or not would not be very satisfactory.
Out of interest I am going to leave it logging overnight to see what happens.

1 Like


Thanks Colin,

Those timings are interesting to see, and make sense, if there is no activity going on (why check so often). It’ll be interesting to know how much you have running on that device, and also how often it is getting push notifications too, which could spring it back to life.

When it comes to identifying people, there was a post a while back that was good - Tracking a Mobile Device - which (putting the tracking part to one side) shows you how owntracks can help to provide another information point to let you know who is around. (Battery life due to regular check ins - is never good.)



Ah, I think I meant to say iOS! Not everyone uses Android. :slight_smile:

RSSI is a measure of wireless network signal. Most phones turn off wireless when sleeping so, by definition, there will be no RSSI. If there is, the phone must be doing something clever to keep part of itself awake.

Not so on my iPhones.

I've tried Owntracks too and some other 3rd-party tools. Best I could get down to was a "fence" of around 100m or so. I lot will depend on cell coverage, phone type, whether you are in an urban or rural setting and so on. To get best accuracy requires more awake time and so worse battery life.

For me personally, these things all add up to something too complex and fragile to bother with. I do report device activity to MQTT but I'm not doing anything with it right now. Plenty of other projects to keep me busy, I'll doubtless revisit at some future point.

Interesting thread though and gives me a few thoughts for the future.



Yep and that is the reason that the stuff i pointed to has chosen to use Bluetooth for location rather than WIFI

You can sprinkle as many Rpi Zero W (less than $10) around as you need to get blanket coverage and they talk to each other.

It is quite a complex bash script he has written that does lots of checking and handoffs etc to enable presence and location detection - well worth looking at the script fro some ideas