SNMP Bandwidth Monitor

I managed to get this working today with my ASUS router and the reported numbers appear to be accurate. The only trouble I’m running into is that HA doesn’t appear to be saving any history which can be charted. Only the last updated value appears. Is that normal/expected behavior? How would I go about saving these values with the recorder so I can chart the historical data no differently than any other sensor?

Make sure your history and recorder sections in configuration.yaml are enabled

I get a nice little graph:

image

Below is my ‘recorder’ section:

recorder:
purge_interval: 1
purge_keep_days: 7
exclude:
entities:
- weather.dark_sky
- sun.sun
- sensor.yr_symbol
- sensor.season
- sensor.ring_front_door_volume
- sensor.home_eta
- sensor.dark_sky_wind_speed_6
- sensor.dark_sky_wind_speed_5
- sensor.dark_sky_wind_speed_4
- sensor.dark_sky_wind_speed_3
- sensor.dark_sky_wind_speed_2
- sensor.dark_sky_wind_speed_1
- sensor.dark_sky_wind_speed
- sensor.dark_sky_wind_bearing_6
- sensor.dark_sky_wind_bearing_5
- sensor.dark_sky_wind_bearing_4
- sensor.dark_sky_wind_bearing_3
- sensor.dark_sky_wind_bearing_2
- sensor.dark_sky_wind_bearing_1
- sensor.dark_sky_wind_bearing
- sensor.dark_sky_visibility_6
- sensor.dark_sky_visibility_5
- sensor.dark_sky_visibility_4
- sensor.dark_sky_visibility_3
- sensor.dark_sky_visibility_2
- sensor.dark_sky_visibility_1
- sensor.dark_sky_visibility
- sensor.dark_sky_temperature
- sensor.dark_sky_summary
- sensor.dark_sky_pressure_6
- sensor.dark_sky_pressure_5
- sensor.dark_sky_pressure_4
- sensor.dark_sky_pressure_3
- sensor.dark_sky_pressure_2
- sensor.dark_sky_pressure_1
- sensor.dark_sky_pressure
- sensor.dark_sky_precip_probability_6
- sensor.dark_sky_precip_probability_5
- sensor.dark_sky_precip_probability_4
- sensor.dark_sky_precip_probability_3
- sensor.dark_sky_precip_probability_2
- sensor.dark_sky_precip_probability_1
- sensor.dark_sky_precip_probability
- sensor.dark_sky_precip_intensity_6
- sensor.dark_sky_precip_intensity_5
- sensor.dark_sky_precip_intensity_4
- sensor.dark_sky_precip_intensity_3
- sensor.dark_sky_precip_intensity_2
- sensor.dark_sky_precip_intensity_1
- sensor.dark_sky_precip_intensity
- sensor.dark_sky_precip_6
- sensor.dark_sky_precip_5
- sensor.dark_sky_precip_4
- sensor.dark_sky_precip_3
- sensor.dark_sky_precip_2
- sensor.dark_sky_precip_1
- sensor.dark_sky_precip
- sensor.dark_sky_ozone_6
- sensor.dark_sky_ozone_5
- sensor.dark_sky_ozone_4
- sensor.dark_sky_ozone_3
- sensor.dark_sky_ozone_2
- sensor.dark_sky_ozone_1
- sensor.dark_sky_ozone
- sensor.dark_sky_nearest_storm_distance
- sensor.dark_sky_minutely_summary
- sensor.dark_sky_icon_6
- sensor.dark_sky_icon_5
- sensor.dark_sky_icon_4
- sensor.dark_sky_icon_3
- sensor.dark_sky_icon_2
- sensor.dark_sky_icon_1
- sensor.dark_sky_icon
- sensor.dark_sky_humidity_6
- sensor.dark_sky_humidity_5
- sensor.dark_sky_humidity_4
- sensor.dark_sky_humidity_3
- sensor.dark_sky_humidity_2
- sensor.dark_sky_humidity_1
- sensor.dark_sky_humidity
- sensor.dark_sky_hourly_summary
- sensor.dark_sky_dew_point_6
- sensor.dark_sky_dew_point_5
- sensor.dark_sky_dew_point_4
- sensor.dark_sky_dew_point_3
- sensor.dark_sky_dew_point_2
- sensor.dark_sky_dew_point_1
- sensor.dark_sky_dew_point
- sensor.dark_sky_daily_summary
- sensor.dark_sky_daily_low_temperature_6
- sensor.dark_sky_daily_low_temperature_5
- sensor.dark_sky_daily_low_temperature_4
- sensor.dark_sky_daily_low_temperature_3
- sensor.dark_sky_daily_low_temperature_2
- sensor.dark_sky_daily_low_temperature_1
- sensor.dark_sky_daily_low_temperature
- sensor.dark_sky_daily_high_temperature_6
- sensor.dark_sky_daily_high_temperature_5
- sensor.dark_sky_daily_high_temperature_4
- sensor.dark_sky_daily_high_temperature_3
- sensor.dark_sky_daily_high_temperature_2
- sensor.dark_sky_daily_high_temperature_1
- sensor.dark_sky_daily_high_temperature
- sensor.dark_sky_cloud_coverage_6
- sensor.dark_sky_cloud_coverage_5
- sensor.dark_sky_cloud_coverage_4
- sensor.dark_sky_cloud_coverage_3
- sensor.dark_sky_cloud_coverage_2
- sensor.dark_sky_cloud_coverage_1
- sensor.dark_sky_cloud_coverage
- sensor.dark_sky_apparent_temperature

