From e9624de5049aa739e00cf814a31d081752c221f6 Mon Sep 17 00:00:00 2001 From: Gorden Mende Date: Wed, 15 Jul 2026 12:31:07 +0200 Subject: [PATCH] modified snmp stuff --- sensors.yaml | 329 ++++++++++++++++++++++++++++++++++++++++++++++---- template.yaml | 234 ++++++++++------------------------- 2 files changed, 367 insertions(+), 196 deletions(-) diff --git a/sensors.yaml b/sensors.yaml index 0d4e75b..fee996a 100644 --- a/sensors.yaml +++ b/sensors.yaml @@ -12,30 +12,311 @@ # device_class: gas # attribute_templates: # state_class: total_increasing +- platform: snmp + name: "HPE Switch Uptime" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.1.3.0 + value_template: "{{ (value | float / 6000) | round(1) }}" + unit_of_measurement: "Minuten" - - platform: snmp - name: "HPE Switch Uptime" - host: 192.168.0.4 - community: realm_local - baseoid: 1.3.6.1.2.1.1.3.0 - value_template: "{{ (value | float / 6000) | round(1) }}" - unit_of_measurement: "Minuten" +## port1 +- platform: snmp + name: "HPE Switch Port 1 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.1 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 - - platform: snmp - name: "HPE Switch Port 1 Status" - host: 192.168.0.4 - community: realm_local - baseoid: 1.3.6.1.2.1.2.2.1.7.1 - value_template: > - {% if value == '1' %} - Connected - {% else %} - Disconnected - {% endif %} +- platform: snmp + name: "HPE Switch Port 1 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.1 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 1 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.1 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port2 +- platform: snmp + name: "HPE Switch Port 2 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.2 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 2 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.2 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 2 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.2 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port9 +- platform: snmp + name: "HPE Switch Port 9 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.9 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 9 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.9 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 9 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.9 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port10 +- platform: snmp + name: "HPE Switch Port 10 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.10 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 10 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.10 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 10 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.10 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port11 +- platform: snmp + name: "HPE Switch Port 11 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.11 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 11 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.11 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 11 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.11 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port19 +- platform: snmp + name: "HPE Switch Port 19 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.19 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 19 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.19 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 19 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.19 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port21 +- platform: snmp + name: "HPE Switch Port 21 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.21 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 21 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.21 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 21 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.21 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port23 +- platform: snmp + name: "HPE Switch Port 23 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.23 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 23 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.23 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 23 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.23 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## port24 +- platform: snmp + name: "HPE Switch Port 24 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.24 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 24 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.24 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port 24 Traffic Out" + host: 192.168.0.4 + community: IhrCommunityString + baseoid: 1.3.6.1.2.1.2.2.1.16.24 + unit_of_measurement: "Bytes" + scan_interval: 10 + +## porttrk1 +- platform: snmp + name: "HPE Switch Port Trk1 Status" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.7.54 + value_template: > + {% if value == '1' %} + Connected + {% else %} + Disconnected + {% endif %} + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port Trk1 Traffic In" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.10.54 + unit_of_measurement: "Bytes" + scan_interval: 10 + +- platform: snmp + name: "HPE Switch Port Trk1 Traffic Out" + host: 192.168.0.4 + community: realm_local + baseoid: 1.3.6.1.2.1.2.2.1.16.54 + unit_of_measurement: "Bytes" + scan_interval: 10 - - platform: snmp - name: "HPE Switch Port 1 Traffic In" - host: 192.168.0.4 - community: realm_local - baseoid: 1.3.6.1.2.1.2.2.1.10.1 - unit_of_measurement: "Bytes" diff --git a/template.yaml b/template.yaml index b9a2dc2..e1a0de4 100644 --- a/template.yaml +++ b/template.yaml @@ -1,176 +1,66 @@ - sensor: - - unique_id: pws_temperature - name: "PWS Temperatur aktuell" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","temperature")}}' + - name: "HPE Trunk 1 Download Rate" + unique_id: hpe_trunk_1_download_rate + unit_of_measurement: "Mbit/s" + device_class: data_rate + state: > + {% set bytes = states('sensor.hpe_switch_port_trk1_traffic_in') | float(0) %} + {% set last_bytes = state_attr('sensor.hpe_trunk_1_download_rate', 'last_bytes') | float(0) %} + {% set now_ts = as_timestamp(now()) %} + {% set last_ts = state_attr('sensor.hpe_trunk_1_download_rate', 'last_ts') | float(now_ts) %} + + {% set delta_bytes = bytes - last_bytes %} + {% set delta_time = now_ts - last_ts %} + + {% if delta_time > 0 and delta_bytes >= 0 and last_bytes > 0 %} + {{ ((delta_bytes * 8) / delta_time / 1000000) | round(2) }} + {% else %} + 0.0 + {% endif %} + attributes: + last_bytes: "{{ states('sensor.hpe_switch_port_trk1_traffic_in') }}" + last_ts: "{{ as_timestamp(now()) }}" - sensor: - - unique_id: pws_indoortemperature - name: "PWS Innentemperatur" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","indoortemperature")}}' + - name: "HPE Trunk 1 Upload Rate" + unique_id: hpe_trunk_1_upload_rate + unit_of_measurement: "Mbit/s" + device_class: data_rate + state: > + {% set bytes = states('sensor.hpe_switch_port_trk1_traffic_out') | float(0) %} + {% set last_bytes = state_attr('sensor.hpe_trunk_1_upload_rate', 'last_bytes') | float(0) %} + {% set now_ts = as_timestamp(now()) %} + {% set last_ts = state_attr('sensor.hpe_trunk_1_upload_rate', 'last_ts') | float(now_ts) %} + + {% set delta_bytes = bytes - last_bytes %} + {% set delta_time = now_ts - last_ts %} + + {% if delta_time > 0 and delta_bytes >= 0 and last_bytes > 0 %} + {{ ((delta_bytes * 8) / delta_time / 1000000) | round(2) }} + {% else %} + 0.0 + {% endif %} + attributes: + last_bytes: "{{ states('sensor.hpe_switch_port_trk1_traffic_out') }}" + last_ts: "{{ as_timestamp(now()) }}" - sensor: - - unique_id: pws_windchill - name: "PWS Windchill" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","windchill")}}' + - name: "HPE Trunk 1 Gesamt Durchsatz" + unique_id: hpe_trunk_1_total_rate + unit_of_measurement: "Mbit/s" + device_class: data_rate + state: > + {% set download = states('sensor.hpe_trunk_1_download_rate') | float(0) %} + {% set upload = states('sensor.hpe_trunk_1_upload_rate') | float(0) %} + {{ (download + upload) | round(2) }} + - sensor: - - unique_id: pws_dewpoint - name: "PWS Taupunkt" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","dewpoint")}}' -- sensor: - - unique_id: pws_humidity - name: "PWS Luftfeuchte" - unit_of_measurement: "%" - state: '{{state_attr("sensor.wetterstation","humidity")}}' -- sensor: - - unique_id: pws_luftdruck - name: "PWS Luftdruck" - unit_of_measurement: "hPa" - state: '{{state_attr("sensor.wetterstation","airpress_rel")}}' -- sensor: - - unique_id: pws_tendenz - name: "PWS Tendenz" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","tendency")}}' -- sensor: - - unique_id: pws_precipitation - name: "PWS Niederschlag Summe" - unit_of_measurement: "mm" - state: '{{state_attr("sensor.wetterstation","precipitation")}}' -- sensor: - - unique_id: pws_rainrate - name: "PWS Regenmenge" - unit_of_measurement: "mm/h" - state: '{{state_attr("sensor.wetterstation","rainrate")}}' -- sensor: - - unique_id: pws_itsraining - name: "PWS es regnet" - unit_of_measurement: ".." - state: '{{state_attr("sensor.wetterstation","itsraining")}}' -- sensor: - - unique_id: pws_windspeed - name: "PWS Windgeschwindigkeit" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation","windspeed")}}' -- sensor: - - unique_id: pws_gustspeed - name: "PWS Windboen" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation","gustspeed")}}' -- sensor: - - unique_id: pws_winddirection - name: "PWS Windrichtung" - unit_of_measurement: "°Grad" - state: '{{state_attr("sensor.wetterstation","winddirection")}}' -- sensor: - - unique_id: pws_indoorhumidity - name: "PWS Luftfeuchte innen" - unit_of_measurement: "%" - state: '{{state_attr("sensor.wetterstation","indoorhumidity")}}' -- sensor: - - unique_id: pws_wetbulbtemperature - name: "PWS Glaskugel" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation","wetbulbtemperature")}}' - -# -# ++++++ Wetterstation Davis Daten 24h ++++++++++ -# -- sensor: - - unique_id: pws_temp_min - name: "PWS Temperatur min" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation_vortag","temp_min")}}' -- sensor: - - unique_id: pws_temp_max - name: "PWS Temperatur max" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation_vortag","temp_max")}}' -- sensor: - - unique_id: pws_taupunkt_min - name: "PWS Taupunkt min" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation_vortag","dewpoint_min")}}' -- sensor: - - unique_id: pws_taupunkt_max - name: "PWS Taupunkt max" - unit_of_measurement: "°C" - state: '{{state_attr("sensor.wetterstation_vortag","dewpoint_max")}}' -- sensor: - - unique_id: pws_luftfeuchte_min - name: "PWS Luftfeuchte min" - unit_of_measurement: "%" - state: '{{state_attr("sensor.wetterstation_vortag","hum_min")}}' -- sensor: - - unique_id: pws_luftfeuchte_max - name: "PWS Luftfeuchte max" - unit_of_measurement: "%" - state: '{{state_attr("sensor.wetterstation_vortag","hum_max")}}' -- sensor: - - unique_id: pws_luftdruck_min - name: "PWS Luftdruck min" - unit_of_measurement: "hPa" - state: '{{state_attr("sensor.wetterstation_vortag","airp_rel_min")}}' -- sensor: - - unique_id: pws_luftdruck_max - name: "PWS Luftdruck max" - unit_of_measurement: "hPa" - state: '{{state_attr("sensor.wetterstation_vortag","airp_rel_max")}}' -- sensor: - - unique_id: pws_windspeed_min - name: "PWS Windgeschwindigkeit min" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation_vortag","windspeed_min")}}' -- sensor: - - unique_id: pws_windspeed_max - name: "PWS Windgeschwindigkeit max" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation_vortag","windspeed_max")}}' -- sensor: - - unique_id: pws_winddir_max - name: "PWS Windrichtung max" - unit_of_measurement: "Grad" - state: '{{state_attr("sensor.wetterstation_vortag","winddir_max")}}' -- sensor: - - unique_id: pws_gustspeed_min - name: "PWS Windboen min" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation_vortag","gustspeed_min")}}' -- sensor: - - unique_id: pws_gustspeed_max - name: "PWS Windboen max" - unit_of_measurement: "km/h" - state: '{{state_attr("sensor.wetterstation_vortag","gustspeed_max")}}' -- sensor: - - unique_id: pws_gustdir_max - name: "PWS Boen Richtung" - unit_of_measurement: "" - state: '{{state_attr("sensor.wetterstation_vortag","gustdir_max")}}' -- sensor: - - unique_id: pws_rainrate_max - name: "PWS Regenmenge max" - unit_of_measurement: "mm/h" - state: '{{state_attr("sensor.wetterstation_vortag","rainrate_max")}}' -- sensor: - - unique_id: pws_precipitation_24h - name: "PWS Regenmenge 24h" - unit_of_measurement: "mm/24h" - state: '{{state_attr("sensor.wetterstation_vortag","precipitation_24h")}}' -#++++++++++++ Windrichtung Kompass ++++++++ -- sensor: - - name: "Windrichtung" - state: > - {% set direction = ['N','NNO','NO','ONO','O','OSO','SO','SSO','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %} - {% set degree = states('sensor.pws_windrichtung')|float %} - {{ direction[((degree+11.25)/22.5)|int] }} - icon: mdi:windsock - unique_id: windrichtung - - -# Regen letzte Stunde -- sensor: - - unique_id: pws_precipitation_1h - name: "PWS Regen letzte h" - unit_of_measurement: "mm/h" - state: '{{state_attr("sensor.niederschlag_letzte_stunde","precipitation_1h")}}' + - name: "HPE Trunk 1 Upload Rate Negativ" + unique_id: hpe_trunk_1_upload_rate_negativ + unit_of_measurement: "Mbit/s" + device_class: data_rate + state: > + {% set upload = states('sensor.hpe_trunk_1_upload_rate') %} + {% if upload in ['unknown', 'unavailable', 'none'] or not upload %} + 0.0 + {% else %} + {{ (upload | float(0) * -1) | round(2) }} + {% endif %}