1.2.1 • Published 5 years ago

unifi-detect v1.2.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

npm version

unifi-detect

Wifi device presence detection for Domoticz using a Ubiquiti Unifi controller.

Requirements

  1. Node v6 or later
  2. A Unifi controller running
  3. A Domoticz instance running

Install

  1. Create a directory for unifi-detect and cd into it.
  2. Run $:>npm i -g unifi-detect
  3. Obtain the MAC addresses of the wifi devices you want to detect
  4. Create one virtual switch in Domoticz for each wifi device
  5. Create a config.json (see below) using your favorite editor

Configuration

Put a file called config.json in the directory from where you run the command unifi-detect (or specify its location with the -c switch). Contents:

{
  "unifi": {
    "url": "https://localhost:8443",
    "user": "unifi",
    "password": "unifi",
    "idleTime": 60
  },
  "domoticz": {
    "url": "http://user:password@localhost:8080",
    "deviceMappings": [{
      "mac": "00:00:00:00:00:00",
      "deviceAlias": "My iPhone",
      "switchId": "77"
    }]
  }
}
Unifi settingsExplanation
urlUrl for the Unifi controller, no trailing slash
userUser name for the controller
passwordPassword for the controller
idleTimeTime in seconds until a device is considered away
Domoticz settingsExplanation
urlUrl for the Domoticz installation, including name and password*, no trailing slash.
deviceMappings.macMAC address of device to detect
deviceMappings.deviceAliasReadable name of device, only used in logging
deviceMappings.switchIdDomoticz idx-value of virtual switch

Using environment variables

This project uses nconf, with __ as a separator. So if you are passing the config as environment variables on the docker run command line:

-e "unifi__user=unifi"
-e "unifi__password=unifi"
-e "unifi__idleTime=60"
-e "domoticz__url=http://user:password@localhost:8080"
-e "domoticz__deviceMappings=[{\"mac\":\"00:00:00:00:00:00\",\"deviceAlias\":\"My iPhone\",\"switchId\":\"77\"}]"

(remove quotes and escaping inside device mappings if passing env variables in an orchestrator UI like rancher).

* Name and password are required for Domoticz API access even if you access it from addresses that are white-listed in the Domoticz settings.

How to run

Manual installation

To test unifi-detect, just run $:>unifi-detect from the folder where your config.json is, or $:>unifi-detect -c the-folder-with-config-json. If no errors are shown, go into Domoticz to see if the virtual switches you created in step 5 in the installation have been updated.

When the installation has been verified, set up running unifi-detect periodically with cron or some other scheduler. How often depends on how close to real-time you want the detection to be. In my experience, a phone connecting will be pretty instantaneously detected by the Unifi controller. A phone disconnection will take up to five minutes or so before registering. Because of this, running unifi-detect more often than once a minute will probably not make updates faster.

Docker

$:>docker run -d -e "unifi__url=https://localhost:8443" -e "unifi__user=unifi" -e "unifi__password=unifi" -e "unifi__idleTime=60" -e "domoticz__url=http://user:password@localhost:8080" -e "domoticz__deviceMappings=[{\"mac\":\"00:00:00:00:00:00\",\"deviceAlias\":\"MyiPhone\",\"switchId\":\"77\"}]" -e TASK_SCHEDULE="* * * * *" osirisguitar/unifi-detect:1.1`

The image is here: https://hub.docker.com/r/osirisguitar/unifi-detect/

1.2.1

5 years ago

1.0.0

5 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago