This is a plugin that detects presence of network devices based on their status pulled from a Unifi Controller. It is based on the Unifi Sensor plugin by @BlueSmurf. It also borrows from @rigpapa’s VirtualSensor plugin. Thank you both for inspiration.
The plugin consist of one main device per Unifi controller/site. The main device handles authentications and polling. The presence detection is done via virtual motion sensors, which are created through the main device UI. With each poll, the plugin checks the status of a device based on its MAC address. If a device is found to be connected during a poll, its sensor is tripped.
Devices timeout value specifies minimum time for which the device has to be off line before the sensor un-trips. It defaults to 300 seconds. This was necessary to detect devices that would in power saving mode turn off their wifi and only check in periodically. Otherwise, if these check ins happened between the polls the device would be considered not present. For example my iPhone, when on low battery (<20%) and NOT switched to power saving mode, will disappear from the network for several minutes.
download following files from https://github.com/imro2/unifi-presence and upload them to your Vera via Apps -> Develop apps -> Luup files.
After upload, go to Apps -> Develop apps -> Create device, fill in following values and click create.
- Upnp Device Filename: D_UnifiPresence.xml
- Upnp Implementation Filename: I_UnifiPresence.xml
You’ll need to reload the Luup Engine and refresh your browser before the device will appear in the UI.
Create a separate local user on your Unifi Controller for Vera to use, do not use your main Admin account. I had problems creating a user, in the new UI, without a confirmation email being sent. However temporarily switching to the old Unifi UI let me do it.
In the UI for the device, go into the Settings tab and provide the information needed - it should be self-explanatory.
After that go to Virtual Sensors tab and add new child devices using the Create Virtual Sensor button. When you click the button, wait until the new device appears in the list above. Once there, fill in the MAC and possibly rename the device by clicking on its name. Wait a minute for first poll to occur, after which you should see a time stamp under Last Update.
The parent device icon will show Green if you have at least one virtual sensor with a MAC address configured and the sensor was able to successfully authenticate with the controller.