Added a SNMP based (Juniper) internet bandwidth monitor.

This commit is contained in:
Marcus Scholz 2021-09-06 15:55:43 +02:00
parent 9575246cd5
commit 45126e79bb
7 changed files with 101 additions and 0 deletions

View File

@ -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) ) }}'

View File

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

View File

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

View File

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

11
input_number.yaml Normal file
View File

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

View File

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

View File

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