Monitor unifi Dream Machine (Pro)

did u setup some influx sensors? i am at the same point here .P

Yes, I got what I wanted, speed and public IP:

- platform: influxdb
  host: localhost
  username: !secret ha-influx-user
  password: !secret ha-influx-pw
  queries:
    - name: Unifi Download Speed
      where: '"subsystem" = ''wan'''
      field: '"rx_bytes-r"'
      measurement: '"subsystems"'
      group_function: last
      database: unifi
      unit_of_measurement: "Mbit/s"
      value_template: "{{ (value | int / 131072) | round(2) }}"
    - name: Unifi Upload Speed
      where: '"subsystem" = ''wan'''
      field: '"tx_bytes-r"'
      measurement: '"subsystems"'
      group_function: last
      database: unifi
      unit_of_measurement: "Mbit/s"
      value_template: "{{ (value | int / 131072) | round(2) }}"
    - name: WAN IP
      where: '"subsystem" = ''wan'''
      field: '"wan_ip"'
      measurement: '"subsystems"'
      group_function: last
      database: unifi

Thanks for sharing this! It was really helpful. I’ve added sensors for CPU and memory as well. Sharing in case they’re useful to anyone else.

    - name: UDMP CPU
      where: '"subsystem" = ''wan'''
      field: '"gw_cpu"'
      measurement: '"subsystems"'
      group_function: last
      database: unifi
      unit_of_measurement: '%'
    - name: UDMP Memory
      where: '"subsystem" = ''wan'''
      field: '"gw_mem"'
      measurement: '"subsystems"'
      group_function: last
      database: unifi
      unit_of_measurement: '%'
1 Like

Darn this is just what I’m looking were it not that I can’t get IfluxDB to work on my HA. :unamused: :roll_eyes:

This looks great. I have grafana and influxdb on HA.
Is there a way to run unpoller also on HA?
How can I know more parameters?
Thanks!

Have a look here, there’s a few ways to pull more data from from the UDM PRO.

Not as far as I know, that would require a person to create a plugin. I’m using proxmox, so I just created a LXC on it for that. Works like a charm

I am running on a docker container on other machine. And it also works great. But if I can use it inside HA would be great.

Anyone a idea how to create a Temperature sensor for my udm pro. If i check influx db, i see that the udm pro is reporting the temperature under usg → temp_CPU. i tried this but don’t think it’s gonna work (tried disabling authentication but also not working):

  - plaform: influxdb
    host: <ip of udm pro>
    queries:
      - name: UDMPro CPU Temp
        where: '"usg" = ''temp_CPU'''
        database: unifi
        measurement: '"usg"'
        unit_of_measurement: °C
        group_function: last

This is what i get from influx db :

SELECT mean("temp_CPU") AS "mean_temp_CPU" FROM "unifi"."autogen"."usg" WHERE time > :dashboardTime: AND time < :upperDashboardTime: GROUP BY time(:interval:) FILL(null)

Already found it by adding this:

  - platform: influxdb
    host: localhost
    queries:
     - name: UDMP temp CPU
       where: '"name" = ''<nameofyourudm>'''
       field: '"temp_CPU"'
       measurement: '"usg"'
       group_function: last
       database: unifi
       unit_of_measurement: '°C'
     - name: UDMP temp Local
       where: '"name" = ''<nameofyourudm>'''
       field: '"temp_Local"'
       measurement: '"usg"'
       group_function: last
       database: unifi
       unit_of_measurement: '°C'
     - name: UDMP temp PHY
       where: '"name" = ''<nameofyourudm>'''
       field: '"temp_PHY"'
       measurement: '"usg"'
       group_function: last
       database: unifi
       unit_of_measurement: '°C' 

I hope i can help someone with sharing this :slight_smile:

1 Like

i am so glad I found this post.

Just installed unpoller in a container within HA using Portainer, installed the HA Community Addons Influx and Grafana, and with a little bit of tinkering around, now have beautiful Grafana dashboards in HA. It works out of the box, all latest versions of everything, and latest unifi software versions.

Now to use some of the above posts to put the values into some entities.

