Author Topic: Presence Detection  (Read 2860 times)

Offline StormStrikes

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Presence Detection
« on: October 17, 2016, 11:54:49 pm »
Before coming to Vera I was setting up home automation using a system called Home Assistant.  A good system to be sure but it was time-consuming getting everything going, but I did not want to give up automation running locally, which happen to be Vera's feature that convinced me to buy their hub.

One of the super duper nice things about Home Assistant was that I could give it access to my home router and it could detect the devices on the network and I could just tell it which to use to detect when I was home.  It used the MAC address of my cell phone.  Im sure every process has it's pro's and con's, but I like how Home Assistant managed it.

All of that to ask does Vera have any means of such presence detection?  Even some kind of Bluetooth solution would be nice if available.  SmartThings had its Zigbee based presence sensors but they do not show up correctly in Vera.

Anyway, I would appreciate any suggestions/ideas. 

Offline zedrally

  • Hero Member
  • *****
  • Posts: 775
  • Karma: +1/-0
  • Black Cat Controllers & Control Systems
    • Black Cat Control Systems
Re: Presence Detection
« Reply #1 on: October 18, 2016, 01:17:33 am »
Lok in the apps store for Ping Sensor, the more reliable way would be to use it with Geofencing, there are quite a few threads on this.
Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, then some  Black Cat Cat's Eye PIR's & Door-Window Sensors plus a Z-UNO or 2.

Offline StormStrikes

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Presence Detection
« Reply #2 on: October 18, 2016, 03:57:52 am »
Thank you for your reply.  I had been searching for posts on this, but most were related to geofencing and I do not nor like to keep my gps on.  I found the Ping Sensor, but it apparently only allows one IP address.

Offline zedrally

  • Hero Member
  • *****
  • Posts: 775
  • Karma: +1/-0
  • Black Cat Controllers & Control Systems
    • Black Cat Control Systems
Re: Presence Detection
« Reply #3 on: October 18, 2016, 04:03:47 am »
I don't see the problem? The Ping Sensor will detect multiple devices.



Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, then some  Black Cat Cat's Eye PIR's & Door-Window Sensors plus a Z-UNO or 2.

Offline zedrally

  • Hero Member
  • *****
  • Posts: 775
  • Karma: +1/-0
  • Black Cat Controllers & Control Systems
    • Black Cat Control Systems
Re: Presence Detection
« Reply #4 on: October 18, 2016, 05:43:12 am »
My bad..

I should have worded it as use multiple ping sensors as required

Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, then some  Black Cat Cat's Eye PIR's & Door-Window Sensors plus a Z-UNO or 2.

Offline zolakk

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +2/-2
Re: Presence Detection
« Reply #5 on: October 18, 2016, 07:42:56 pm »
I use a script on my router (requires a router that you can run scripts on like DDWRT, Tomato, or similar - I use an Asus) that sets a multi-switch in my Vera based on which MACs are detected on my wifi network. I then use PLEG to do things based on if any of the switches are "on" (phone is home) or not. A bit more involved than a turnkey solution but works well. Here's the thread I followed

Offline dirtbikr

  • Sr. Newbie
  • *
  • Posts: 34
  • Karma: +2/-0
Re: Presence Detection
« Reply #6 on: October 20, 2016, 03:51:29 pm »
I use a script on my router (requires a router that you can run scripts on like DDWRT, Tomato, or similar - I use an Asus) that sets a multi-switch in my Vera based on which MACs are detected on my wifi network. I then use PLEG to do things based on if any of the switches are "on" (phone is home) or not. A bit more involved than a turnkey solution but works well. Here's the thread I followed

Does your implementation work when the phone's screen is off?

OP: I use a Raspberry Pi to keep track of who's home and who's not. We have a household of four so I needed something reliable and fairly quick to pick up so that the house modes would reliably change. The raspberry pi runs a python script every minute (using cron) that scans to see if the phone is within Bluetooth proximity (phone does not have to be paired to the Pi, it just has to have Bluetooth on). If the phone is not found via Bluetooth, it will ping the phone (static IP) and only if that fails does the Pi say that the person is not home.

