Skip to content

UniFi Network Binding ​

This binding provides network management and client presence detection for Ubiquiti UniFi Networks. It is part of the UniFi binding family and requires the unifi:controller bridge from the parent UniFi binding.

Supported Things ​

  • site - A site with connection statistics
  • wlan - A wireless network. Control the Wi‑Fi network and provide easy access via QR code.
  • wirelessClient - Any wireless client connected to a UniFi wireless network
  • wiredClient - A wired client connected to the UniFi network
  • poePort - A PoE (Power over Ethernet) port on a UniFi switch
  • accessPoint - An access point managed by the UniFi controller software
  • network - A network managed by the UniFi controller software.

Bridge hierarchy. All Network things are children of the shared unifi:controller bridge from the parent UniFi binding. The controller bridge holds the console host, username, and password — see the parent binding documentation for bridge setup.

Discovery ​

The binding supports discovery of things connected to a unifi:controller bridge. To discover things, start the discovery process manually.

Thing Configuration ​

All Network things require a unifi:controller bridge as their parent. See the UniFi binding documentation for controller bridge configuration.

site ​

The following table describes the site configuration parameters:

ParameterDescriptionConfigDefault
sidThe ID, name, or description of the siteRequired-

wlan ​

The following table describes the wlan configuration parameters:

ParameterDescriptionConfigDefault
widThe name or ID of the WLANRequired-

wirelessClient & wiredClient ​

The following table describes the wirelessClient & wiredClient configuration parameters:

ParameterDescriptionConfigDefault
cidThe MAC address, IP address, hostname or alias of the clientRequired-
siteThe site where the client should be foundOptional-
considerHomeThe interval in seconds to consider the client as homeOptional180

Here's some additional notes regarding the Thing configuration parameters:

cid ​

The cid parameter is a universal "client identifier". It accepts the following values:

  1. MAC address [highest priority]
  2. IP address
  3. Hostname (as shown by the controller)
  4. Alias (as defined by you in the controller UI) [lowest priority]

The priority essentially means the binding attempts to look up by MAC address, then by IP address, then by hostname, and finally by alias. Once it finds a matching client, it short-circuits and stops searching. Most of the time, you will simply use the MAC address.

site ​

The site parameter is optional. If you leave it blank, the client will appear ONLINE if found in any site defined on the controller.

You may use the site parameter as a filter if you only want the client to appear home if it is found in the site defined in the site parameter.

Additionally, you may use friendly site names as they appear in the controller UI.

considerHome ​

The considerHome parameter allows you to control how quickly the binding marks a client as away. For example, using the default of 180 (seconds), the binding will report a client as away as soon as lastSeen + 180 (seconds) < now.

poePort ​

The following table describes the poePort configuration parameters:

ParameterDescriptionConfig
portNumberThe port number as reported by the switch (starts with 1)Required
macAddressThe MAC address of the switch device the port is part ofRequired

accessPoint ​

The following table describes the accessPoint configuration parameters:

ParameterDescriptionConfigDefault
macThe MAC address of the access pointRequired-
siteThe site where the access point should be foundOptional-

network ​

The following table describes the network configuration parameters:

ParameterDescriptionConfigDefault
nidThe id of the networkRequired-

Channels ​

site ​

The site information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
totalClientsNumberTotal number of clients connectedRead
wirelessClientsNumberNumber of wireless clients connectedRead
wiredClientsNumberNumber of wired clients connectedRead
guestClientsNumberNumber of guest clients connectedRead
guestVoucherStringGuest voucher for access through the guest portalRead
guestVouchersGenerateStringGenerate additional guest vouchers for access through the guest portalWrite

The guestVouchersGenerate string channel is a command only channel that will trigger voucher creation. It has configuration parameters to tailor the vouchers created:

ParameterDescriptionConfigDefault
voucherCountNumber of vouchers to createOptional1
voucherExpirationMinutes a voucher is valid after activation (default is 1 day)Optional1440
voucherUsersNumber of users for voucher, 0 for no limitOptional1
voucherUpLimitUpload speed limit in kbps, no limit if not setOptional
voucherDownLimitDownload speed limit in kbps, no limit if not setOptional
voucherDataQuotaData transfer quota in MB per user, no limit if not setOptional

wlan ​

The wlan information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
enableSwitchEnable status of the WLANRead, Write
wirelessClientsNumberNumber of wireless clients connectedRead
guestClientsNumberNumber of guest clients connectedRead
essidStringWireless Network (ESSID)Read
siteStringUniFi site the WLAN is associated withRead
securityStringSecurity protocol of the Wi-Fi networkRead
wlanBandStringWireless LAN band of the Wi-Fi networkRead
wpaEncStringWPA Encoding of the Wi-Fi networkRead
wpaModeStringWPA Mode of the Wi-Fi networkRead
passphraseStringPassphrase of the Wi-Fi networkRead
qrcodeEncodingStringMECARD-like encoding to generate a QR code for easy access to the Wi‑Fi networkRead

Attention

