SNMP bandwidth monitor using statistics

Thanks. How do I figure out the baseoid for the UDM Pro? For WAN Bandwidth in and out.

Check my post above yours. Others and I have posted some pointers there. In short, find the ethernet ports and use an SNMP tool to plot the usage while doing a large, known download or speedtest.

@odwide
I’m quite new to working with templates and derivatives, but I’ve been doing my best to figure things out. Thanks to your code, I’ve managed to get most of the sensors working, except for the “WAN Down Usage” sensor, which is showing as unavailable. Here’s my YAML code. I’d really appreciate any assistance could be provided here.

sensor:
  - platform: snmp
    name: "Optus WAN Interface Down Octets"
    unique_id: optus_wan_interface_down_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0. 
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.5
    state_class: total_increasing
    icon: mdi:cloud-download
    unit_of_measurement: "B"
  
  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Optus WAN Down Throughput - Bps"
    source: sensor.optus_wan_interface_down_octets
    unit_time: s
    round: 2

template:
  - sensor:
    - name: "Optus WAN Down Throughput"
      unique_id: optus_wan_down_throughput
      unit_of_measurement: Mbps
      icon: mdi:cloud-download
      # Convert throughput derivative from Bps to Mbps
      state: "{{ ((states('sensor.network_optus_wan_down_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
      state_class: measurement
    
    - name: "Optus WAN Down Usage"
      unique_id: wan_down_usage
      unit_of_measurement: GiB
      icon: mdi:cloud-download
      # Convert usage meter below from B to GiB
      state: "{{ ((states('sensor.network_optus_wan_down_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
      state_class: total_increasing

    
utility_meter:
  network_optus_wan_down_data_usage_meter_bytes:
    unique_id: network_optus_wan_down_data_usage_meter_bytes
    name: Network - WAN Down Data Usage Meter - Bytes
    source: sensor.optus_wan_interface_down_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0

Based on your yaml the correct entity id for Optus Wan Down Usage is sensor.wan_down_usage, not sensor.optus_wan_down_usage.

Thanks, I am new in HA world and still learning. I’ve updated the unique ID for Optus Wan Down Usage to something more descriptive. However, the sensor is still showing as unavailable, and I haven’t found any other sensors with “wan” in their names either.

  - platform: snmp
    name: "Optus WAN Interface Down Octets"
    unique_id: optus_wan_interface_down_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0. 
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.5
    state_class: total_increasing
    icon: mdi:cloud-download
    unit_of_measurement: "B"
  
  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Optus WAN Down Throughput - Bps"
    source: sensor.optus_wan_interface_down_octets
    unit_time: s
    round: 2

template:
  - sensor:
    - name: "Optus WAN Down Throughput"
      unique_id: optus_wan_down_throughput
      unit_of_measurement: Mbps
      icon: mdi:cloud-download
      # Convert throughput derivative from Bps to Mbps
      state: "{{ ((states('sensor.network_optus_wan_down_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
      state_class: measurement
    
    - name: "Optus WAN Down Usage"
      unique_id: optus_wan_down_usage
      unit_of_measurement: GiB
      icon: mdi:cloud-download
      # Convert usage meter below from B to GiB
      state: "{{ ((states('sensor.network_optus_wan_down_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
      state_class: total_increasing

    
utility_meter:
  network_optus_wan_down_data_usage_meter_bytes:
    unique_id: network_optus_wan_down_data_usage_meter_bytes
    name: Network - WAN Down Data Usage Meter - Bytes
    source: sensor.optus_wan_interface_down_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0

If network_optus_wan_down_data_usage_meter_bytes is giving the correct value then optus_wan_down_usage should too.

Apparently there are entities no longer being provided but that have id collision, since your sensor now has the id optus_wan_down_usage_3. To clean up, comment out the template for Optus WAN Down Usage, restart HA, under the Entities page search for any entity with id optus_wan_down_usage and delete it, uncomment the sensor in yaml and restart again. That should get rid of any all dangling sensors and leave only the one that will work.

1 Like

Thanks, you gave the idea of double-checking the sensor ids. Unfortunately the id for network_optus_wan_down_data_usage_meter_bytes wasn’t created properly even it was specified correctly in the code. I fixed that things started to work!

Here is the working YAML code for someone who has implemented Double WAN on a supported router.

sensor:

# Optus WAN Interface
  - platform: snmp
    name: "Optus WAN Interface Down Octets"
    unique_id: optus_wan_interface_down_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0.
    # Run following command to get the baseoid:
    # snmpwalk -v3 -l authPriv -u <username> -a <auth_protocol> -A <auth_key> -x <priv_protocol> -X <priv_key> <host> <baseoid>
    # example: snmpwalk -v3 -l authPriv -u isr_snmp_user -a hmac-sha -A !secret isr_snmp_auth_key -x aes-cfb-128 -X !secret isr_snmp_priv_key 192.168.10.1 1.3.6.1.2.1.31.1.1.1.6[.5]
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.5
    state_class: total_increasing
    icon: mdi:cloud-download
    unit_of_measurement: "B"

  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Optus WAN Down Throughput - Bps"
    source: sensor.optus_wan_interface_down_octets
    unit_time: s
    round: 2

  - platform: snmp
    name: "Optus WAN Interface Up Octets"
    unique_id: optus_wan_interface_up_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0.
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.10.5
    state_class: total_increasing
    icon: mdi:cloud-upload
    unit_of_measurement: "B"

  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Optus WAN Up Throughput - Bps"
    source: sensor.optus_wan_interface_up_octets
    unit_time: s
    round: 2

