SNMP Sensor features

Hi there,

Thanks alot for an amazing product. Really enjoy playing around with it and configuring it.
I have a question regarding the SNMP sensor that I’ve been playing around with and I have a few questions/suggestions.
So, currently I use it to monitor the interfaces on my router. The values come back in bytes and I then need to convert them into MiB (Mibibytes) using the template sensor and then round that value off to 1 decimal point. I have four interfaces that I’m monitoring, so each one requires a call/new instance of the SNMP monitor, followed by the data conversion using the template monitor for all 4 and once again another 4 instances of the template sensor need to be run.

  1. Would it be possible to add a value_template to the SNMP monitor so that a template monitor isn’t required?
  2. Can the SNMP monitor be modified to call all values of the all interfaces using one instance rather than multiple?

Am I running the SNMP sensor in the correct manner or can it already be run using one instance and returning multiple values?

If these modifications can be made, then other systems can be monitored in an extremely ‘light’ manner. This will bring down the load by quite a chunk.
Please let me know if this is possible

Thanks

Would be possible as the SNMP sensor is just receiving values.

With code changes, yes. We have a bunch of sensors which are gathering everything and then splitting the values into different sensors (eg. the weather platforms). I doubt that it would be efficient for SNMP because the responses can be pretty big (without further containment) and those information needs to be processed some way or another.

I see the point here. For systems and network monitoring are already a lot of tools available which are optimized for speed and resource usage. It is always an option to get the needed information from an intermediary tool like netdata, collectd, or alike in a slow pace.

Yes a value_template for the snmp sensor would be super handy.

Voted! I would love value_template for SNMP sensors!

Oh, and unit_of_measurement: of course!

Can you give me an example where that’s needed? An OID usually return a value which doesn’t needed be the extracted.

That’s already available.

Here are 2 examples:

- platform: snmp
  name: "UPS Runtime"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.3.6.1.0

- platform: snmp
  name: "UPS Status"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.2.1.0

The first sensor returns the estimated runtime of the UPS connected to my NAS, in seconds.
The second sensor returns the status of that same UPS, as either ‘OL’ or ‘OB’.

So I have the following template sensors to make those values more readable:

- platform: template
  sensors:
    ups_runtime_templated:
      value_template: >-
        {%- if states.sensor.ups_runtime -%}
          {%- set minutes = states.sensor.ups_runtime.state | multiply(0.016666666666667) | round(0) -%}
          {%- if minutes == 1 -%}
            1 minute
          {%- else -%}
            {{ minutes }} minutes
          {%- endif -%}
        {%- else -%}
          unknown
        {%- endif -%}
    ups_status_templated:
      value_template: >-
        {%- if is_state('sensor.ups_status', 'OL') -%}
          On power
        {%- elif is_state('sensor.ups_status', 'OB') -%}
          On battery
        {%- endif -%}

EDIT: unit_of_measurement does indeed work…not sure why I never just tried it.

Looks some how familiar…aah :wink:

https://github.com/home-assistant/home-assistant/issues/2767

Mmhmm :wink:

At this point, I’m hoping for a fix for that issue so my 4 float-based SNMP sensors would actually work. The SNMP sensor supporting value_template would be a nice bonus.

1 Like

Hi All,

So here is what I currently use:
SNMP Sensor:
baseoid: 1.3.6.1.2.1.2.2.1.16.1

And then to change the value, which is in bytes, I use the following template sensor to convert to Mebibytes(Total)
value_template: ‘{{ states.sensor.snmp.state | multiply(0.00000095367) | round | int }}’

This outputs a whole number as for the value in Mebibytes.
I also experience a problem as once this value goes over 4000MiB (Around 4GB), the counter reports as unknown or 0. The only fix is to restart the monitored SNMP device, in this case, my router. I understand that this is an issue with SNMP v1. Is there a way to force SNMP v2c to query the router and if so, where can a I specify authentication under the sensor…

Is your uptime template also for the normal linux snmp uptime or is this a different conversion?

I doubt it, it’s device specific (APC UPS connected to a Synology NAS).

Hi there,
Sorry for the late reply. By the way, you guys are making life rather expensive :smile: All I wanna do is buy more and more HA compliant devices. I think a robot vacuum is next on the list.
Anyway, back to the SNMP value_template request. So, I use the following template to pull current data sent/receive on an interface on my router:
{{ states.sensor.interface-up/down.state | multiply(0.00000095367) | round | int }}
And that returns a value in MB on how much data has been sent or received on the specified interface. It works, but just thought that it could just be run using the SNMP sensor rather than having to template

I use snmp to check the toner level and status of my printers.

A few features have been added to the SNMP sensor, including value_template. See this PR on GitHub for more info.

I suspect these changes will go live with the release of Home Assistant 0.52.

Please add SNMP Trap support. It would be nice to recieve SNMP messages from my NAS

2 Likes