Best Presence detection

Just make sure you’re not using a 4.3 or 4.4 android, as their Bluetooth doesn’t play nicely long term with ibeacons

@masto182 I’m using IFTTT binding to track presence by location on my Android phone and my wife’s iPhone. I’m also able to track connect/disconnect on home WIFI on the Android but not the iPhone using IFTTT.

I had been using Openpaths but it was wildly inaccurate in positioning and as of late the site is unresponsive making it useless.

Just because a binding isn’t officially built for OH 2 yet doesn’t necessarily mean it won’t work. There is a compatibility layer which should let any OH 1 binding work with OH 2. If it isn’t listed as supported it mainly means no one has tested it.

But as others have mentioned, I too found Owntracks to be a bit inaccurate and on my wife’s phone I couldn’t keep it up and running all the time. I also experimented with IFTTT but I found similar reliability and accuracy issues with it.

I personally use a combination of the Network Health binding (requires static IP assignment to the phones) and some bluetooth dongles and a python script running on my OH server and my remote Raspberry Pis which detect the presence of my or my wife’s phones (requires BT be on the phones). Bluetooth doesn’t propagate through my entire house so having the BT detection on each floor gives me full coverage.

I am able to statically assign the phone’s IP through the router and we both keep wifi and bluetooth on all the time so these restrictions are not onerous for us.

I’ve found the newer the BT dongle, the better the python script is at detecting the devices (the Pi 3 is a champ). I’ve also found that Network Health often will lose the iPhone which is caused by something related to how the iPhone sleeps the wifi when the screen is off.

If you have motion sensors and/or door sensors the wasp in the box may work well to deal with these intermittent detections.

Over all this approach works about 95-99% of the time. And when something fails with presence detection we know about it because alerts get generated every time a door is opened.

4 Likes

@steve1 Thanks for your advise, It prompted me to look further into the iBeacons, this seems like a really great solution. What iBeacons do you use? I came across an article on how to create some DIY beacons that might work in places I can hide them. But for other area’s I might want a nicer looking commercial beacon.

Have you used long range beacons, I saw some that claim up to 250 meters which might help to get a detection earlier for things like opening a garage door.

Hi @normaniac

This sounds really interesting is this based on some of the work done by dreamgreenhouse? regarding the algorithm what sensors do you use and could you point me to any reading or code that would help me start designing my own wasp-in-a-box-algorithm?

Hi Steve are you able to use Owntracks with OH2? (I had thought the binding wasn’t yet available because of this thread New binding for mqttitude / owntracks) Have you worked around this?

Hi @masto182, no, it’s just an algorithm, so no special product is used.

It works just like that:
1.) openHAB registers a person inside your house and all “outer” doors are closed.
2.) As long as these doors keep closed, no person can escape your house, so they must be present - regardless what sensors tell (broken network health, ibeacon doesn’t work, no movement, wrong gps data).
3.) As soon as a door is opened, someone could leave the house.

So, in my case, I have two presence switches, one for my wife and one for me. If we are at home and our front door (we just have one way out) is closed, openHAB will keep these presence switches ON for as long as the front door is closed. Even when one of our phones gets a bad gps signal and thinks, it has to leave the geofence. It would tell openHAB someone is gone, but openHAB knows better and ignores that.

Some of our presence items:

Group:Switch:OR(ON,OFF)   Presence                        "Präsenz"				<icon_presence>		(All)

Group:Switch:OR(ON,OFF)   PresenceNorman                  "Norman"				<icon_presence_norman>	(Presence)
Switch                    PresenceNorman_PhoneWifi        "iPhone WiFi"				<icon_iphone>	        (PresenceNorman)	 { nh="xxx.xxx.xxx.xxx" }
Switch                    PresenceNormanWasp              "Norman Wasp"				<icon_presence>		(PresenceNorman)
Switch                    PresenceNormanGeofence          "Norman Geofence"			<icon_gps>		(PresenceNorman)

And here are some very simple rules:

rule "Frontdoor closes"
	when
	         Item Frontdoor changed from OPEN to CLOSED
	then

        // We wait 1 minute to make sure that the phone
        // is far away by then and can't be registered
        // by network health before actually leaving.

        Thread::sleep(60000)
        sendCommand(PresenceNormanWasp, OFF)

end


rule "Norman leaves"
	when
		Item PresenceNormanGeofence changed to OFF
	then
	
        if (PresenceNormanWasp.state == ON)
      	 {
		sendCommand(PresenceNormanGeofence, ON)
	 }