This is my ‘history’ section

Enables support for tracking state changes over time

history:

Yet no graph. Any idea why? I’m seeing graph history on other entities like my thermostats etc.
Internet%20Speed

When you go to the <> menu are any numbers showing in your snmp sensors?

Example:

image

1 Like

I like the use of the snmpget command, but it doesn’t seem to be installed on HASSIO, does anyone know a workaround?

Can someone help me do this with a Unifi USG?

I’d like to know if it’s possible to make this per client bandwidth?

What do I use to see capture the OIDs of my clients based on their MAC’s

Thanks

Hi, this is working really well for me, it allows me to see my see my bandwidth.

I can even log the Speed using the recorder component and make a nice graph of bandwidth usage.

However my SNMP updates every 10 seconds or so, so it seems to have made my database double in size!

Is there a way I can limit it so it only updates once per minute? Thanks

I think you can use the scan_interval option to adjust the update frequency.
So scan_interval: 60 should be 1/min.

1 Like

thanks, I didn’t see scan_interval in the snmp docs:

turns out it works, thanks very much :slight_smile:

2 Likes

I really appreciate this, but a few slight changes are necessary for the latest HASS code. Hope this can benefit the next person…

  • input_slider renamed to input_number
  • service select_value is now set_value
  • input_number must be explicitly defined
    NOTE: maximum has been defined assuming 32-bit counter

For example:

input_number:
  internet_traffic_delta_in:
    min: 0
    max: 4294967295
    step: 1
  internet_traffic_delta_out:
    min: 0
    max: 4294967295
    step: 1

Cheers!

3 Likes

How to run snmpget from docker ?

One trick to run anything in the docker host that I used, is a command line sensor that does ssh to the host itself and executes a command:

ssh ha@rpi /home/ha/.homeassistant/some_script.sh

this needs another trick since you need persistent storage for the container’s ssh to use always the same ssh key. I did that by creating ssh keys for the container to use, and then storing them in the host in a “container_persistent_storage” folder I created, mapping that to /root/.ssh in the container. In docker-compose, something like this works:

volumes:
  - /home/ha/.homeassistant:/config
  - /home/ha/.homeassistant/container_persistent_storage/ssh_config:/root/.ssh

I still use this method for some basic calls to host scripts, but I have moved most of the most frequent calls such as the snmp polls of my router to a web service. I wrote a simple web service in python that I run as a daemon in the host, using the werkzeug library I expose a bunch of KPIs that a dockerized homeassistant consumes via sensors using a REST sensor. This approach needs more work to setup but it is very light on resources.
Once I had the webservice running the polling, it was easier to do the throughput calculations directly in it and expose to HA the results via the REST API

1 Like

After upgrading to 108 i’ve noticed an error in the log

2020-04-10 05:09:58 ERROR (MainThread) [homeassistant.components.automation] Monitor Traffic In: Error executing script. Invalid data for call_service at pos 1: Invalid value for input_number.internet_traffic_delta_in: -3072910986.1984906 (range 0.0 - 4294967295.0)

