Best Presence detection

Kai has put up a blog post on Smart Home Day.
Last presentation is on presence detection.

Oh, and FIND is to become part of openHABian.

@andreaslink-de

I also moved to using ESP8266 sniffer (Wemos D1) and it seems to work pretty well (better than the network binding as far as I can see). I did the following changes to the code:

  1. Moved to use REST API instead of MQTT
  2. The sniffer first get all items tagged with [“Presence”] from openab and only for those items it send status.
  3. Flag to lock to channel of router so detection is faster (no need to scan all channels).
  4. The sniffer sends the notification directly to the item and not via proxy item.

Ok, that sounds pretty cool, (sorry I did not respond earlier to your former comments, as I was lying ill in bed some days), is there anywhere the source available, where I can see your improvements/changes?
And did you fully delete MQTT or did you just add the REST API in addition? I really would like to add your improvements to my solution, but still stick to MQTT here.
I like the idea of the channel-lock, but I’m a little concerned, if this will work in all cases? As I have several access points split over my house and they are all working on different dedicated channels, will that be caught by your setup from point no. 3? So the same device can switch channels while moving through the house.

@andreaslink-de

I have removed the MQTT support. Probably it will make more sense to support both but because I need to query the items via REST API I didn’t see any point to keep the MQTT (as I already have HTTP support).
I will send you my code and you can take the parts that you want and maybe integrate them into the MQTT version.
Currently the lock is done to the given SSID. It shouldn’t be hard to add support for more then one SSID.
Note that the lock is for “friendly” presence. I also plan to add extra wifi sniffer for “intruders” which will scan all channels.
Another enhancement can be adding some openhab items that will be used to configure the sniffer. This way after sniffer boot / reboot, it will access those items for configuration.

1 Like

Just looking into FIND, looks impressive. Seem to have it all running, but can’t get the simple bit of logging the information to an openhab item to work.

The docs give this example for the item:

String mqttfind_johndoe "John Doe is @ [%s]" (All) {mqtt="<[find:YOURGROUP/location/USERNAME:state:JSONPATH($.location)]"}

I’m getting state = “JSONPATH($.location)” when using this. I’m guessing there’s just a syntax error, but I’m not sure what it is?

Just answered my own question, I needed to install the JSON transformation

moring sir, I’ve try your sketch, it seems working, however the serial console and mqtt pops up lots of MAC address, something like this:

{"MAC":{"106682813de4":"OPEN","f42853370d4c":"OPEN","d8150d5d83f4":"OPEN","6cb0ce1f6fe0":"OPEN","8cf228054b5a":"OPEN","ec26caffec22":"OPEN","206be76f1f4d":"OPEN","c83a35452ae8":"OPEN","f428534c3588":"OPEN","f428533eb0d4":"OPEN","c83a352d3918":"OPEN","d0fa1d6a8dd9":"OPEN","503aa0a85b6e":"OPEN","c061180a3c70":"OPEN","f4285347e09c":"OPEN","503aa09306f2":"OPEN","246968009426":"OPEN","44975a67d92c":"OPEN","3496727abaa3":"OPEN","8cbebe26d1b9":"OPEN","64098069dbd8":"OPEN","88259364c0fe":"OPEN","3496723e9bea":"OPEN","5c63bfc7e3ac":"OPEN","f4cb520a5378":"OPEN","5001d93bda04":"OPEN","349672f8dfcc":"OPEN","8cbebe289e0c":"OPEN","f0b42943d41e":"OPEN","bc469931ca50":"OPEN","30fc68ae9b74":"OPEN","02fc68ae9b74":"OPEN","487d2e1ac55d":"OPEN","c88d83b5059c":"OPEN","b827eb0fc3fd":"OPEN","600194989ee1":"OPEN","f42853370d48":"OPEN","0c9160868b90":"OPEN","106682813de3":"OPEN","ecfabc877cab":"OPEN","eccb3036b804":"OPEN","60019499ac7d":"OPEN","b43052792998":"OPEN","48a9d25ba1f4":"OPEN","9c443d3a36a3":"OPEN","48a9d2409b5c":"OPEN","8cbebe26d1b8":"OPEN","5001d93bd9fb":"OPEN","844bb7025b70":"OPEN","00e04c06bec7":"OPEN","30749619905c":"OPEN","8c89a502573c":"OPEN","60019485b594":"OPEN","2c3ae837d6be":"OPEN","7c7d3da53894":"OPEN","683e34e27eb0":"OPEN"}}

