Monitor unifi Dream Machine (Pro)

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 }}"

Got it setup and working using unifi-stats which was great, but for some reason it was causing my node-red integration to forcefully disconnect from the supervisor every few seconds… So had to turn it off.

Anyone else have this issue?

You can try the Unifi Protect integration. It shows CPU temps on UDM Pro

1 Like

Hi, I’ve added the custom component, added it to my config but the entities stay empty.
It gives me health errors in the logs, but it doesn’t show any connection issues, however all the entities remain status ‘unknown’. Any idea?

Did you set the ‘version’ string? It’s different if it’s an UDM Pro or a cloud key?

Would love to have it. Been looking for this for months now. Thanks!

yes, yes i just did a read only user on the network app.

Here is the compose file. I just use this in Portainer, and it works fine.
Recreates do updates too.
make sure you update your specific info that you have setup in influxdb

  • influxdb ip address,
  • influxdb db name,
  • username,
  • password

and your Unifi console read only user name, and the console IP Address.

create a stack, add this into the editor, click create, and away you go.

version: '2'
services:
  unifi-poller:
    restart: always
    image: ghcr.io/unpoller/unpoller:latest
    environment:
      - UP_PROMETHEUS_DISABLE=true
      - UP_INFLUXDB_DISABLE=false
      - UP_INFLUXDB_DB=UNIFIDBNANE
      - UP_INFLUXDB_USER=unifipoller
      - UP_INFLUXDB_PASS=unifipoller
      - UP_INFLUXDB_URL=http://172.30.33.6:8086
      - UP_UNIFI_DEFAULT_USER=unifipoller
      - UP_UNIFI_DEFAULT_PASS=unifipoller
      - UP_UNIFI_DEFAULT_URL=https://192.168.1.1
      - UP_UNIFI_DEFAULT_SAVE_DPI=true
      - UP_UNIFI_DEFAULT_SAVE_EVENTS=true
      - UP_UNIFI_DEFAULT_SAVE_ALARMS=true
      - UP_UNIFI_DEFAULT_SAVE_ANOMALIES=true
      - UP_UNIFI_DEFAULT_SAVE_IDS=true
      - UP_POLLER_DEBUG=false
    volumes:
      - /mnt/data/supervisor/homeassistant/unpoller:/config

and then follow the other instructions above to add your dashboards to graphana, once the data is going to influxdb. you can check int eh container logs that its working too.

2 Likes

Thanks for sharing the compose file!

I got however stuck in this “unpoller in a docker container in HA with portainer”. How did you do this?

There is an addon for portainer. I have the original one that was in the community store, that’s not there now so I think there is another respository that provides it now. Maybe in hacs

1 Like

Super! Thanks! Can confirm everything is working! :slight_smile:

Although everything is working, but I am getting an error(warning) regarding unsupported container.

Any way to fix this? Does it break the OTA updates and auto full backup?

click ignore :slight_smile:

It doesnt break OTA or backups.

Ideally running the poller outside of HA is better, but then you need Influx outside too. This seems a pretty simple solution. What we actually need is someone who knows how to do this to create an Addon out of poller, so you dont need portainer, and dont get the warning.

That is something outside of my skillset, but looking at the documentation, it may not be too hard, so that feels like a winter project. (southern hemisphere) so in next few months.

1 Like

Did it help?

yes. I have another Pi where I have the docker and portainer running with some other set of containers for a different purpose. In HA on a different machine I had already influxDB and Grafana running. I wanted Unpoller thats why in HA machine, so this was the most elegant solution.