SNMP Bandwidth Monitor

Yeah sorry, out of my league, I havent even started looking at automation or syntaxes in HASS yet!
Maybe someone else can help?

It may be that your router doesn’t need the times 8 multiplication. It all depends on what format the data from the SNMP sensor is from the router.

Some might be in bits and others might already be in bytes.

The referenced OID is octet count, so you always need to multiply by 8.

I’ll set this up and will come back to u ASAP if I need support .always wanted to include this component

ok, so I’ve just done a ifconfig via SSH to my router, and also a snmpwalk and the result from snmpwalk shows the same number as RX Bytes and TX Bytes. So I’m guess my ASUS outputs in bytes already.

So, to stop the multiplication by 8, would I just remove the * 8 from the automations?

I’m getting this error message in the logs which appears to be stopping home assistant from launching [homeassistant.components.sensor.statistics] mean requires at least one data point

I have the following in sensors.yaml that’s is included correctly:

- platform: statistics
  name: 'WAN Traffic IN'
  entity_id: sensor.internet_speed_in

- platform: statistics
  name: 'WAN Traffic OUT'
  entity_id: sensor.internet_speed_out

# Templates
# https://community.home-assistant.io/t/snmp-bandwidth-monitor/7122       

- 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' 

Here’s what I have in automations.yaml:

# Network Monitoring
- 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) ) }}'

I wasn’t sure where to stick the input_slider in my setup so I tried it in both configurations.yaml and sensors.yaml and neither worked. Any ideas? Is this to do with the oid’s? I have a virgin media router if that helps.

Input slider in configuration.yaml.

Is normal and safe to ignore it does not stop HA from starting, something else in your configuration is causing that.

Include this in configuration.yaml:

## Custom Input Sliders ##
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

Thanks, I readded everything and it does indeed appear to stop HA, at least the GUI. I can see the logs being written to but I can access the frontent. Here’s how I added the input slider as you suggested:

device_tracker: !include device_tracker.yaml
sensor: !include sensors.yaml
media_player: !include media_players.yaml
notify: !include notifiers.yaml
group: !include groups.yaml
automation: !include automations.yaml

## Custom Input Sliders ##
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

Is this the correct order? I’ve also attached the log file but there doesn’t seem to be anything interesting there. Any ideas?

2017-07-25 18:12:28 WARNING (MainThread) [homeassistant.components.sensor.statistics] mean requires at least one data point
2017-07-25 18:12:28 WARNING (MainThread) [homeassistant.components.sensor.statistics] mean requires at least one data point
2017-07-25 18:12:32 WARNING (MainThread) [homeassistant.components.sensor.statistics] mean requires at least one data point
2017-07-25 18:12:32 WARNING (MainThread) [homeassistant.components.sensor.statistics] mean requires at least one data point
2017-07-25 18:12:35 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2017-07-25 18:12:35 WARNING (MainThread) [homeassistant.setup] Setup of group is taking over 10 seconds.
2017-07-25 18:12:36 WARNING (MainThread) [homeassistant.setup] Setup of notify is taking over 10 seconds.
2017-07-25 18:12:37 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2017-07-25 18:12:38 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2017-07-25 18:12:49 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.

what does a sudo service home-assistant status output for you?

this:

[email protected] - Home Assistant
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
   Active: active (running) since Tue 2017-07-25 19:12:09 UTC; 26min ago
 Main PID: 731 (hass)
   CGroup: /system.slice/system-home\x2dassistant.slice/[email protected]
           └─731 /srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant

