Hi again!
I want to use HA as a dashboard to easily manage most of my network in one place.
Like another user suggested a couple of years ago, it would be nice to be able to configure snmp only once per host or be able to grab consecutive OIDs. Integrations would be easier and the snmp server would be less stressed.
I currently monitor the on/off status of each port, and check if a wire is connected to that port.
I’m not sure if such integration would be feasable as I don’t know enough about how HA backend works.
My current setup:
sensor:
- platform: snmp
name: TPLink Switch Port 1 Status
host: !secret tplink_switch_ip
auth_protocol: 'hmac-sha'
username: !secret tplink_switch_snmp_username
auth_key: !secret tplink_switch_snmp_authkey
priv_protocol: 'des'
priv_key: !secret tplink_switch_snmp_privkey
version: '3'
baseoid: 1.3.6.1.2.1.2.2.1.8.49153
accept_errors: true
switch:
- platform: snmp
name: TPLink Switch Port 1 Toggle
host: !secret tplink_switch_ip
auth_protocol: 'hmac-sha'
username: !secret tplink_switch_snmp_username
auth_key: !secret tplink_switch_snmp_authkey
priv_protocol: 'des'
priv_key: !secret tplink_switch_snmp_privkey
version: '3'
baseoid: 1.3.6.1.2.1.2.2.1.7.49153
payload_on: 1
payload_off: 2
I still need to add a template for each port to check if it’s connected, on or off, based on the status of one or both sensors depending on the values returned.
I added those entries for OIDs 1.3.6.1.2.1.2.2.1.7.49153 to 1.3.6.1.2.1.2.2.1.7.49180 (and 1.3.6.1.2.1.2.2.1.8.49153 to 1.3.6.1.2.1.2.2.1.8.49180), that is 56 requests to get the status of the ports only. I’m not monitoring the traffic yet or checking for packets error.
I have 2 possible implementations in mind, either:
- Major rewrite I think but the best, Ability to set the OIDs name and type directly in the UI (or YAML).
Pros: Only 1 integration per hardware/SNMP device, less duplication data, easier to configure, Cons: still lots of duplicate settings depending on use case.
#This is an example only to illustrate, not sure what would be the best way to approach this
snmp:
- name: tplink switch
host: !secret tplink_switch_ip
auth_protocol: 'hmac-sha'
username: !secret tplink_switch_snmp_username
auth_key: !secret tplink_switch_snmp_authkey
priv_protocol: 'des'
priv_key: !secret tplink_switch_snmp_privkey
version: '3'
oids:
- oid: 1.3.6.1.2.1.2.2.1.7.49153 # On/Off
type: 'switch'
payload_on: 1
payload_off: 2
name: Port 1
- oid: 1.3.6.1.2.1.2.2.1.8.49153 # Connected/Disconnected
type: 'sensor'
name: Port 1
value_template: >...
groups:
- payload_on: 1
type: 'switch'
name: 'more switch'
oids:
- oid: 1.3.6.1.2.1.2.2.1.7.49154
name: 'Port 2 Status' # name = tplink switch more switch port 2 status
- 1.3.6.1.2.1.2.2.1.7.49155
- 1.3.6.1.2.1.2.2.1.7.49156
This would take the name tplink switch and generate entities name: tplink_switch_port_1. I’m not sure if it would be possible to have the entity having both the connected status and the on/off status. It would know to merge them since they have the same name.
We could also add groups to elements. User would add their elements to a group, and could configure the whole group only once (payload, templates, etc). Useful if a group of OIDs return 1 for something while another group return 1 to say something else.
- Ability to set from/to OIDs
Pros: slightly less configuration duplication, Cons: can get confusing?, more code in the backend I think. I also hate that approach, but would still be better than right now.
switch:
- platform: snmp
name: TPLink Switch Toggle Port
host: !secret tplink_switch_ip
auth_protocol: 'hmac-sha'
username: !secret tplink_switch_snmp_username
auth_key: !secret tplink_switch_snmp_authkey
priv_protocol: 'des'
priv_key: !secret tplink_switch_snmp_privkey
version: '3'
baseoid: 1.3.6.1.2.1.2.2.1.7
command_oid: 1.3.6.1.2.1.2.2.1.7
from_oid: 49153
to_oid: 49180
limit: 28 #instead of to_oid?
payload_on: 1
payload_off: 2
This would get the OIDs from 1.3.6.1.2.1.2.2.1.7, then get the from and to values and create the switched for those. Switch entities would be names TPLink Switch Toggle Port X. This would only be for switches, it would need to be implemented for sensors too.
There is another thing that could get implemented but it would require more coding I think
oids: #not actual oids
- switch: 1.3.6.1.2.1.2.2.1.7.49154
status: 1.3.6.1.2.1.2.2.1.8.49154
packet_in: 1.3.6.1.2.1.2.2.1.7.49154
packet_in_discarded: 1.3.6.1.2.1.2.2.1.13.49153
label: 1.3.6.1.2.1.31.1.1.1.18.49153
#My current usecase is for port monitoring, but someone who want to monitor a PC could do
cpu_usage: 1.3.6.1.2.1.2.2.1....
ram_usage: ...
device_name: ...
As I said before, if it is possible to merge switch and sensors, it would be nice to do is_state('switch.tplink_port_1', 'is_plugged') is_state('switch.tplink_port_1', 'label') is_state('switch.tplink_port_1', 'speed') or whatever
This would take a month for me to code test and make this works, and I’m sure it wouldn’t get approved anyway for code quality or something. but if someone uses snmp and have the time, this would be awesome!
Other suggestions: Calculate bandwidth utilization, Better delta handling, counters
Thanks for reading that! <3
