From 45126e79bbd8016cb2c0c959ea0f0604567f8f61 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 6 Sep 2021 15:55:43 +0200 Subject: [PATCH] Added a SNMP based (Juniper) internet bandwidth monitor. --- automations.yaml | 20 ++++++++++++++++++++ configuration.yaml | 3 +++ customize.yaml | 16 ++++++++++++++++ groups.yaml | 13 +++++++++++++ input_number.yaml | 11 +++++++++++ recorder.yaml | 4 ++++ sensors.yaml | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+) create mode 100644 input_number.yaml diff --git a/automations.yaml b/automations.yaml index 6597912..d95b56c 100644 --- a/automations.yaml +++ b/automations.yaml @@ -309,3 +309,23 @@ - schlafzimmer - wohnzimmer mode: single +- id: snmp_monitor_traffic_in + alias: Monitor Traffic In + trigger: + platform: state + entity_id: sensor.snmp_wan_in + action: + - service: input_number.set_value + data_template: + entity_id: input_number.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) ) }}' +- id: snmp_monitor_traffic_out + alias: Monitor Traffic Out + trigger: + platform: state + entity_id: sensor.snmp_wan_out + action: + - service: input_number.set_value + data_template: + entity_id: input_number.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) ) }}' diff --git a/configuration.yaml b/configuration.yaml index f47cf3e..3656e38 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -29,6 +29,9 @@ webostv: !include webostv.yaml homeassistant: customize: !include customize.yaml +# Include helpers +input_number: !include input_number.yaml + # Spotify spotify: !include spotify.yaml diff --git a/customize.yaml b/customize.yaml index feef757..9f53db5 100644 --- a/customize.yaml +++ b/customize.yaml @@ -2,3 +2,19 @@ media_player.wohnzimmer_main: icon: mdi:audio-video sensor.home_assistant_datenbankgrosse: icon: mdi:database +sensor.download_speed_mean: + friendly_name: 'SNMP Download Average' + icon: mdi:speedometer +sensor.upload_speed_mean: + friendly_name: 'SNMP Upload Average' + icon: mdi:speedometer +sensor.ping_time_mean: + friendly_name: 'SNMP Ping Average' + icon: mdi:clock-fast +sensor.wan_traffic_in_mean: + friendly_name: 'WAN Download Average' + icon: mdi:download +sensor.wan_traffic_out_mean: + friendly_name: 'WAN Upload Average' + icon: mdi:upload + diff --git a/groups.yaml b/groups.yaml index e69de29..0ea1acf 100644 --- a/groups.yaml +++ b/groups.yaml @@ -0,0 +1,13 @@ + snmp_monitor: + name: Bandwith Monitoring + entities: + - sensor.internet_speed_in + - sensor.internet_speed_out + - sensor.wan_traffic_in_mean + - sensor.wan_traffic_out_mean + snmp_raw_values: + name: SNMP Raw Values + entities: + - sensor.snmp_wan_in + - sensor.snmp_wan_out + diff --git a/input_number.yaml b/input_number.yaml new file mode 100644 index 0000000..fe57db3 --- /dev/null +++ b/input_number.yaml @@ -0,0 +1,11 @@ + 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 diff --git a/recorder.yaml b/recorder.yaml index cd3f518..08aaf6f 100644 --- a/recorder.yaml +++ b/recorder.yaml @@ -28,6 +28,10 @@ entities: - sun.sun # Don't record sun data - sensor.fritzbox_device_uptime + - sensor.snmp_wan_in + - sensor.snmp_wan_out + - input_number.internet_traffic_delta_in + - input_number.internet_traffic_delta_out # event_types: # - call_service # Don't record service calls diff --git a/sensors.yaml b/sensors.yaml index 04b8076..be4b10a 100644 --- a/sensors.yaml +++ b/sensors.yaml @@ -18,3 +18,37 @@ query: 'SELECT table_schema "database", Round(Sum(data_length + index_length) / 1048576, 2) "value" FROM information_schema.tables WHERE table_schema="homeassistant" GROUP BY table_schema;' column: 'value' unit_of_measurement: MB +# SNMP (Juniper) router traffic sensor + - platform: snmp + name: snmp_wan_in + host: !secret router_ip + community: !secret router_community + baseoid: .1.3.6.1.2.1.2.2.1.10.511 + + - platform: snmp + name: snmp_wan_out + host: !secret router_ip + community: !secret router_community + baseoid: .1.3.6.1.2.1.2.2.1.16.511 + + - platform: template + sensors: + internet_speed_in: + friendly_name: 'Internet Speed IN' + value_template: '{{ ((states.input_number.internet_traffic_delta_in.state | float ) / 1000000 ) | round(2) }}' + unit_of_measurement: 'Mbps' + + - platform: template + sensors: + internet_speed_out: + friendly_name: 'Internet Speed OUT' + value_template: '{{ ((states.input_number.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