Best Presence detection

Tags: #<Tag:0x00007f618c7b0800> #<Tag:0x00007f618c7b0738> #<Tag:0x00007f618c7b0670>

Hi,

I was wondering if someone could help I’m planing on implementing a few presence detection options I wanted to know if these are still valid methods or if new techniques have been developed that I haven’t yet found or understood.

  • Owntracks, MQTT broker, Mqttitude. (This looks good, but bindings haven’t been built for OH2, so I thought it might not be the favored method anymore)
  • Detection with a DD-WRT Router (controlling switch, no binding)
  • Bluetooth keyfob and detection script running on Raspberry Pi (controlling switches in openhab, no binding)

I plan on using a combination of these to ensure even if my wife’s phone goes flat or she turns her wifi off her presence can still be detected. If anyone has any other presence detection methods I could add to this or advise on better methods please let me know.

Regards
Campbell

1 Like

I’ve been playing with Owntracks and the locations reported aren’t very good, at least when using the Android app. I think in order to save battery it appears to be using the low resolution location provider in Android which relies on wifi and cell towers to determine location which isn’t very accurate. In fact it usually shows me as several blocks away unless I force the GPS on by opening GPS Status or something like that.

I’d definitely look into using some sort of bluetooth keyfob or something like that.

I’ve also used Owntracks with a MQTT broker for a while, but wasn’t fond of the reliability neither. We switched now to an iOS-app called Geofency (another one doing the same is called Locative, which is free). This app sends http-requests with some JSON data to a private and self defined URL protected with htaccess as soon as we enter or leave a geofence. You can create as many geofences as you like. I set up a little script on my webserver for that which notifies openHAB via REST API whenever it get’s triggered. That works very stable and is rock solid so far.

I also check for the devices in the network and make some use of the wasp-in-a-box-algorithm.

No need for bluetooth or any other device like that so far.

2 Likes

The issue with using a phone GPS is the battery consumption if the location is tracked continuously. I had similar experiences with Owntracks and GPS but now I’m using iBeacons with Owntracks and it works much more reliably and quickly for detecting presence in my home (even specific areas of the home), my car, and so on.

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.