end


rule "Norman presence detected"
when
    Item PresenceNorman_PhoneWifi changed to ON
then

	if (PresenceNormanGeofence.state != ON) // just in case
	 {
		sendCommand(PresenceNormanGeofence, ON)
	 }
	if (PresenceNormanWasp.state != ON)
	 {
		sendCommand(PresenceNormanWasp, ON)
 	 }
end
5 Likes

Nobody are using tasker for that? Because I do, and it’s pretty simple, and it’s working great! Just create an item for each phone to detect:
Switch myPhone Switch wifePhone ....
And use tasker to send “http get” to update phone present status to ON, when the trusted wifi connect. When the trusted wifi is disconected, tasker send an update, present status to OFF. The important thing is that you need a stable, rock solid, wifi connection. After that, you can do anything using a simple rule. No need for a binding, like network health constantly using your controller ressources.
Hope it’s help someone! :smiley:

Tasker is Android specific , correct? The challenge I have is a mix of android and apple phones in the house. Also, I prefer a system that is not dependent on any applications on the mobile device itself.

Similar to @tpmcleod24, our family is both iPhone and Android and I refuse use a different approach for the two.

Furthermore, I am against implementing something central to my home automation on my phone. I’m OK with using my phone as a token to aid the home automation but I don’t want the logic to live on the phone itself. It’s a personal preference and not really technically driven beyond the fact that we are a mixed iPhone and Android house so I’d have to figure out two different ways to do it (yuck).

If your controller is so resource constrained that running NH is a concern, you need to be running OH on something better as you will be facing more problems than pinging a few IPs once a second.

1 Like

@Tomtibo How do you get your phone to update openhab via rest over the mobile network? I can only query REST or send a command from my local LAN. I actually like that behavior from a security position, but i’m guessing how ever you set yours up allows you to limit with external devices can access REST?

I agree with @rlkoshak, the logic probably shouldn’t be on the phone. We go through phones like it’s a job. I wouldn’t want to constantly reconfigure presence when ever a device dies or is upgraded. As it is currently I’ll have to change a mac address on my DHCP server and the new phone will just slide right into place.

Like other’s I use a combination of my alarm panel status, PIR’s, and the network health binding to drive the wasp in a box algorithm. However, i do this based on groups. I have the triggers for each user in user specific groups and the groups drive a presence switch for each user. Each user switch is a part of a larger group for the whole house. I exercise the same logic for the rooms in my house. For my presence in practice, I only need any one trigger from my group to turn on so my presence switch can be turned on, my presence switch turning on will turn on presence for the whole house. All my triggers would have to go off for my presence switch to turn off. On the other side, any one trigger for any room will turn that rooms presence on, that room going active will turn on presence for the whole house. In the event that someone forgets a phone at home or a TV is left on (they’re triggers also), an alarm panel status of away overrides and supersedes everything as you can’t occupy the house if the alarm is set to away (there isn’t a PIR blind spot in my house) and we’ll never be hanging out outside in the yard or something with the alarm set to away.

Although i’m not using user specific scenes and setting just yet this is the foundation for that. It also allows for more granular presence modes. For example, A less secure house mode if my wife and/or myself is detected, if rooms are active and we’re not detected (assume we have house guests or a baby sitter and keeps the security a little higher(keep the cameras on or something)), etc. Since it’s kind of a modular design I can get as granular as needed. For example, if only 1 of 2 or more triggers are active for a user OH could suspect that the user is present and do things a little differently than if 2 of 3 or more, or all triggers are active then the user is absolutely present.

I’m still building on all of this but so far it’s working out great and again because of the modular design I can add and remove triggers at any time by modifying the group members. For instance i’m currently working in owntracks as triggers and it’s working out pretty well, and with the manual vs auto modes owntracks provides at least 2 triggers per user. Blu-tooth is next, but it’s being a pain in the ass…

1 Like

There are two approaches that don’t require a reverse proxy. Either you punch a hole in your firewall and subscribe to some dynamic dns service or you access it through my.openhab.

