I've created a Unifi Presence sensor that will log into your Unifi controller and check to see whether specified mac addresses are connected, and then update a Hubitat Elevation virtual switch. A virtual switch is currently required, as MakerAPI does not allow modification of virtual presence sensors. The workaround is (old details removed) use Cobra's DH that has both on/off and presence/absence built in. And skip step 9.
Requirements: access to UniFi controller (local works, not sure about cloud controllers), python script (works on 2.7.x, not tested others)
Files are here
- Create a virtual switch for each phone you wish to monitor. Note the device ID of each device. eg; http://Hubitat IP/device/edit/601
- Enable MakerAPI, and select the virtual switch(es) you created in step 1.
- Note the MakerAPI app ID. The three digit number in the address
eg: http://Hubitat IP/installedapp/configure/700
- Note the MakerAPI access token on that page
- Download and save the files (in their final location) on a device that runs python scripts (2.7.x tested). Note the location and enter it in step 6e.
- Edit 'unifipresence.conf', edit the following fields:
6a. Hubitat local IP address inside the double quotation marks.
6b. Maker API from step 3 above, inside single quotations.
6c. Unifi controller IP address (have only tried local, not cloud controller). Include the port number inside single quotation marks.
6d. Unifi user name and password inside single quotations. Recommend to create a user with read only access, as this file records the user name and password for UniFi controller. Leave SiteUniFi as default
6e. Filepath of these files inside single quotations. Two more files are created upon first run of the python script. Enter the path before the filename of the two files. (These files are not yet created, and will be done so at step 8).
6f. (Inside single quotations) Enter mac Address of phone, Device ID (from step 1), and Access token of MakerAPI (from step 3). The Access token will remain the same for each device.
- Edit the python script unifipresense.py with the location of the conffile (unifipresence.conf).
- Run the python script to ensure creation of two files unifipresence.cookie and unifipresence.status.
- Create two rules in Rule Machine for each device to sync status of switch with virtual presence sensors.
- Call/run the python script every 1 minute.
Presence will only update to Hubitat if the python script notices a change. It does not send presence (on/off) on no change.
If presence is not updating, open unifipresence.status to determine if script has checked Unifi controller successfully. File will update with devices connected. If not, check Ip address + port, password, username, location of files.
If presence is updating in unifipresence.status, check HE side of script etc.