I feed this information into scenes for *Person* is home or *Person is not home* which flips a virtual switch for that person. I have logic in PLEG that checks the status of the switches, once they are all off for 15 minutes the house flips to away mode. As soon as anyone's switch is turned on the house goes back to home mode.

The python script also writes the home or not home status out to an excel spreadsheet so there is a log of who is in and who isn't, and a total execution time for the script (I've been trying to minimize it. Runtime is about 40 seconds when nobody is home, and as low as four seconds when everyone is home).

The only issue I have is sometimes it will report a not home status when the person really is home. This seems to be worse with Windows Phones than the iPhones in the house, but they all do it from time to time. If zolakk's MAC address method is reliable with the screen off I would love to implement that and make it bulletproof. The whole setup took about an hour to make it work, I'm confident you could make it work as well. Depending on how large your house is Bluetooth works pretty well. I would like to make the system modular so I can install more Raspberry Pis and get better coverage in larger areas, but that would be a lot more code. I can share it with you guys if anyone is interested.

Offline tb001

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: +5/-2
Re: Presence Detection
« Reply #7 on: October 21, 2016, 09:29:25 am »
Dirtbkr, how far is the range on the pi? I'd love a solution to know where in the house people are (we have big dogs, so motion sensors don't work). I wish the ibeacons worked well--this seems like the perfect solution but haven't been able to get them reliable enough.

Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4431
  • Karma: +246/-120
Re: Presence Detection
« Reply #8 on: October 21, 2016, 09:32:08 am »
@dirtbikr - Would you be willing to share your script. I think your solution should one of the better presence detectors, but as you indicated, with its occasional false reports, it should be combined with another option(not ping sensor) to make it more reliable.

Was there a particular reason for using Python? It seems that Bash could probably do it in about 15 lines.

Is your script execution time due to waiting on the Bluetooth scan, or do you have some extensive processing logic? If you're doing something like a hcitool scan, look at hcitool scan --flush --length=n

Your presence detection scheme is one that I use to use with an Asterisk PBX for call forwarding. It was one of the functionalities that I envisioned when the Vera Plus was launched with its Bluetooth radio, but they have completely failed to deliver any Bluetooth functionality at all.


Offline zolakk

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +2/-2
Re: Presence Detection
« Reply #9 on: October 21, 2016, 03:12:27 pm »
I use a script on my router (requires a router that you can run scripts on like DDWRT, Tomato, or similar - I use an Asus) that sets a multi-switch in my Vera based on which MACs are detected on my wifi network. I then use PLEG to do things based on if any of the switches are "on" (phone is home) or not. A bit more involved than a turnkey solution but works well. Here's the thread I followed

Does your implementation work when the phone's screen is off?

OP: I use a Raspberry Pi to keep track of who's home and who's not. We have a household of four so I needed something reliable and fairly quick to pick up so that the house modes would reliably change. The raspberry pi runs a python script every minute (using cron) that scans to see if the phone is within Bluetooth proximity (phone does not have to be paired to the Pi, it just has to have Bluetooth on). If the phone is not found via Bluetooth, it will ping the phone (static IP) and only if that fails does the Pi say that the person is not home.

I feed this information into scenes for *Person* is home or *Person is not home* which flips a virtual switch for that person. I have logic in PLEG that checks the status of the switches, once they are all off for 15 minutes the house flips to away mode. As soon as anyone's switch is turned on the house goes back to home mode.

The python script also writes the home or not home status out to an excel spreadsheet so there is a log of who is in and who isn't, and a total execution time for the script (I've been trying to minimize it. Runtime is about 40 seconds when nobody is home, and as low as four seconds when everyone is home).

