[SOLVED] SNMP Binding - Transform incoming integer to float by dividing the value with 1000


I’m trying to monitor my Raspberry Pis (temperature, load, drives etc.) through snmp and want to define rules (perhaps node red) and graphs (habpanel) in openhab2. Now I’ve the problem, that I’m getting temperatures as integers with values like 49926. This is obviously not the temperature of my RPI and has to be divided through 1000.

How can I do this in OpenHAB2 unless I didn’t found a way to do this on the (remote) system side.

Is that the raspberry you are running openHAB from?
Did you have a look at the system info binding?

One of the RPIs runs openHAB, but the others not. Because of the mixed behavior I can’t use the system info binding.

Some bindings support a transform between raw data and channel. Unfortunately, not the SNMP binding.

openHAB profile feature allows a transform between channel and Item. Unfortunately, at the moment transform output is always in string form and cannot be linked to a Number Item. You could make a String Item take a state like “49.95” or “49.95 C” but that’s not much help if you want to compare the numeric value with some threshold to ring an alarm, for instance.

You’ll probably need a rule to parse and convert the SNMP raw data Item into a prettier virtual Number Item.

1 Like

I have kind of the same set-up
I use node-red on the satellite pis to report to OH

Okay, I try to learn how to do this with rules. As you mentioned, strings are no option, because it comes with a lot of disadvantages.

1 Like

Okay, found some time and finished the task.

I’ve created a new item (without a thing) that can store the temperature data. After that I’ve created a rule that looks like this:

rule "SnmpConvertTemperatureOctoprint"
    Item OctoPrintSNMPTarget_OctoprintSnmpTemperautreUnformated changed 
    var Number formatedTemperature = Math::round(((OctoPrintSNMPTarget_OctoprintSnmpTemperautreUnformated.state as Number) / 1000 * 100.0).floatValue()) / 100.0

    logInfo("Snmp_Temperature.rules", "Formated temperature is: " + formatedTemperature) 


Works like a charm. Thanks for the help.

1 Like