Thank you for all your work and sharing. Happy to share configuration steps or docker compose files if anyone needs. the instructions on the various websites were not super clear, so took a few hours trying things to get working.

key points

  • add user to unifi with local only read only access
  • install influx and grafana from the addon store in HA
  • setup a influx db with user name and password for unpoller to put data
  • setup grafana datasource http://a0d7b954-influxdb:8086 for influx
  • unpoller in a docker container in HA with portainer
  • setup using a docker compose file with all ENV variables in the compose file (not best way but easy with unifi and influx user/passwords)
  • connect container to hassio network so can connect to lan
  • grafana dashboards loaded using the json file, not via the ID and grafana url.
  • enjoy
4 Likes

I’d love to have a peek at some more of the details for that! I was pretty surprised that it wasn’t already available as a community add-on (sorry if that sounds terribly entitled, it’s not intended as such).

  • add user to unifi with local only read only access

For this, I’ve noticed when setting up a local user, you have a choice of picking what Role the user will have. For example a Unifi Protect View Only user, or a Unifi Talk View Only user. So when you set this read only user up, and a role for it, did you just do it for the Unifi Network portion?

@benchr

You just need the network viewer rights for the local user.

1 Like

I don’t know if a camera is required for the protect integration but it supplies mem temp and cpu for the udm pro. You can try enabling protect on the udm and then add the integration in hacs.

For anyone else here. If you didn’t know you can use this HACS integration to monitor UDM Pro’s

Unifi Status Sensor

Unify Counter Sensor

Then you create this configuration.yaml file