If you link an item to the passphrase or qrcodeEncoding channel, your Wi‑Fi password will be exposed in openHAB. The password will also be visible in the openHAB event log.

The qrcodeEncoding channel can be used to easily create a QR code to access, for example, a guest network. It contains a MECARD-like representation of the access. This is the notation used in QR codes that can be scanned by mobile phones.

wirelessClient ​

The wirelessClient information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
onlineSwitchOnline status of the clientRead
nameStringName of device (from the controller web UI)Read
hostnameStringHostname of device (from the controller web UI)Read
siteStringSite name (from the controller web UI) the client is associated withRead
macAddressStringMAC address of the clientRead
ipAddressStringIP address of the clientRead
guestSwitchOn if this is a guest clientRead
apStringAccess point (AP) the client is connected toRead
essidStringNetwork name (ESSID) the client is connected toRead
rssiNumber:PowerReceived signal strength indicator (RSSI) of the clientRead
uptimeNumber:TimeUptime of the client (in seconds)Read
lastSeenDateTimeDate and Time the client was last seenRead
experienceNumber:DimensionlessOverall health indication of the client (in percentage)Read
blockedSwitchBlocked status of the clientRead, Write
cmdStringCommand channel: reconnect to force the client to reconnectWrite
reconnectSwitchForce the client to reconnectWrite

Note: All channels with the Write permission require administrator credentials as defined in the controller.

wiredClient ​

The wiredClient information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
onlineSwitchOnline status of the clientRead
nameStringName of device (from the controller web UI)Read
hostnameStringHostname of device (from the controller web UI)Read
siteStringSite name (from the controller web UI) the client is associated withRead
macAddressStringMAC address of the clientRead
ipAddressStringIP address of the clientRead
uptimeNumber:TimeUptime of the client (in seconds)Read
lastSeenDateTimeDate and Time the client was last seenRead
experienceNumber:DimensionlessOverall health indication of the client (in percentage)Read
blockedSwitchBlocked status of the clientRead, Write

blocked ​

The blocked channel allows you to block / unblock a client via the controller.

reconnect ​

The reconnect channel allows you to force a client to reconnect. Sending ON to this channel will trigger a reconnect via the controller.

poePort ​

The poePort information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
onlineSwitchOnline status of the portRead
modeSelectionSelect the PoE mode: off, auto, pasv24 or passthroughRead, Write
enableSwitchEnable Power over EthernetRead, Write
cmdStringCommand channel: power-cycle: Power Cycle portWrite
powerNumber:PowerPower consumption of the port in WattRead
voltageNumber:ElectricPotentialVoltage of the port in VoltRead
currentNumber:ElectricCurrentCurrent used by the port in mARead

The enable switch channel has a configuration parameter mode which is the value used to switch PoE on when the channel is switched to ON. The default mode value is auto.

accessPoint ​

The accessPoint information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
onlineSwitchOnline status of the deviceRead
enableSwitchEnable or disable the access pointRead, Write
nameStringName of device (from the controller web UI)Read
siteStringSite name (from the controller web UI) the device is associated withRead
ipAddressStringIP address of the deviceRead
uptimeNumber:TimeUptime of the device (in seconds)Read
lastSeenDateTimeDate and Time the device was last seenRead
experienceNumber:DimensionlessThe average health indication of the connected clientsRead
ledSwitchSwitch the LED on or offRead, Write

network ​

The network information that is retrieved is available as these channels:

Channel IDItem TypeDescriptionPermissions
enableSwitchEnable status of the networkRead, Write
totalClientsNumberTotal number of clients connectedRead
siteStringUniFi Site the client is associated withRead
purposeStringPurpose of the network (e.g. Corporate, Guest, WAN, VPN, VLAN Only)Read

Rule Actions ​

As an alternative to using the guestVoucher and guestVouchersGenerate channels on the site Thing, it is possible to use rule actions on the Thing to generate, revoke and list guest vouchers. The following actions are available:

  • boolean success = generateVoucher(Integer expire, Integer users, Integer upLimit, Integer downLimit, Integer dataQuota)
  • boolean success = generateVouchers(Integer count, Integer expire, Integer users, Integer upLimit, Integer downLimit, Integer dataQuota)
  • boolean success = revokeVoucher(String voucherCode)
  • boolean success = revokeVouchers(List<String> voucherCodes)
  • boolean success = revokeAllVouchers()
  • String vouchers = listVouchers()

Since there is a separate rule action instance for each site Thing, this needs to be retrieved through getActions(scope, thingUID). The first parameter always has to be unifi and the second is the full Thing UID of the site that should be used. Once this action instance is retrieved, you can invoke the action method on it.

Boolean return values for the actions indicate success or failure.

The generateVoucher(s) actions parameters match the configuration parameters for the guestVouchersGenerate channel. With the actions, these parameters can be controlled in a rule or script. null values for the parameters are allowed, and will set the parameter to the default value.