In either case openHAB supports Basic Auth so you can supply the username and password (e.g. https://user:password@url:port/cmd?itemName=ON).

While I don’t want main automation logic on my phone, I have no problem using Tasker to control my home. In this case I have a Tasker generated dialog that pops up when AutoLocation detects I get close to home. If I say yes it sends the command to OH to open the garage. My wife prefers to push the button so the mixed devices problem doesn’t pop up.

Eventually I may set up a reverse proxy and authenticate with certs instead of user/password, but I’ve bigger fish to fry before that.

I do something very similar though probably a lot simpler overall. Since I only use the presence of phones as a proxy for presence of people (I don’t have an alarm or PIRs or anything like that so it’s all I’ve got). So I have a group for my wife’s phone and a group for my phone. The groups are configured to be ON if any one switch in the group is ON. I mainly have these separated by person groups for debugging purposes.

I then have another group which includes all the presence Items configured in the same way. This one actually drive the house.

Where I diverge slightly is I added a five minute timeout before the house will really go into all away mode. This is a kind of low pass filter to deal with cases where I may be in the backyard and jumping in and out of range of the wifi and BT. To do this I have a Switch which is the house’s actual Presence state. It only gets set to OFF five minutes after the Presence Group goes OFF. If the Presence Group goes ON before the Timer expires the house stays in home mode.

I have one exception. If the Presence Group goes OFF and a door is open, an alert is immediately sent. It doesn’t do me any good to get an alert five minutes down the road that I left the back door open.

I also have a switch where I can manually disable the Presence for cases when we have house guests who may be in the house when the rest of us are not.

And, by using Groups like this the whole logic fits on one screen in one rule.

I call this whole approach Group and Loop in the Design Patterns post.

I wrote an external script and a fellow OH enthusiast updated it to work better to do BT detection. It works fairly well, though it works better with newer BT dongles (works phenomenally well on the Pi 3) than older BT 2 and BT 3 dongles.

2 Likes

I use a PfSense rooter witch include a VPN server. So wen I leave home, tasker auto-connect my VPN and then update myPhone item to OFF. You could use a port fowarding setup but, it’s way less secure, because it expose your controller to the internet! I think the VPN is a more secure way because it’s strongly encrypt all communications from your phone, to your home, and it’s like if you are alway at home. :slight_smile:

2 Likes

Sorry I did’t know that Tasker was Android exclusive. That’s bad. :anguished:

Keeping thinks low on the controller is not the only reason why I’ve switch from NH to Tasker. I’m not linked to a security system, at least for now, so I can’t do a wasp-in-a-box-algorithm and using NH alone fail sometime. Probably because of some sort of sleep mode on the phone. Also, I ask a network security expert : How would you hack in my house? (When using NH) He said: Easy! The wifi can be craked! And when your in, you just need to emulate the MAC adresse to unlock your home. :confused:
Sure I am not a network security expert, and i’m not sure which way is better, but It’s worth the time to think about it, because your phone, could be the key of your home (with a good lock-screen of course). :wink:

@sc1982 I bought a DSC alarm for my new house and was also thinking of implementing an override switch into all rules triggered when the alarm is deactivated by the alarm panel. As I need to provide my wife with an easy way to over ride things. she often ignores me when I explain how things will work… either that or she listens and does the opposite, lol. She will actually be a fantastic destructive tester of my automation solution.

Anyway it looks like your actual system is year ahead of even my thinking. Would you be able to share some of your rules or configurations? It love to implement some of this logic myself.

In regards to the security, what your friend told you is true whether you are using the network health binding or not. If your locks can be controlled from a computer that is on your wifi what he described is possible. Frankly, whether or not you are using network health is irrelevant. It’s the fact that your locks are wirelessly controlled that is the security risk. BTW, I am a security expert by trade. An attacker doesn’t need network health to be running to break into your wifi and they don’t need it to spoof a trusted device and unlock your doors. It’s a complete non sequetor.

Setting your locks up where they can be controlled from your phone is the source of the security risk. But it isn’t because of your phone, it’s because the locks can be controlled wirelessly so anyone can spoof your phone it your OH server and unlock your doors.

Of course how much of a risk that if and whether you are willing to accept that risk is your decision.

That’s the piece I was missing!!! I didn’t know you can send the username and password like that in the URL. I’ve already created the NAT rules in my firewall for OH so I can access the sitemaps on my phone but even with that I could not get REST to work externally, I guess if I authenticate via the URL it’ll work. I like @Tomtibo approach better. I also have PFsense and I started down the road warrior VPN route but gave up after I realized I couldn’t use REST externally as that was my only driving force at the time. I will revisit this though as i’d like to close that hole in the firewall and the server essentials vpn solution i use is… well… Sometimes I really hate Microsoft!!!

I actually am also using a X minute timer before my presence switches actually turns off and i’m using it for almost all the same reasons. I’m using a modified version of the NH sample rule for presence detection. I’m using a number item as a variable for the timer so depending on the room/person/house mode the timed delay can be virtually anything. Since it’s applied to each technology i’m using for presence seperately i can adjust for the pit falls of each independently. Actually, you helped me with the syntax for that!!! Damn you’re awesome!!!

I found your BT script during my research and I was very interested but it looks like it’s meant for flavors of Linux so I dismissed it as i’m on windows. Am i incorrect in thinking that? When you say it works better on newer than older, how bad is it on older bluetooth dongles? I have a shit ton of older bluetooth dongles because on my previous automation system the plan was to use a bluetooth dongle in each room to help detect presence in that room. Since the range on the older stuff is weaker, in theory, which ever dongle is detecting you should be in the same room you’re in (provided you have the sq ft to make that statement true…).

If your phone is VPN’ed to your home network it should show up as a local device. If you set up OH with EXTERNAL security it will not require user/password for the REST calls.

I wrote it for Linux but there is nothing about it that would prevent it from running on Windows, beyond the generic issues with running Python scripts on Windows in general. I’ve not done so so what if any problems you might face are unknown, but the libraries you need are available for Windows Python. It will print warnings about the lack of some of the other libraries that don’t make sense on Windows like GPIO, but it will still run.

I wish I could quantify that with an answer. I’ve the script running on an old laptop with an embedded BT (BT 3?) and I’ve played around with tuning it and haven’t really come up with settings that reliable detects my and my wife’s iPhone AND detects when the phone goes away (i.e. it will keep “seeing” the phone even after it is gone). I have a BT 2 dongle plugged into a Pi in the basement that has a similar problem only it is even more prone to see phones when they are not really there. The Pi 3, however, and based on reports from the guy who wrote the module and added it to my script, it works really well.

NOTE: The script works by measuring the signal strength the dongle reports between itself and the BT device. It adds a count if the strength indicates it is near and a different count for when it is far or absent. To tune you adjust an if/elit near the bottom of bluetoothScanner.py that compares the far_cound and near_count with each other and a threshold. So you can make it more sensitive to the device being near and less sensitive to the device being far or visa versa.

In practice, even the BT 2 dongle I have reaches at least to the three rooms around the device so it really isn’t great at determining a specific room so much as detecting which floor I’m on (e.g. if the main floor detector and top floor detector is on I’m probably on the main floor). Now you could potentially aggregate the sensor info in one location and which ever dongle in which room has the strongest signal would be a good indicator the device at least is in that room.

Of course that would only work if you keep your phone on you while you are home. This isn’t true for me at least so it would have limited utility though it could be useful to figure out where I left my phone (or the toddler has taken it).

If you want room by room presence detection, and have Android devices (iOS locks down the APIs needed for this program to work), you might be interested in this thread.

1 Like

HA, I think wifes were put on this earth to either ignore us or do the opposite of what we ask of them. You’re very correct in that they make great testers. My wife is completely responsible for the reliability of my automation. All the time that went into error checking, confirmation sweeps, manual and auto over-rides, etc - all because of her! Now when I roll out something new, one of my primary objective is to be able to roll this out without her noticing. 1st - she’s not a geek so she really don’t care, 2nd - she’s not really paying attention to instructions, 3rd - even if she was listening she’ll forget, and 4th - If she doesn’t forget she’d complain about the extra steps. Great automation is automation where no special instructions are needed. The house just auto-magically does what needs to be done around the users before they even realize that it had to be done, and manual overrides look no different than what everyone on the planet already does so instructions really isn’t necessary. However with that said i’m in the process of mentally designing a way to send loaded questions to our mobiles so our yes or no responses trigger an action. Sounds like tasker is where i want to be for that but i’d like it to not be os specific.

To finally get your question (As you can probably tell, in person i’ll literally talk your ear off, it’s who I am, I’ve come to accept it), I’ll absolutely share what I have. I’m all about that shit. I’m far from a programmer so for all I know you or someone else will see it and turn it from okay to F’in awesome. All I ask is if such changes are made share it back so we all benefit. Not to mention that a lot of my rules and such was taken from the samples on the wiki or snippets i stumble across while surfing the forum. Then I changed them to make them work for what I need. I’ll have to post it later or over the weekend as I don’t have access to my system at the moment.

1 Like