The only issue I have is sometimes it will report a not home status when the person really is home. This seems to be worse with Windows Phones than the iPhones in the house, but they all do it from time to time. If zolakk's MAC address method is reliable with the screen off I would love to implement that and make it bulletproof. The whole setup took about an hour to make it work, I'm confident you could make it work as well. Depending on how large your house is Bluetooth works pretty well. I would like to make the system modular so I can install more Raspberry Pis and get better coverage in larger areas, but that would be a lot more code. I can share it with you guys if anyone is interested.
It seems to work just fine for me and my wife (Lumia 950XL and iPhone 6S), screen on and off. It works by querying the wifi client list directly on the router so as long as your phone doesn't disconnect from wifi when it turns the screen off I see no reason why it wouldn't work. Also works for any other wifi devices like tablets too

Offline dirtbikr

  • Sr. Newbie
  • *
  • Posts: 34
  • Karma: +2/-0
Re: Presence Detection
« Reply #10 on: October 24, 2016, 07:44:56 pm »
Dirtbkr, how far is the range on the pi? I'd love a solution to know where in the house people are (we have big dogs, so motion sensors don't work). I wish the ibeacons worked well--this seems like the perfect solution but haven't been able to get them reliable enough.

I'd say the range is ~30 feet or so. It works very well in our 1500 sqft house with the pi directly in the middle of the house on the pot shelf.

@Z-Waver: I attached the script. I chose Python because there was an example online that I used to seed my implementation and I never worked in Python so I figured I would give it a shot. Take a look at it and try it out. I removed the bits that export to the excel file and I removed three of the users so it was less cluttered. (The forums wouldn't allow me to upload a ".py" extension, so I changed it to ".txt")

Offline cleight

  • Sr. Newbie
  • *
  • Posts: 45
  • Karma: +0/-0
Re: Presence Detection
« Reply #11 on: October 24, 2016, 10:09:07 pm »
I use AutoVera and Android Device Monitor. ADM monitors my wifi connection and when I connect to my home SSID it flips a virtual switch through AutoVera. For the most part this is bulletproof. However Home Assistant Ubiquiti Unifi plugin is much more reliable and wish it was available in Vera.

Sent from my Nexus 6P using Tapatalk


Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4431
  • Karma: +246/-120
Re: Presence Detection
« Reply #12 on: October 25, 2016, 08:00:27 am »
@Z-Waver: I attached the script. I chose Python because there was an example online that I used to seed my implementation and I never worked in Python so I figured I would give it a shot. Take a look at it and try it out. I removed the bits that export to the excel file and I removed three of the users so it was less cluttered. (The forums wouldn't allow me to upload a ".py" extension, so I changed it to ".txt")
Thanks for sharing your script. I don't see any room for improvement on it. You're checking if a Bluetooth device is present and then a redundant check via ping, if both fail, then NotHome.

I suspect that many people will start using this. Vera should absolutely be doing it on Vera with a Bash script. Does anyone know if hcitool is included in the Vera Plus firmware yet?

Offline cybrmage

  • Hero Member
  • *****
  • Posts: 1002
  • Karma: +96/-5
Re: Presence Detection
« Reply #13 on: October 25, 2016, 10:23:27 am »
Does anyone know if hcitool is included in the Vera Plus firmware yet?

As for 1.7.2138, yes,.. hci-tester, hci_cmd, hcitool, hciattach, hcidump, hciconfig, bdaddr, bccmd, blumon, bluetoothd, bluetoothctl, ble_tool, btgatt-server, btgatt-client, btinfo and btmon are included in the firmware image.
« Last Edit: October 25, 2016, 10:29:08 am by cybrmage »
EVL3Vista - Wink Connect - Caseta Connect - Venstar Colortouch - WiFi UDP Switch Controller - MyQGateway

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 597
  • Karma: +12/-0
Re: Presence Detection
« Reply #14 on: October 25, 2016, 10:26:25 am »
Does your implementation work when the phone's screen is off?

(Assuming an Android phone) Check that your Wifi setting "Leave WiFi on when screen is off" setting is set. Otherwise, your Wifi will shut down when the screen is off, and Pinging it will not work.