This Presence Sensor has two components - a plugin for Vera that provides a new virtual device type for keeping track of presence states and a Raspberry Pi that does the actual polling and updates the virtual devices as changes are noted. Due to the size of the image, I have made the disk image for the Raspberry Pi available on my website.
The Raspberry Pi image supports polling for known bluetooth devices (gets around iPhones going to sleep) and also continuously searches for ibeacons and can check them against known addresses as well.
The Raspberry Pi sits near the front door in our house and provides coverage of the road outside, our driveway, as well as most of the house. I am using this plugin to monitor my own and my wife’s iPhone and I also have an ibeacon stuck to the windscreen of each of our cars to detect when they are home.
Some experimentation may be needed to find the optimal placement to get the required coverage as the Pi does not have a high-gain antenna for Bluetooth. Better results may be had by using a USB bluetooth adapter with external antenna.
[size=18pt]Vera Presence Sensor Virtual Device Component[/size]
The Presence Sensor Virtual Device was modeled on Ping Sensor and allows the presence or absence of the monitored device to be used as a trigger for scenes or PLEGs. It was written to be used with the Raspberry Pi image outlined below, but should be usable with anything that can send HTTP requests to the Vera unit to update the status (such as apps like Tasker).
To install the plugin, unzip the plugin files and upload to your Vera unit using the Apps → Develop Apps → Luup Files function.
Once the files have been uploaded and Vera has restarted, you will need to create one or more devices. Go to Apps → Develop Apps → Create device. Set Description to the name you want the device to be called (Bob’s iPhone) and the Upnp Device filename to “D_PresenceSensor.xml”
If you are using my Raspberry Pi image, on the settings tab of the device page you need to enter the Bluetooth MAC address of the device you want to monitor and whether it’s a bluetooth device or ibeacon. How to find this MAC address is left to an exercise of the reader - there are numerous bluetooth scanners for both major phone platforms.
The plugin has been tested on UI7. I believe it should also work on UI5, but I don’t have any UI5 systems to test.
The latest version will always be available from my website at [url=https://afoyi.com/software/vera-presence/]https://afoyi.com/software/vera-presence/[/url]
[size=18pt]Raspberry Pi Disk Image Component[/size]
The disk image for the Raspberry Pi will fit on a 2GB or larger MicroSD card and is set up to simply be written to the card and just one configuration setting to be set (the local IP address of your Vera unit). The instructions for writing the image to the SD card depend on the operating system that you’re using, but are identical to the instructions for getting any other image for the Pi installed.
One difference in my image is that after it boots up it leaves the root filesystem mounting read-only and creates a few ram drives to run from. This means that power can be pulled at any time and there is absolutely no risk of corrupting the file system. If changes are needed to be made, there’s a command called ‘remountrw’ which can be run to mount the disk into read-write mode so the changes can be made. Once the changes have been completed, don’t forget to run ‘remountro’ to put it back into read-only mode. As the ramdrives shadow files that sometimes need to be edited (particularly /etc), the root filesystem is bind mounted under /ro - so you can make peristent changes to /etc by editing the files under /ro/etc/ and then rebooting.
Logging In
The image is set up using the standard Raspbian credentials of the username ‘pi’ and password ‘raspberry’. It can be accessed using a USB keyboard and monitor plugged into the HDMI port, or via SSH.
Network Configuration
The image is configured to automatically DHCP an address on the wired ethernet port. If you have a Raspberry Pi 3, or a USB wifi adaptor, it can also be configured to connect to wifi. To do this, remount the file system in read-write mode, edit /ro/etc/wpa_supplicant/wpa_supplicant.conf appropriately and then enable the wifi interface in /ro/etc/network/interfaces.
Vera Configuration
To configure the address of your Vera unit, remount the file system as read-write and edit the python scanner script at /ro/srv/scanner/run_scanner.py. All you need to set in this file is the IP address your Vera unit has on your local network at the top of the file.
Reboot your Raspberry Pi and it should automatically start the scanner script, connect to your Vera, find the PresenceSensor devices and start to poll them.
Updating
The image is using two main libraries to do the bluetooth work, plus my own containing the scanner script. All three can easily be updated using git.
ibeacon-scanner by John Shovic <john.shovic@gmail.com>
[url=https://github.com/switchdoclabs/iBeacon-Scanner-]https://github.com/switchdoclabs/iBeacon-Scanner-[/url]
pyvera by Cyber MacGeddon <cybermaggedon@gmail.com>
[url=http://forum.micasaverde.com/index.php/topic,37927.0.html]http://forum.micasaverde.com/index.php/topic,37927.0.html[/url]
[url=https://github.com/cybermaggedon/pyvera]https://github.com/cybermaggedon/pyvera[/url]
(my fork) [url=https://github.com/daemondazz/pyvera]https://github.com/daemondazz/pyvera[/url]
scanner script
[url=https://github.com/daemondazz/vera-presence-scanner]https://github.com/daemondazz/vera-presence-scanner[/url]
Any of those libraries can be updated by remounting in read-write mode, changing into the appropriate directory under /ro/srv/ and running a ‘git pull’
The full image can be downloaded from my website at https://afoyi.com/software/vera-presence-pi/