I previously had it set to
max: 1000000000000

and changed it according to the post above, but still the error

Adjust your min to -4294967295

1 Like

I recently changed the MAC address of my WAN interface in pfsense, and after that I lost tracking of in/out data. I was using the BASEOIDs used in the original post here (1.3.6.1.2.1.2.2.1.10.2 and 1.3.6.1.2.1.2.2.1.16.2), which worked fine.

I’m guessing the change of NIC (and thus MACs address) caused the BASOID to change, but to what? Anyone got any an idea?

Use an SNMPwalker to find them.

1 Like

Guys,

Have someone a good working configs with PFsense en SNMP integration?

I used SNMPwalker for windows to find the interfaces, and then I guessed based on their sent/received data which one was which.

Why guess when 1.3.6.1.2.1.2.2.1.2 tells you the description of the entries?

Hi to all!
I am in this condition:


Why?

This is my configuration.yaml

`sensor:

  • platform: systemmonitor
    resources:

    • type: disk_use_percent
      arg: /home
    • type: memory_use_percent
    • type: load_1m
    • type: load_5m
    • type: load_15m
    • type: processor_use
  • platform: mitemp_bt
    rounding: True
    decimals: 2
    period: 60
    log_spikes: False
    use_median: False
    active_scan: False
    batt_entities: False
    sensor_names:
    ‘A4:C1:38:2E:FA:57’: ‘Ufficio’
    ‘A4:C1:38:FF:85:1F’: ‘Camera’
    ‘A4:C1:38:C6:F3:EF’: ‘Cucina’
    report_unknown: False
    whitelist: False

  • platform: command_line
    name: CPU Temperature
    command: “cat /sys/class/thermal/thermal_zone0/temp”
    unit_of_measurement: “°C”
    value_template: ‘{{ value | multiply(0.001) | round(1) }}’

  • platform: snmp
    name: snmp_wan_in
    host: 192.168.10.201
    baseoid: 1.3.6.1.2.1.2.2.1.10

  • platform: snmp
    name: snmp_wan_out
    host: 192.168.10.201
    baseoid: 1.3.6.1.2.1.2.2.1.16.2

  • platform: template
    sensors:
    internet_speed_in:
    friendly_name: ‘Internet Speed’
    value_template: ‘{{ ((states.input_slider.internet_traffic_delta_in.state | float ) / 1000000 ) | round(2) }}’
    unit_of_measurement: ‘Mbps’

  • platform: template
    sensors:
    internet_speed_out:
    friendly_name: ‘Internet Speed’
    value_template: ‘{{ ((states.input_slider.internet_traffic_delta_out.state | float ) / 1000000 ) | round(2) }}’
    unit_of_measurement: ‘Mbps’

  • platform: statistics
    name: ‘WAN Traffic IN’
    entity_id: sensor.internet_speed_in

  • platform: statistics
    name: ‘WAN Traffic OUT’
    entity_id: sensor.internet_speed_out

input_slider:
internet_traffic_delta_in:
name: “Traffic IN Delta”
initial: 0
min: 0
max: 1000000000000

internet_traffic_delta_out:
name: “Traffic OUT Delta”
initial: 0
min: 0
max: 1000000000000
`

and this is automation.yaml

  • alias: Monitor Traffic

    trigger:
    platform: state
    entity_id: sensor.snmp_wan_in

    action:

    • service: input_slider.select_value
      data_template:
      entity_id: input_slider.internet_traffic_delta_in
      value: ‘{{ ((trigger.to_state.state | int - trigger.from_state.state | int) * 8 ) / ( as_timestamp(trigger.to_state.last_updated) - as_timestamp(trigger.from_state.last_updated) ) }}’
  • alias: Monitor Traffic

    trigger:
    platform: state
    entity_id: sensor.snmp_wan_out

    action:

    • service: input_slider.select_value
      data_template:
      entity_id: input_slider.internet_traffic_delta_out
      value: ‘{{ ((trigger.to_state.state | int - trigger.from_state.state | int) * 8 ) / ( as_timestamp(trigger.to_state.last_updated) - as_timestamp(trigger.from_state.last_updated) ) }}’

Can anyone help me?

1 Like