Jul 25 19:38:51 raspberrypi hass[731]: 2017-07-25 19:38:51 ERROR (MainThread) [homeassistant.core] Timer got ou...etting
Jul 25 19:38:52 raspberrypi hass[731]: 2017-07-25 19:38:52 INFO (Thread-7) [homeassistant.components.device_tra...8.0.20
Jul 25 19:38:52 raspberrypi hass[731]: 2017-07-25 19:38:52 INFO (Thread-7) [homeassistant.components.device_tra...essful
Jul 25 19:38:53 raspberrypi hass[731]: 2017-07-25 19:38:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event...
Jul 25 19:38:54 raspberrypi hass[731]: 2017-07-25 19:38:54 ERROR (MainThread) [homeassistant.core] Timer got ou...etting
Jul 25 19:38:57 raspberrypi hass[731]: 2017-07-25 19:38:57 ERROR (MainThread) [homeassistant.core] Timer got ou...etting
Jul 25 19:38:58 raspberrypi hass[731]: 2017-07-25 19:38:58 INFO (MainThread) [homeassistant.core] Bus:Handling <Event...
Jul 25 19:38:59 raspberrypi hass[731]: 2017-07-25 19:38:59 ERROR (MainThread) [homeassistant.core] Timer got ou...etting
Jul 25 19:39:01 raspberrypi hass[731]: 2017-07-25 19:39:01 WARNING (MainThread) [homeassistant.helpers.entity] ...econds
Jul 25 19:39:02 raspberrypi hass[731]: 2017-07-25 19:39:01 INFO (MainThread) [homeassistant.core] Bus:Handling <Event...
Hint: Some lines were ellipsized, use -l to show in full.

I’ve also gotten the following in the logs now:

2017-07-25 19:37:42 WARNING (MainThread) [homeassistant.components.sensor.statistics] variance requires at least two data points
2017-07-25 19:37:42 WARNING (MainThread) [homeassistant.components.sensor.statistics] variance requires at least two data point

got the full thing:

 [email protected] - Home Assistant
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
   Active: active (running) since Tue 2017-07-25 19:12:09 UTC; 27min ago
 Main PID: 731 (hass)
   CGroup: /system.slice/system-home\x2dassistant.slice/[email protected]
           ├─ 731 /srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant
           └─1764 nmap -oX - 192.168.0.1/24 -F --host-timeout 5s --exclude 192.168.0.12,192.168.0.15,192.168.0.16,192.168.0.23,192.168.0.21,192.168.0.1,192.168.0.29,192.168.0.11,192.168.0.19,192.168.0.17

Jul 25 19:39:28 raspberrypi hass[731]: 2017-07-25 19:39:28 INFO (Thread-9) [homeassistant.components.device_tracker.nmap_tracker] No MAC address found for 192.168.0.20
Jul 25 19:39:28 raspberrypi hass[731]: 2017-07-25 19:39:28 INFO (Thread-9) [homeassistant.components.device_tracker.nmap_tracker] nmap scan successful
Jul 25 19:39:30 raspberrypi hass[731]: 2017-07-25 19:39:30 WARNING (MainThread) [homeassistant.setup] Setup of light is taking over 10 seconds.
Jul 25 19:39:31 raspberrypi hass[731]: 2017-07-25 19:39:31 ERROR (Thread-5) [homeassistant.components.sensor.snmp] Please check the details in the configuration file
Jul 25 19:39:32 raspberrypi hass[731]: 2017-07-25 19:39:32 WARNING (MainThread) [homeassistant.helpers.entity] Update of media_player.spotify is taking over 10 seconds
Jul 25 19:39:32 raspberrypi hass[731]: 2017-07-25 19:39:32 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
Jul 25 19:39:34 raspberrypi hass[731]: 2017-07-25 19:39:33 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state media_player.unnamed_device=unknown; volume_level=0, is_volume_m...9:20.770572+01:00
Jul 25 19:39:35 raspberrypi hass[731]: 2017-07-25 19:39:35 INFO (Thread-3) [homeassistant.components.device_tracker.nmap_tracker] Scanning...
Jul 25 19:39:37 raspberrypi hass[731]: 2017-07-25 19:39:37 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
Jul 25 19:39:46 raspberrypi hass[731]: 2017-07-25 19:39:46 WARNING (MainThread) [homeassistant.components.device_tracker] Updating device list from nmap_tracker took longer than the scheduled scan interval 0:00:12
Hint: Some lines were ellipsized, use -l to show in full.

Okay it loads now, it just took a long time.

Ya my HA takes about a minute to load as well, normal. If you want the full low down run a tail -f /var/log/syslog that’s where the most detailed bits of HA info you’ll find.

I try is , but automation.yaml was incorrect .

anyone can help? thx.

2017-09-08 08:57:49 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['value']. Got None. (See /config/configuration.yaml, line 146). Please check the docs at https://home-assistant.io/components/automation/
2017-09-08 08:57:49 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['value']. Got None. (See /config/configuration.yaml, line 146). Please check the docs at https://home-assistant.io/components/automation/
2017-09-08 08:57:49 WARNING (MainThread) [homeassistant.components.group] Group 'all_automations' doesn't exist!

Likely bad formatting, post your config.

My automations.yaml.

- alias: Monitor Traffic In
  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 Out
  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) ) }}'

Did you add the input_sliders?

:grinning:Thanks for reminding me.

it’s works now.

In case anyone is interested, I tried to make this as easy to install as possible, and turned it into a package for my configuration. Everything is located here: https://github.com/mconway/homeassistant-config . The only thing I wasn’t able to include was the customize section because apparently that is not supported within a package.

4 Likes

Thanks @mconway this is awesome!

1 Like