What’s that? Does these super long MAC addresses are all my neighbor’s wifi router? or, these just my local wifi’s devices?(cuz I think that’s too many, I don’t think I have such this amount of devices connecting to my wifi router, I think it’s 64 devices…)… so the question is, what are they? How to get rid of them? What’s Device DB? I think this amount of devices is coming from the Deivce DB?

Connecting to 'mywifi'
.....
WiFi connected
IP address: 192.168.0.42
Connecting to MQTT... connected as ESPClient-8878523

Number of devices: 66
{
  "MAC": {
    "106682813de4": "OPEN",
    "f42853370d4c": "OPEN",
    "d8150d5d83f4": "OPEN",
    "6cb0ce1f6fe0": "OPEN",
    "8cf228054b5a": "OPEN",
    "ec26caffec22": "OPEN",
    "206be76f1f4d": "OPEN",
.......(many mac address....)

Also, I think the codes is getting the beacons even far away from my house(I even get the car driving recorder coming from neighbor’s… lolz…)

Can I add my devices to the list(or I should say the DB) instead of a super huge amount of “scanning ap mac” keep flushing my mqtt server every few seconds?(It’s very huge…)

@kevinshane

Have you tried setting the

#define MINRSSI -150

in WiFi_Sniffer_OpenHAB.ino

to -90 or -80? If the code works as I would expect, the list should be considerably shorter then.

Oh, that sounds great so far, there are two major answers for this, one could be to reduce the default MINRSSI value as this sets the minimal strength, when a detected beacon is taken into consideration, so this equals somehow the distance to the device.
Or the second one is related to devices near by :slight_smile:, if you have of course multiple devices (e.g. a flat in a big crowded house), than this is the explanation (remind there are a lot possible devices, like every phone, computers, webcams, sometimes printers and so on), but if at least one of the devices is an Apple iPhone or iPad and this device is not connected to any(!) wifi network, each sent beacon is sent with a random MAC. This can also pile up entries a lot. Usually everybody has his phone connected to at least his home wifi spot, so this should not be a concern, but could lead to a high amount of fluctuating random devices, if not.

Another solution could also be, to modify the code to only filter on a specific set of MAC addresses.

That would work, thanks man!
I also set the channel to only 6, which I can limit my router channel to also 6 so it only shows every device connected to channel=6, this will greatly shorter the device list down to very few… previously if I do nothing, I can get 100+ devices around me. ^^

Thanks man, could u please open issue page in your github page? I would like to send issues but I can’t find the issue page, thanks!

Also could you please describe how to filter on a specific set of MAC addresses? Can I also be able to filter down to only shows the currently connected devices in my local router?

btw thanks for your hard work, the codes are working very stable, goog job sir ^^

I believe the term “Presence” takes on multiple levels of granularity, which could be serviced by different techniques;

  • Intra-building: Within a room in a building (e.g, FIND, bluetooth beacon, or similar). If facial recognition is to be considered, it invariably should be enhanced by tracking via Kalman filters (or similar) which would benefit very significantly from tracking the head (front or side) and upper torso of any individuals that have been facially recognized (as actual facial recognition events may be few and far between). This requires cameras in many (if not most) locations in and around the building, and is a fairly complex solution. I had made progress in this direction until a lightning strike knocked out my system and I rediscovered life outside of OH.
  • On Premises: Inside or within a very short distance of a building or other finite location (e.g, geofence of 7 to 50 meters from building/location boundary, depending on location ‘footprint’ and urban/suburban/exurban density considerations). Phone WIFI presence could work here.
  • Near Premises: Within some end user definable distance as ‘near’, in order to identify when a person is approaching/leaving home for purposes of HVAC control, outside light control, setting security system mode, etc. There could be multiple geofences of differing distances for different purposes (as HVAC control may need more time to ramp up, as one example) 0.5 to 3 kms might be such example distances, with the aforementioned urban/suburban/exurban considerations. Owntracks or other solutions could work here
  • Away: Anything considered beyond ‘Near Premises’. Owntracks or similar could work well here. There could also be multiple such levels, if purposes warrant.

So Presence could be an object with the attributes 'location" and “time”, with the location attribute defined by rules that focused on the most granular location systems first per their availability.

Timeliness is another important aspect, as different User Stories have differing needs. Knowing the presence of a person with respect to whole house HVAC or security mode settings only requires knowing within a 10-20 seconds that a person has entered or exited a zone. Lighting or ‘following’ music, as two examples, would be expected to react within 1-2 seconds. Zone/room HVAC would be expected to react within 5-10 seconds, though behavior interpretation via video analytics (such as recognizing that a person just sat down) would be highly preferable to preclude starting up a system to respond to a person who walks into a room, picks up something, then leaves (which has obvious HVAC efficiency penalties). One could take this to extremes, of course, so it goes without saying that understanding the actual need should drive any system analysis of alternatives and corresponding architecture.

Hence, “Best Presence Detection” may likely be a combination of techniques tailored to the specific circumstances and objectives.

(have created a new thread for purposes of the larger context of Presence discussion)

1 Like

hi, I have got the script installed, ESP device working, listing clients and beacons,Have seen the Connecting to MQTT on the Serial console, mosquitto installed, MQTT failed with state -2, im guessing user/pass, not that ive seen them in the .ino, comments appreciated

Yeah that’s what its usually been whenever I’ve seen that error. As long as you’ve got your mqtt broker set to require a password, the mqtt .connect function in your arduino sketch should take username and password arguments from memory.

Did you make the non sensitive parts of this code available ?

Hi guys, I was also using Andreas’ version of the wifi sniffer. I couldn’t get it to work stable (crashes) on my esp so I made some changes to the code.
For me personally it was also a nice small project to test developing something on a ESP using platformio/vscode.

Because it is running stable for a couple of months now on two ESP’s I decided to push the code to github.
Maybe it is also useful for somebody else.

3 Likes

Hi @normaniac,

I’m not sure how I should configure this self defined URL. As of this moment I wrote a simple PHP script which does return the post request. this is stored in a free webhosting environment. When testing webhook posting in Geofency I do get a message that it was succesful, along with correct data. This data however is not present on my website. What did you use to store the webhook’s data?

kind regards

So a general question on presence that I’m struggling to find a neat solution too.

I have motion sensors, cameras, Bluetooth beacons, phones etc - like everyone else.

I’m trying to create a simple ‘generic’ set of rules for presence, ie ones that don’t require me to have to put specific apps on phones or spend 5 minutes adding a devise ip / Mac to my router when a guest arrives etc etc etc.

I get the wasp in a box methodology and see a lot of benefit in it from a ‘someone must be home’ point of view but how do people determine between a family member / guest / unwanted guest? For example if I assume front door sensor opening and movement in my hallway is someone home, surely it could be a burglar, and all my system has done is unarm everything and even turn the lights on for him if it’s dark…might as well get it to roll a red carpet out!

What logic do people add to negate this?

I have static DHCP leases for my “authorized” people, it does stink if they change phones as you have to maintain this until the end of time; however they are members of groups and based on that the house can be “armed/unarmed” and notifications can be sent out based on what you want to know about happening.

I took this approach with some family members who are left in charge of my house and I like knowing their coming and goings without them having to send me updates; as one time I discovered the person in charge went all the way back home and back to my house without notifying me. I wasn’t upset as they are an adult but at the same time I wasn’t thrilled they left for two plus hours without an FYI.

I’m going to be putting in a rule soon for my door/light rules to be sent a telegram if my “armed” system has a sensor updated when no one is supposed to be home; just never seem to have enough time or brain power by the time I get to do things I want to do. :confused:

If security is your top priority, then I would suggest that your alarm system should be manually armed and disarmed, rather than automated for convenience. Then, your only concern is that all of your family members (and guests, when necessary) know how to arm/disarm the system. It reduces the highly unpredictable human element to a single variable, and doesn’t require anyone to always remember their phone, tag, or whatever else they need to have on their person to identify themselves as coming or going. More importantly, it reduces the risk that the alarm won’t go off when an intruder breaks in due to some unforeseen set of conditions.

Also, I like knowing when I’m in the house that the alarm is definitely off, and won’t accidentally sound off due a perfect storm of presence-detection failures.

1 Like