SNMP OID sensor

Hi,

Currently playing with OID for SNMP to read values of my Draytek Vigor 2925. I haven’t had a lot of luck finding anything useful but did come across the below sensor which gives router type, CPU, Memory, Build No, Version etc etc. I’ve been unable to find another OID which displays these sensors individually.

Question: Are you able to break this sensor up from within home assistant to show each item individually or am I stuck with the above output

Yaml Code:

  • platform: snmp
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.1.1.0
    name: ‘Draytek’

Thanks Nick

1 Like

Use the template sensor.

Thank you VDRainer for the suggestion but I’m still confused as to what “value_template” I would need to use to display the data

I found the below example and tried to use it but the state is “unknown”. This makes sense cause I haven’t told the sensor how to look for the data “Memory Usage”. This is where my lack of json knowledge kicks me the bum.

  • platform: snmp
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.1.1.0
    name: “Draytek Memory Usage”
    value_template: “{{ value_json.State }}”

Any suggestion on how to break this up?

Thanks Nick

sensor:
  - platform: template
    sensors:
      draytek_cpu_usage:
        friendly_name: "Draytek CPU Usage"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('sensor.draytek', 'memory_usage') }}"

Also you can use snmpwalk to find exact OID for each value, I use Paessler SNMP Tester which has GUI

Thank you LbDab for you assistants, I’ve added this to my config but it doesn’t read the information from the sensor

 - platform: template
   sensors:
     draytek_cpu_usage:
       friendly_name: "Draytek CPU Usage"
       unit_of_measurement: '%'
       value_template: "{{ state_attr('sensor.draytek', 'cpu_usage') }}"

I’ve connected to my router using “SnmpB” and “Manage Engine Mib Browser” but was unable to find these values as a standalone OID. I will take a look at snmpwalk maybe this might display them differently but not hopeful I will find a solution

Thanks again Nick

I think the state is a list in a string not attributes. I think you’d need to use state and use some string extraction to get each part into individual sensors.

Thank you Holdestmade for the suggestion will research displaying state list vs attributesvand see what I can work out.

Does anyone have documents connecting Draytek 2925 with HA? I have opened snmp on Draytek 2925 but I am not sure how to connect to HA?

This may help with setting your Draytek sensor, I added the below code in my config file

Output from snmp sensor
image

  • platform: snmp
    host: 192.168.11.1
    baseoid: 1.3.6.1.2.1.1.3.0
    name: ‘SNMP Draytek Uptime’
    value_template: >-
    {% set time = (value | int) | int %}
    {% set minutes = ((time % 360000) / 6000) | int%}
    {% set hours = ((time % 8640000) / 360000) | int %}
    {% set days = (time / 8640000) | int %}
    {%- if time < 60 -%}
    Less then 1 min
    {%- else -%}
    {%- if days > 0 -%}
    {{ days }}d
    {%- endif -%}
    {%- if hours > 0 -%}
    {%- if days > 0 -%}
    {{ ’ ’ }}
    {%- endif -%}
    {{ hours }}hr
    {%- endif -%}
    {%- if minutes > 0 -%}
    {%- if days > 0 or hours > 0 -%}
    {{ ’ ’ }}
    {%- endif -%}
    {{ minutes }}min
    {%- endif -%}
    {%- endif -%}

  • platform: snmp
    host: 192.168.11.1
    baseoid: 1.3.6.1.2.1.1.1.0
    name: ‘SNMP Draytek’

  • platform: template
    sensors:
    draytek_model:
    friendly_name: “SNMP Draytek Model”
    value_template: “{{ states.sensor.snmp_draytek.state.split(‘:’)[1] | replace (‘, Version’,‘’) | trim }}”

    draytek_firmware_usage:
    friendly_name: “SNMP Draytek Firmware Usage”
    value_template: “{{ states.sensor.snmp_draytek.state.split(‘:’)[2] | replace (‘, Build Date/Time’,‘’) | trim }}”

    draytek_cpu_usage:
    friendly_name: “SNMP Draytek CPU Usage”
    unit_of_measurement: ‘%’
    value_template: “{{ states.sensor.snmp_draytek.state.split(‘:’)[4] | replace (‘, Memory Usage’,‘’) | trim }}”

    draytek_memory_usage:
    friendly_name: “SNMP Draytek Memory Usage”
    unit_of_measurement: ‘%’
    value_template: “{{ states.sensor.snmp_draytek.state.split(‘:’)[5] | replace (‘, CPU Usage’,‘’) | trim }}”

Above code will produce the following splitting the SNMP output nicely
image

1 Like

You might consider stripping off the “%” signs in the template and then adding the | float jinja2 filter to convert the string into a numeric value. Then you can have graphs and stuff.

To illustrate, I have a bunch of sensors that use MQTT as means of transporting the measurements, but they have human readable strings in them, including units, in the MQTT payload. While that’s nice to look at, I want these to be numbers. So I define sensors that look something like this:

  - platform: mqtt
    expire_after: 300   # genmon MQTT flushes out MQTT updates every 60 seconds
    name: Genmon Mon Load
    unit_of_measurement: '%'
    state_topic: '19916/generator/Monitor/Platform Stats/CPU Utilization'
    value_template: '{{ value | regex_replace(" *%","") | float | round(1) }}'

where that regexp pattern strips off zero or more spaces and the trailing % character from the string. You could probably adapt something like this to your problem.

Just what I was looking for! Thanks

can you share your file?