Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP sensor not processing float values (correctly) #2767

Closed
fanaticDavid opened this issue Aug 9, 2016 · 22 comments
Closed

SNMP sensor not processing float values (correctly) #2767

fanaticDavid opened this issue Aug 9, 2016 · 22 comments

Comments

@fanaticDavid
Copy link
Contributor

fanaticDavid commented Aug 9, 2016

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):
0.25.2 (installed using AiO installer)

Python release (python3 --version):
3.4.2

Component/platform:
SNMP sensor, used on a Raspberry Pi 3 (with Raspbian Jessie Lite)

Description of problem:
I use SNMP sensors to track the status and some statistics of the APC UPS connected to my Synology NAS. The result of that looks like this:

schermafbeelding 2016-08-09 om 02 17 19

The bottom 2 sensors work just fine. The top 4 sensors, however, return unusual results.

Expected:
Expecting float values, but getting unusual string values instead

Problem-relevant configuration.yaml entries and steps to reproduce:
The sensors in my HASS config are defined as follows:

- platform: snmp
  name: "UPS Battery Charge"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.3.1.1.0

- platform: snmp
  name: "UPS Battery Voltage"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.3.2.1.0

- platform: snmp
  name: "UPS Input Voltage"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.4.1.1.0

- platform: snmp
  name: "UPS Load"
  host: xxx.xxx.xxx.x
  community: home
  baseoid: 1.3.6.1.4.1.6574.4.2.12.1.0

- 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

- 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 states.sensor.ups_status %}
          {% if states.sensor.ups_status.state == 'OL' %}
            On power
          {% elif states.sensor.ups_status.state == 'OB' %}
            On battery
          {% endif %}
        {% else %}
          unknown
        {% endif %}

Using snmpwalk on my MacBook, I was able to determine that this issue occurs when a float value is returned.

Testing the top 4 broken sensors:
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.3.1.1.0 enterprises.6574.4.3.1.1.0 = Opaque: Float: 100.000000
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.3.2.1.0 enterprises.6574.4.3.2.1.0 = Opaque: Float: 27.200001
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.4.1.1.0 enterprises.6574.4.4.1.1.0 = Opaque: Float: 231.00000
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.2.12.1.0 enterprises.6574.4.2.12.1.0 = Opaque: Float: 3.000000

Testing the bottom 2 working sensors:
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.3.6.1.0 enterprises.6574.4.3.6.1.0 = INTEGER: 9375
snmpwalk -Os -c home -v 2c xxx.xxx.xxx.x 1.3.6.1.4.1.6574.4.2.1.0 enterprises.6574.4.2.1.0 = STRING: "OL"

Traceback (if applicable):
none

Additional info:
Using templates to change the values to floats doesn't work, not that I was expecting it to

@fabaff
Copy link
Member

fabaff commented Aug 11, 2016

I've tested the SNMP sensor and it works with the following types:

  • String
  • Integer
  • Gauge32
  • Counter32
  • Timeticks
  • OID

This seems to confirm your observation. Unfortunately I can't get my hands on an OID that returns a float at the moment.

@fabaff
Copy link
Member

fabaff commented Aug 11, 2016

Can you please test #2788 for your setup? Thanks.

@fanaticDavid
Copy link
Contributor Author

fanaticDavid commented Aug 11, 2016

@fabaff I hate to sound stupid but...how would I go about that? I'm currently running the release version of HASS installed with the AiO installer. If you could give me a nudge in the right direction, I'd be more than happy to test it for you. I am by no means a developer, though.

I did try it a "dirty" way by simply renaming the original snmp.py file and creating a new snmp.py file with the new code. Unfortunately, even after restarting HASS, the result is the same as before. On the contrary, I have another SNMP sensor for a different OID which now returns "100.0" instead of "100": it turned a Gauge32 value into a Float value.

@Spartan-II-117
Copy link
Contributor

has any progress been made on this?

@fanaticDavid
Copy link
Contributor Author

Nope. I'm running Home Assistant 0.43.2 and this issue still exists.

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@fanaticDavid
Copy link
Contributor Author

This is still an issue...

schermafbeelding 2017-07-17 om 19 25 16

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@fanaticDavid
Copy link
Contributor Author

fanaticDavid commented Oct 20, 2017

Still relevant with 0.55.x:

schermafbeelding 2017-10-20 om 22 54 11

@ChristianKuehnel
Copy link
Contributor

Hey @fanaticDavid,

I had a look at the issue I added support for decoding of "Opaque" types, as long as they are supported by the unerlying pyasn1 library (https://github.com/etingof/pyasn1). I'm not sure if that solves your problem, as pyasn1 does not list the type "Float". It does offer type "Real".

You can give it a try:
#11239

If that does not solve the problem, you probably need to request the Float data type in the pyasn1 project.

@keithmichael
Copy link

Hoping this get fixed soon, I can't monitor UPS battery input voltage because type is opaque

@fanaticDavid
Copy link
Contributor Author

The code from #11239 already works, it just needs to be finalized and merged 🙂

@keithmichael
Copy link

keithmichael commented Feb 5, 2018 via email

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@fanaticDavid
Copy link
Contributor Author

This is still a bug as #11239 by @ChristianKuehnel was never finished.

Personally, I switched from using SNMP to using NUT to monitor my NAS' UPS. However, since I'm not the only user who is/was affected by this bug, I would like this issue to remain open until it has been fixed.

@keithmichael
Copy link

keithmichael commented May 31, 2018 via email

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@fanaticDavid
Copy link
Contributor Author

Can anyone confirm this issue still exists? I suspect it does since #11239 was closed without being merged.

For my use case, I've switched from the SNMP component to the NUT component so I cannot test this at the moment.

@bagobones
Copy link

I don't recall which version it started working in but I have been able to pull SNMP network info from my Gigabit router now for some time where it did not work previously. I Think it is fixed, or at least I can get accurate network traffic from a EdgeRouter Now.

@cgarwood
Copy link
Member

Closing based on @bagobones report and the age of the issue. Please open a new issue if this problem still persists.

@cartwrightian
Copy link

sorry to comment on such an old issue, let me know if should open new issue.

Opaque float ends up as a hex number, tried adding value template to cast value to a float but yields 0.0

The config:

  • platform: snmp
    name: Real Power Nominal
    host: 192.168.0.4
    baseoid: 1.3.6.1.4.1.6574.4.2.21.2.0
    unit_of_measurement: "W"

In dev panel:
Entity: sensor.real_power_nominal = 0x9f780444584000

Actual value via snmpget:
% snmpget -v1 -c public nas.jazz iso.3.6.1.4.1.6574.4.2.21.2.0
iso.3.6.1.4.1.6574.4.2.21.2.0 = Opaque: Float: 865.000000

System Health

version core-2021.8.6
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.9.6
os_name Linux
os_version 5.10.52-v7l+
arch armv7l
timezone Europe/London
Home Assistant Cloud
logged_in true
subscription_expiration 6 November 2021, 00:00
relayer_connected true
remote_enabled true
remote_connected true
alexa_enabled true
google_enabled true
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Lovelace
dashboards 1
resources 0
views 5
mode storage

@lextm
Copy link
Contributor

lextm commented Mar 16, 2024

@cartwrightian you actually hit the same issue.

We finally have a patch to submit to HA. Hope it can make into the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants