效果图:
搬运自https://community.home-assistant.io/t/snmp-bandwidth-monitor/7122
先在路由器中开启SNMP,我的路由器是UBNT ERX
configuration.yaml中添加:
baseoid可能不同设备不一样,可以用snmpwalk软件确认,下载地址: https://support.solarwinds.com/S ... erformance_Monitor_(NPM)/SolarWinds_SNMP_Walk_A_new_tool_for_collecting_SNMP_MIB_walks
oid在线查询: http://oid-info.com
### EDGE ROUTER ###
- platform: snmp
name: snmp_wan_in
host: 192.168.2.1
baseoid: 1.3.6.1.2.1.2.2.1.16.2
- platform: snmp
name: snmp_wan_out
host: 192.168.2.1
baseoid: 1.3.6.1.2.1.2.2.1.10.2
- platform: template
sensors:
internet_speed_in:
friendly_name: 'Internet Speed In'
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 Out'
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
## 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
automations中添加:
- 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) ) }}'
customs中添加:
sensor.internet_speed_in:
friendly_name: '下载速度'
icon: mdi:speedometer
sensor.internet_speed_out:
friendly_name: '上传速度'
icon: mdi:speedometer
sensor.wan_traffic_in_mean:
friendly_name: '下载平均速度'
icon: mdi:download
sensor.wan_traffic_out_mean:
friendly_name: '上传平均速度'
icon: mdi:upload
好了 搞定!
|