## Unifi Dream Machine sensors https://github.com/zvldz/unifi_status
## Add as custom respository in HACS. Add below code to configuration.yaml
## Update secrets.yaml file.
sensor:
  - platform: unifi_status
    host: !secret host_udm
    port: 443
    version: UDMP-unifiOS
    username: !secret unifi_username
    password: !secret unifi_password
    monitored_conditions:
      - www
      - wan
      - wlan
      - lan
      - alerts
      - firmware
  - platform: template
    sensors:
      unifi_status_wan_cpu:
        friendly_name: "CPU"
        unit_of_measurement: "%"
        value_template: "{{ states.sensor.unifi_status_wan.attributes['gw_system-stats']['cpu'] }}"
      unifi_status_wan_mem:
        friendly_name: "Memory"
        unit_of_measurement: "%"
        value_template: "{{ states.sensor.unifi_status_wan.attributes['gw_system-stats']['mem'] }}"
      unifi_status_wan_ip:
        friendly_name: 'WAN IP'
        value_template: '{{ states.sensor.unifi_status_wan.attributes.wan_ip }}'
      unifi_status_wan_download:
        friendly_name: 'WAN Download'
        unit_of_measurement: Kbps
        icon_template: "mdi:progress-download"
        value_template: "{{ (states.sensor.unifi_status_wan.attributes['rx_bytes-r'] / 1024) | int }}"
      unifi_status_wan_uptime:
        friendly_name: "UDM Uptime"
        value_template: >
          {%- set time = states.sensor.unifi_status_wan.attributes['gw_system-stats']['uptime'] | int %}
          {%- set minutes = ((time % 3600) // 60) %}
          {%- set minutes = '{}min'.format(minutes) if minutes > 0 else '' %}
          {%- set hours = ((time % 86400) // 3600) %}
          {%- set hours = '{}hr '.format(hours) if hours > 0 else '' %}
          {%- set days = (time // 86400) %}
          {%- set days = '{}d '.format(days) if days > 0 else '' %}
          {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}
      unifi_status_firmware_version:
        friendly_name: "UDM Firmware Version"
        icon_template: "mdi:database-plus"
        value_template: "{{ states.sensor.unifi_status_wan.attributes.gw_version }}"
      unifi_status_www_xput_down:
        friendly_name: "UDM Speedtest Download"
        unit_of_measurement: Mbps
        icon_template: "mdi:progress-download"
        value_template: "{{ states.sensor.unifi_status_www.attributes.xput_down }}"
      unifi_status_www_xput_up:
        friendly_name: "UDM Speedtest Upload"
        unit_of_measurement: Mbps
        icon_template: "mdi:progress-upload"
        value_template: "{{ states.sensor.unifi_status_www.attributes.xput_up }}"
      unifi_status_www_speedtest_ping:
        friendly_name: "UDM Speedtest Ping"
        unit_of_measurement: ms
        icon_template: "mdi:progress-clock"
        value_template: "{{ states.sensor.unifi_status_www.attributes.speedtest_ping }}"
      unifi_status_www_uptime:
        friendly_name: 'Internet Uptime'
        value_template: >
          {%- set time = states.sensor.unifi_status_www.attributes.uptime | int %}
          {%- set minutes = ((time % 3600) // 60) %}
          {%- set minutes = '{}min'.format(minutes) if minutes > 0 else '' %}
          {%- set hours = ((time % 86400) // 3600) %}
          {%- set hours = '{}hr '.format(hours) if hours > 0 else '' %}
          {%- set days = (time // 86400) %}
          {%- set days = '{}d '.format(days) if days > 0 else '' %}
          {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}
      unifi_status_wlan_num_user:
        friendly_name: 'Users Wifi'
        icon_template: "mdi:account-multiple"
        value_template: '{{ states.sensor.unifi_status_wlan.attributes.num_user }}'
      unifi_status_lan_num_user:
        friendly_name: 'Users Lan'
        icon_template: "mdi:account-multiple"
        value_template: '{{ states.sensor.unifi_status_lan.attributes.num_user }}'
9 Likes

You can also add the following SNMP sensors. Just make sure SNMP is enabled on your Unifi devices.

# SNMP sensors
# if you have more ap/switches you can copy paste the code.
# change name and ip and you are ready to go
#
sensor:
  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi Switch Uptime
    baseoid: 1.3.6.1.2.1.1.3.0
    value_template: >
      {%- set time = value | int // 100 %}
      {%- set minutes = ((time % 3600) // 60) %}
      {%- set minutes = '{}min'.format(minutes) if minutes > 0 else '' %}
      {%- set hours = ((time % 86400) // 3600) %}
      {%- set hours = '{}hr '.format(hours) if hours > 0 else '' %}
      {%- set days = (time // 86400) %}
      {%- set days = '{}d '.format(days) if days > 0 else '' %}
      {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}
  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi Switch Firmware Version
    baseoid: 1.3.6.1.4.1.4413.1.1.1.1.1.13.0

  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi Switch Model
    baseoid: 1.3.6.1.4.1.4413.1.1.1.1.1.2.0

  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi AP Uptime
    baseoid: 1.3.6.1.2.1.1.3.0
    value_template: >
      {%- set time = value | int // 100 %}
      {%- set minutes = ((time % 3600) // 60) %}
      {%- set minutes = '{}min'.format(minutes) if minutes > 0 else '' %}
      {%- set hours = ((time % 86400) // 3600) %}
      {%- set hours = '{}hr '.format(hours) if hours > 0 else '' %}
      {%- set days = (time // 86400) %}
      {%- set days = '{}d '.format(days) if days > 0 else '' %}
      {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}
  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi AP Model
    baseoid: 1.3.6.1.4.1.41112.1.6.3.3.0

  - platform: snmp
    host: xxx.xxx.xxx.xxx
    name: Unifi AP Firmware Version
    baseoid: 1.3.6.1.4.1.41112.1.6.3.6.0
3 Likes

Had to remove “entity_id: sensor.unifi_gateway_wan” but the rest worked great, thank you!

I updated the sensors template and links to a UDM Status HACS integration.

1 Like

Thanks for the help :+1:. unifi_status is working very well.
and one help, I cont find UDM pro temperature … how to get that …?
my UDMP is always overheating due to its position. I’m using an external fan to cool it. if I got a temperature, that will very help full to monitor.

@ruaandeysel This is a great substitution instead of going through the unifi-poller, which is a bit of a round-about way of doing it.
One more sensor :slight_smile:

    unifi_status_wan_upload:
      friendly_name: "WAN Upload"
      unit_of_measurement: Kbps
      icon_template: "mdi:progress-upload"
      value_template: "{{ (states.sensor.unifi_status_wan.attributes['tx_bytes-r'] / 1024) | int }}"