SNMP - temperature sensor returns two values as a string, how to convert to a float value?

I’m reading a SNMP temperature sensor from a NAS WD Cloud EX4 device, I got the result but the value is a string:

snmpwalk -Os -c public -v 2c 192.168.0.216 1.3.6.1.4.1.5127.1.1.1.1.7.7.0
iso.3.6.1.4.1.5127.1.1.1.1.1.7.0 = STRING: “Centigrade: 60 Fahrenheit: 140”

In the configuration file I configured it as follows:

 - platform: snmp
    name: 'NAS_BKP temperature'
    host: 192.168.0.216
    baseoid: 1.3.6.1.4.1.5127.1.1.1.1.1.7.0
    community: 'public'
    version: '2c'
    unit_of_measurement: 'C'
    value_template: '{{(value | float)}}'

Using the line value_template: '{{(value | float)}}' the return is 0.00

Without the line the return is:

The value that is of interest to me is Centigrate, how can I cut this value from the string “Centigrade: 60 Fahrenheit: 140”?

Probably not the most elegant way, but it works:

value_template: "{{ value.split(':')[1].split(' ')[1] }}"

The result was just the string Fahrenheit!

It worked by changing the value from 1 to 0:

value_template: "{{ value.split(':')[1].split(' ')[0] }}"

Thanks

Ah, sorry about the typo. You got though. :+1:

Hi everyone, I found this thread after fiddling out some SNMP-readings on a similar device (EX2Ultra) for myself. I was successfull with the disk temperatures, but system temperature results in “unknown”.
I think I have the exact same platform description as advised above:

- platform: snmp
    name: 'NAS System Temperature'
    host: 192.168.178.21
    baseoid: 1.3.6.1.4.1.5127.1.1.1.8.1.7.0
    community: 'public'
    version: '2c'
    unit_of_measurement: '°C'
    value_template: "{{ value.split(':')[1].split(' ')[0] }}"
    scan_interval: 60

Any ideas how to track that down?

Well, first get and show the actual value returned by SNMP.

A “similar” device doesn’t garantee exact same readings

You are right, and in fact I was doing that in the meantime… before posting over here, I allready evaluated the OIDS with a MIB browser (iReasoning), and that came out as
Centigrade:51 Fahrenheit:123

But the value in I get in HomeAssistant is
0x43656e746967726164653a3531200946616872656e686569743a313233
means the right value in HEX.

I allready tried to convert that with
value_template: "{{ value|int(base=16) }}"
but no luck. Result:
1816998406599388799644624818724751109110565163680710675210123212829235

Thanks for chiming in, BTW :slight_smile:

I tried it also "the other way around:

value_template: "{{ value.split(' ')[0].split(':')[1] }}"

Result is then empty:

Your drive inserts a tab (0x09) which make the string not directly translatable.

You could go through a command_line sensor that calls a python script to decode the string, but it’s quite convoluted.
Maybe @123 has a simpler solution?

Seems to me that something isn’t set to decode the data correctly. Instead of converting each two-bytes into its ASCII character equivalent, it’s passing everything through undecoded.

I am unfamiliar with any Jinja2 filter able to perform the required decoding.

Ok, that means there‘s no trivial procedure atm do get this.

Thanks for confirming that, so I do not waste more time on that. If you have another idea in the future, I‘d like to try that out and learn some advanced stuff.