ParameterDescriptionDefault
countNumber of vouchers to create1
expireMinutes a voucher is valid after activation (default is 1 day)1440
usersNumber of users for voucher, 0 for no limit1
upLimitUpload speed limit in kbps, no limit if not set
downLimitDownload speed limit in kbps, no limit if not set
dataQuotaData transfer quota in MB per user, no limit if not set

The revoke... actions allow you to revoke previously created vouchers. The parameter is the voucher code or a list of voucher codes to be revoked.

The listVouchers action will return a json string representing the currently available vouchers for the site. The json contains all parameters for the voucher, therefore it is possible to filter on these in a rule or script. For example, one could retrieve all vouchers created before a certain time and use the revokeVouchers action to delete these. The structure of the returned json is (depending on content, some fields may be missing):

json
[
    {
        "code": "3867791284",
        "createTime": "2023-01-31T14:40:47Z",
        "duration": 1440,
        "quota": 2,
        "used": 0,
        "qosUsageQuota": 300,
        "qosRateMaxUp": 200,
        "qosRateMaxDown": 100,
        "qosOverwrite": true,
        "note": "I added a note when creating vouchers in the UniFi hotspot UI",
        "status": "VALID_MULTI"
    },
    {
        "code": "0021952641",
        "createTime": "2023-01-31T14:38:47Z",
        "duration": 1440,
        "quota": 1,
        "used": 0,
        "qosOverwrite": false,
        "status": "VALID_ONE"
    },
    { ... }
]

Full Example ​

things/unifi.things ​

Network things are nested inside the unifi:controller bridge from the parent UniFi binding:

dsl
Bridge unifi:controller:home "UniFi Controller" [ host="192.168.1.1", username="openhab", password="secret" ] {
    Thing wirelessClient matthewsPhone "Matthew's iPhone" [ cid="aa:bb:cc:dd:ee:ff", site="default", considerHome=180 ]
    Thing site mysite "My Site" [ sid="default" ]
}

items/unifi.items ​

dsl
Switch       MatthewsPhone           "Matthew's iPhone [MAP(unifi.map):%s]"             { channel="unifi:wirelessClient:home:matthewsPhone:online" }
String       MatthewsPhoneSite       "Matthew's iPhone: Site [%s]"                      { channel="unifi:wirelessClient:home:matthewsPhone:site" }
String       MatthewsPhoneMAC        "Matthew's iPhone: MAC [%s]"                       { channel="unifi:wirelessClient:home:matthewsPhone:macAddress" }
String       MatthewsPhoneIP         "Matthew's iPhone: IP [%s]"                        { channel="unifi:wirelessClient:home:matthewsPhone:ipAddress" }
String       MatthewsPhoneAP         "Matthew's iPhone: AP [%s]"                        { channel="unifi:wirelessClient:home:matthewsPhone:ap" }
String       MatthewsPhoneESSID      "Matthew's iPhone: ESSID [%s]"                     { channel="unifi:wirelessClient:home:matthewsPhone:essid" }
Number:Power MatthewsPhoneRSSI       "Matthew's iPhone: RSSI [%d dBm]"                  { channel="unifi:wirelessClient:home:matthewsPhone:rssi" }
Number:Time  MatthewsPhoneUptime     "Matthew's iPhone: Uptime [%d %unit%]"             { channel="unifi:wirelessClient:home:matthewsPhone:uptime" }
DateTime     MatthewsPhoneLastSeen   "Matthew's iPhone: Last Seen [%1$tH:%1$tM:%1$tS]"  { channel="unifi:wirelessClient:home:matthewsPhone:lastSeen" }
Switch       MatthewsPhoneBlocked    "Matthew's iPhone: Blocked"                        { channel="unifi:wirelessClient:home:matthewsPhone:blocked" }
Switch       MatthewsPhoneReconnect  "Matthew's iPhone: Reconnect"                      { channel="unifi:wirelessClient:home:matthewsPhone:reconnect" }

transform/unifi.map ​

text
ON=Home
OFF=Away

sitemaps/unifi.sitemap ​

dsl
sitemap unifi label="UniFi Binding"
{
    Frame {
        Text item=MatthewsPhone
        Text item=MatthewsPhoneSite
        Text item=MatthewsPhoneMAC
        Text item=MatthewsPhoneIP
        Text item=MatthewsPhoneAP
        Text item=MatthewsPhoneESSID
        Text item=MatthewsPhoneRSSI
        Text item=MatthewsPhoneUptime
        Text item=MatthewsPhoneLastSeen
        Switch item=MatthewsPhoneBlocked
        Switch item=MatthewsPhoneReconnect
    }
}

rule actions for site Thing ​

rules
val uniFiActions = getActions("unifi","unifi:site:home:mysite")
val success = uniFiActions.generateVoucher(null, null, null, 100, 500, 250)
rules
val uniFiActions = getActions("unifi","unifi:site:home:mysite")
val vouchersJson = uniFiActions.listVouchers()
rules
import java.util.List

val List<String> voucherList = newArrayList("38677-91284", "46415-36104")
val uniFiActions = getActions("unifi","unifi:site:home:mysite")
val success = uniFiActions.revokeVouchers(voucherList)