Simple rule math help

Gday,

Could someone point me in the right direction with subtracting a value from a sensor reading.

This is what I have but it does not seem to be working, both items are Number items.

rule "Calibration"
when
		Item Sensor1Temp changed
then
		Sensor1TempCAL = Sensor1Temp - 2
end

Regards,
George

1 Like

I think you have to have put:

import java.lang.Math.*

At the top of your rules.

You want to calculate with the .state of the item, not the item itself.

Thanks guys,
I have put, import java.lang.Math.* at the top of the rules.

watou do you mean to do it this way?

rule "Calibration"
when
		Item Sensor1Temp changed
then
		Sensor1TempCAL=Sensor1Temp.state-2
end

Regards,
George

Maybe this would work? Assuming Sensor1TempCAL is an item…

import org.openhab.core.library.types.DecimalType

rule "Calibration"
when
		Item Sensor1Temp changed
then
		Sensor1TempCAL.postUpdate((Sensor1Temp.state as DecimalType) - 2)
end
2 Likes

watou,

That did the trick. Thank you!

I think I need to do some work and understand the postupdate command a bit more.

Regards,
George

1 Like

Where does the Sensor1Temp item get its value? If it’s a binding that supports transforms (like MQTT, for example), then you could replace the word default in the in-binding string with JS(calibrate.js) and make a file transform/calibrate.js:

(function(temp){
return temp - 2;
})(input)

So you item Sensor1Temp’s value would arrive already adjusted, with no need for a rule and second item. Just a thought – your way obviously works, too, and you may have good reason to do it your way!

watou,

Sensor1Tem is coming in from a zwave aeotec multisensor 6. I know there is a calibration method via habmin however when I tried that way it wouldn’t save for temperature or humidity (of course the two I can measure here). For some reason Lux and UV would accept calibration adjustments via habmin but not temp and humidity.
After a few hours of googling it does appear others are having similar challenges with the product. I logged a ticket with the manufacturer to see if they know of a fix.

Not to worry I thought I could just calibrate it within openhab instead.

Does the transform method work with zwave items?

Regards,
George

No, so until the vendor can update the firmware to allow temperature calibration, the proxy item/rule approach you are using is the best alternative I’m aware of.

Hey, any news on this ?

My Aeotec Multisensor is also off by 2 degrees and the calibration with habmin doesnt work.

Not sure, if its a habmin/zwave-binding error or an aeotec-firmware-bug

Hi, I am getting my bar indicators data via Mqtt. Normally, it shows a number like 0.50 high. What kind of js should I do for this? I have never done before. I would be glad if you explain in detail. Thank you…