# Telstra WAN Interface 
  - platform: snmp
    name: "Telstra WAN Interface Down Octets"
    unique_id: telstra_wan_interface_down_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0.
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.6.6
    state_class: total_increasing
    icon: mdi:cloud-download
    unit_of_measurement: "B"

  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Telstra WAN Down Throughput - Bps"
    source: sensor.telstra_wan_interface_down_octets
    unit_time: s
    round: 2

  - platform: snmp
    name: "Telstra WAN Interface Up Octets"
    unique_id: telstra_wan_interface_up_octets
    host: 192.168.10.1
    version: "3"
    username: !secret isr_snmp_user
    auth_key: !secret isr_snmp_auth_key
    auth_protocol: "hmac-sha"
    priv_key: !secret isr_snmp_priv_key
    priv_protocol: "aes-cfb-128"
    # ifHCInOctets G0/0/0.
    # Running total of octects (Bytes) going into the interface since router reboot.
    baseoid: 1.3.6.1.2.1.31.1.1.1.10.5
    state_class: total_increasing
    icon: mdi:cloud-upload
    unit_of_measurement: "B"

  - platform: derivative
    # Calculate the throughput by sampling the SNMP sensor
    name: "Network - Telstra WAN Up Throughput - Bps"
    source: sensor.telstra_wan_interface_up_octets
    unit_time: s
    round: 2

##########################################################################################
# Template
##########################################################################################

template:
# Optus WAN Interface Template
  - sensor:
      - name: "Optus WAN Down Throughput"
        unique_id: optus_wan_down_throughput
        unit_of_measurement: Mbps
        icon: mdi:cloud-download
        # Convert throughput derivative from Bps to Mbps
        state: "{{ ((states('sensor.network_optus_wan_down_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
        state_class: measurement

      - name: "Optus WAN Down Usage"
        unique_id: optus_wan_down_usage
        unit_of_measurement: GiB
        icon: mdi:cloud-download
        # Convert usage meter below from B to GiB
        state: "{{ ((states('sensor.network_optus_wan_down_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
        state_class: total_increasing
      
      - name: "Optus WAN Up Throughput"
        unique_id: optus_wan_up_throughput
        unit_of_measurement: Mbps
        icon: mdi:cloud-upload
        # Convert throughput derivative from Bps to Mbps
        state: "{{ ((states('sensor.network_optus_wan_up_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
        state_class: measurement

      - name: "Optus WAN Up Usage"
        unique_id: optus_wan_up_usage
        unit_of_measurement: GiB
        icon: mdi:cloud-upload
        # Convert usage meter below from B to GiB
        state: "{{ ((states('sensor.network_optus_wan_up_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
        state_class: total_increasing

# Telstra WAN Interface Template

  - sensor:
      - name: "Telstra WAN Down Throughput"
        unique_id: telstra_wan_down_throughput
        unit_of_measurement: Mbps
        icon: mdi:cloud-download
        # Convert throughput derivative from Bps to Mbps
        state: "{{ ((states('sensor.network_telstra_wan_down_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
        state_class: measurement

      - name: "Telstra WAN Down Usage"
        unique_id: telstra_wan_down_usage
        unit_of_measurement: GiB
        icon: mdi:cloud-download
        # Convert usage meter below from B to GiB
        state: "{{ ((states('sensor.network_telstra_wan_down_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
        state_class: total_increasing
      
      - name: "Telstra WAN Up Throughput"
        unique_id: telstra_wan_up_throughput
        unit_of_measurement: Mbps
        icon: mdi:cloud-upload
        # Convert throughput derivative from Bps to Mbps
        state: "{{ ((states('sensor.network_telstra_wan_up_throughput_bps') | int) * 8 / 10**6) | round(1) }}"
        state_class: measurement

      - name: "Telstra WAN Up Usage"
        unique_id: telstra_wan_up_usage
        unit_of_measurement: GiB
        icon: mdi:cloud-upload
        # Convert usage meter below from B to GiB
        state: "{{ ((states('sensor.network_telstra_wan_up_data_usage_meter_bytes') | int) / 2**30) | round(2) }}"
        state_class: total_increasing

##########################################################################################
# Utility Meter
##########################################################################################  

utility_meter:
# Optus WAN Interface Utility Meter 
  network_optus_wan_down_data_usage_meter_bytes:
    unique_id: network_optus_wan_down_data_usage_meter_bytes
    name: Network - Optus WAN Down Data Usage Meter - Bytes
    source: sensor.optus_wan_interface_down_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0
  
  network_optus_wan_up_data_usage_meter_bytes:
    unique_id: network_optus_wan_up_data_usage_meter_bytes
    name: Network - Optus WAN Up Data Usage Meter - Bytes
    source: sensor.optus_wan_interface_up_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0

# Telstra WAN Interface Utility Meter 
  network_telstra_wan_down_data_usage_meter_bytes:
    unique_id: network_telstra_wan_down_data_usage_meter_bytes
    name: Network - Telstra WAN Down Data Usage Meter - Bytes
    source: sensor.telstra_wan_interface_down_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0
  
  network_telstra_wan_up_data_usage_meter_bytes:
    unique_id: network_telstra_wan_up_data_usage_meter_bytes
    name: Network - Telstra WAN Up Data Usage Meter - Bytes
    source: sensor.telstra_wan_interface_up_octets
    cycle: monthly
    offset:
      hours: 72
      minutes: 0
      seconds: 0
1 Like