Ubiquiti UNMS sensor to monitor your devices on HASSIO

For those who have Ubiquiti Antennas and use UNMS system (not UniFi), I wrote some code in order to monitor antennas status with HA, using sensors.

REMEBER: You need to be registered on UNMS system and have antennas connected.

First of all, take a look to https://<<yourHostName>>.unmsapp.com/nms/api-docs/ (where <<yourHostName>> is the host name used to access UNMS platform)

Our first step is to get the IDs of every device (antenna) registered on UNMS.

To do that we need a token.

To have a token we need to login.

To login, open Authorization section and choose /user/login/

Click on Try it out button and type your userid and password in the model

Click on Execute and go to Header section (after the Body section). You will find x-auth-token: abcdefabcdsdw-4505-87e3-0000000000

The token is the second part of the string, that is: abcdefabcdsdw-4505-87e3-0000000000
This is just an example. You will see your right token.

Copy the token, click on AUTHORIZE button (upper right of the page), paste the code and click Authorize

Click on Device section and choose GET /devices.

Select only the ROLE section (e.g. station) and look at the results. You will find all your station information in JSON format.

You will find many sections of this kind:

 {
    "identification": {
      "id": "blabla-1111-1111-0000-blablablablabla",
      "site": {
        "id": "mySite",
        "name": "myDevice Name",
        "status": "active",
        "type": "site",
        "parent": null
      },
      "mac": "00:00:00:00:00:00",
      "name": "PPPV",
      "hostname": "PPPV",
      "serialNumber": null,
      "firmwareVersion": "8.7.0",
      "model": "NBE-5AC-Gen2",
      "modelName": "NanoBeam 5AC",

The ID of your devices is first id after identification (e.g. blabla-1111-1111-0000-blablablablabla)
Take note of all your devices ID

At this point we can go to HA.

First of all, we need to create a sensor that logins UNMS system and get a token.

- platform: command_line
  command: 'curl -s -m 20 -X POST "https://MYHOSTNAME.unmsapp.com/nms/api/v2.1/user/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"username\": \"MYUSERID\", \"password\": \"MYPASSWORD\", \"mobilePlatform\": \"ios\", \"sessionTimeout\": 0}" -i | grep x-auth-token:'
  name: x_auth_token_ubiquity
  value_template: "{{ value.split(': ')[1] }}"
  scan_interval: 600
  command_timeout: 30

You need to change MYHOSTNAME, MYUSERID and MYPASSWORD according to your account.
This sensor will take a new token every 10 minutes.

The second and last step is to create a sensor for each device. It will be like this one:

  - platform: command_line
    name: My Ubiquiti Device Connectivity
    command: 'curl -X GET "https://MYHOSTNAME.unmsapp.com/nms/api/v2.1/devices/DEVICE-ID" -H "accept: application/json" -H "x-auth-token: {{ states("sensor.x_auth_token_ubiquity") }}"'
    value_template: >-
          {% if (value_json.overview.status == 'active') %} True {% else %} False {% endif %}
    payload_on: "True"
    payload_off: "False"    
    device_class: connectivity
    scan_interval: 60

You need to change MYHOSTNAME and DEVICE-ID according to your account and device id. DEVICE-ID is the ID of the device found before.

This sensor will get connectivity status of your device every 60 seconds.

With the same method you can get any other information about your device (speed, RSSI and so on) and also you can change the parameters using other API.

That’s it!

Hope to be helpful

1 Like

You can also do this locally with SNMP. Enable SNMP on the radios. Then you need to get the MIB files from Ubiquiti: https://help.ui.com/hc/en-us/articles/210391987-airMAX-Guide-to-Enable-Test-SNMP-

Then, from Linux, trying e.g.:

snmpwalk 10.0.0.95 -c public -v 1 1.3.6.1.4.1.41112.1.4.7.1.15.1.120.138.32.60.32.52

gives you the connection uptime (in my case the connection uptime between 2 nanobeam PtP radios):

SNMPv2-SMI::enterprises.41112.1.4.7.1.15.1.120.138.32.60.32.52 = Timeticks: (44216900) 5 days, 2:49:29.00

Then, after finding the OIDs that you are interested in having in home assistant, you can set SNMP sensors:

sensor:
  - platform: snmp
    name: "Nanobeam Link Uptime"
    host: YOUR-RADIO-IP-HERE
    baseoid: 1.3.6.1.4.1.41112.1.4.7.1.15.1.120.138.32.60.32.52
    accept_errors: true
    unit_of_measurement: "minutes"
    value_template: "{{((value | int) / 6000) | int}}"

1 Like