Bandwidth monitor from unifi controller

1. 1563269455081
2. 920551248135
3. unknown
4. unknown

This is what I have in my config.yaml

#Unifi USG
sensor:
  - platform: snmp
    name: "USG WAN in"
    host: 10.1.1.1
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.2
    community: "public"
    version: "2c"
    scan_interval: 10

  - platform: snmp
    name: "USG WAN out"
    host: 10.1.1.1
    baseoid: 1.3.6.1.2.1.31.1.1.1.10.2
    community: "public"
    version: "2c"
    scan_interval: 10

  - platform: statistics
    name: "USG WAN in Stats"
    entity_id: sensor.usg_wan_in
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

  - platform: statistics
    name: "USG WAN out Stats"
    entity_id: sensor.usg_wan_out
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

template:
  - sensor:
      - name: "Internet Download"
        state: "{{ states('sensor.usg_wan_in_stats')|float(0)*8/1024/1024|round(2) }}"
        unit_of_measurement: "MBps"
      - name: "Internet Upload"
        state: "{{ states('sensor.usg_wan_out_stats')|float(0)*8/1024/1024|round(2) }}"
        unit_of_measurement: "MBps"

Just an FYI for people trying this in 2024 and struggling to get anything working. A few changes I had to make to get this to work.

I was following https://www.martinrowan.co.uk/2020/11/enabling-snmp-on-ubiquiti-udm-pro/

While setting up snmpd on my UDM, I did NOT duplicate the config into /usr/share/... like the article suggests. It’s also important to either match the config as the article suggests or ensure that you at least remove the lines that will prevent external access e.g. agenthost / limit viewability to views / datasets e.g. some of the existing rocommunity lines.

The baseoid for the snmp interface depends on your specific setup. I am using a UDM SE and I’m using the 2.5Gb WAN not the SFP+ WAN. I’d recommend using a tool like MiB Browser to find the specific interface.

I found it helpful to right click on interfaces → ifTable in the LHS panel and select Table View.

Once you have identified the interface you want to measure (there are way more than just WAN interfaces in here — fun!), scroll to the right and find columns titled ifInOctets and ifOutOctets. These are the values you want. Click the cells and note the oids in the bottom panel. As an example, in my specific case, the OID for ifInOctets was 1.3.6.1.2.1.2.2.1.10.12 not 1.3.6.1.2.1.31.1.1.1.6.2 like in many of the examples above. Note you do not need the leading period from this value.

Once I got the raw values in HA, I noticed that the template was not formatting properly. Specifically, it was not rounding. The solution I used was to change the template to

{{ '%0.2f' | format(states('sensor.<SENOR ID>')|float(0)*8/1024/1024) }}

Hope this helps someone!

1 Like

I’m using this but assume in need to replace the host id?
Or name also?
anything else?

Is there an update to this the final verision?

I’m getting this:

This entity (‘sensor.internet_download’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

That’s your router.

If you want to. It’s the name used for the sensor in HA.

What are your trying to do when you get this?

THanks for this MIB info. I have found my Interface by looking at the mac address. The stats are coming in but they are not looking correct. I am running a UDM Pro
Here is my yml file and screen shot of my dashboard. Not sure what’s going on. Thoughts??

#Unifi USG
sensor:
  - platform: snmp
    name: "USG WAN in"
    host: 172.xx.xx.xx
    baseoid: .1.3.6.1.2.1.2.2.1.10.4
    community: "public"
    version: "2c"
    scan_interval: 10

  - platform: snmp
    name: "USG WAN out"
    host: 172.xx.xx.xx
    baseoid: .1.3.6.1.2.1.2.2.1.16.4
    community: "public"
    version: "2c"
    scan_interval: 10

  - platform: statistics
    name: "USG WAN in Stats"
    entity_id: sensor.usg_wan_in
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

  - platform: statistics
    name: "USG WAN out Stats"
    entity_id: sensor.usg_wan_out
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

template:
  - sensor:
      - name: "Internet Download"
        state: "{{ '%0.2f' | format(states(sensor.usg_wan_in_stats')|float(0)*8/1024/1024) }}"
        unit_of_measurement: "MBps"
      - name: "Internet Upload"
        state: "{{ '%0.2f' | format(states('sensor.usg_wan_out_stats')|float(0)*8/1024/1024) }}"
        unit_of_measurement: "MBps"

Hi, I try with UXG-Lite but not working.

snmpbulkwalk -v 2c -c public 192.168.1.1 1.3.6.1.2.1.31.1.1.1.1
iso.3.6.1.2.1.31.1.1.1.1.1 = STRING: “lo”
iso.3.6.1.2.1.31.1.1.1.1.2 = STRING: “dummy0”
iso.3.6.1.2.1.31.1.1.1.1.3 = STRING: “gre0”
iso.3.6.1.2.1.31.1.1.1.1.4 = STRING: “gretap0”
iso.3.6.1.2.1.31.1.1.1.1.5 = STRING: “ip_vti0”
iso.3.6.1.2.1.31.1.1.1.1.6 = STRING: “ip6_vti0”
iso.3.6.1.2.1.31.1.1.1.1.7 = STRING: “sit0”
iso.3.6.1.2.1.31.1.1.1.1.8 = STRING: “ip6tnl0”
iso.3.6.1.2.1.31.1.1.1.1.9 = STRING: “eth0”
iso.3.6.1.2.1.31.1.1.1.1.10 = STRING: “eth1”
iso.3.6.1.2.1.31.1.1.1.1.11 = STRING: “ifb0”
iso.3.6.1.2.1.31.1.1.1.1.12 = STRING: “ifb1”
iso.3.6.1.2.1.31.1.1.1.1.13 = STRING: “br0”
iso.3.6.1.2.1.31.1.1.1.1.14 = STRING: “eth0.2”
iso.3.6.1.2.1.31.1.1.1.1.15 = STRING: “eth0.3”
iso.3.6.1.2.1.31.1.1.1.1.16 = STRING: “eth0.4”
iso.3.6.1.2.1.31.1.1.1.1.17 = STRING: “dnsfilter”
iso.3.6.1.2.1.31.1.1.1.1.19 = STRING: “dnsfilter-0”
iso.3.6.1.2.1.31.1.1.1.1.20 = STRING: “dnsfilter-1”
iso.3.6.1.2.1.31.1.1.1.1.21 = STRING: “dnsfilter-2”
iso.3.6.1.2.1.31.1.1.1.1.22 = STRING: “eth0.10”
iso.3.6.1.2.1.31.1.1.1.1.23 = STRING: “dnsfilter-3”

I try all the numbers but none of them work

Any idea?

Not without seeing your config or the raw data from SNMP (command line or whatever).