My sensor reports a percentage of the meassured value. With a given MIN and MAX value I want to calculate the “real” value into a new Item. This is my rule, but nothing happens.
rule CalcCurrent
when
Item Ponik1Amp changed or
Item Ponik1AmaxCV changed
then
var Number x = Ponik1Amp.state as DecimalType
var Number in_min = 0
var Number in_max = 100
var Number out_min = Ponik1AminCV as DecimalType
var Number out_Max = Ponik1AmaxCV as DecimalType
var Number y = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
postUpdate(Ponik1ACV,y)
end
Please use VSCode as editor with the openhab extension.
And use the log when you save a rule as this gives you feedback when something goes awry.
Rule Name not in double quotes
out_max is not out_Max
Ponik1AmaxCV is not Ponik1AmaxCV.state
Object types Number vs. primitiv types.
Hope this helps a little:
rule "CalcCurrent"
when
Item Ponik1Amp changed or
Item Ponik1AmaxCV changed
then
var x = TestScenes.state as DecimalType
var in_min = 0
var in_max = 100
var out_min = Ponik1AminCV.state as DecimalType
var out_max = Ponik1AmaxCV.state as DecimalType
var y = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
//postUpdate(Ponik1ACV, y.toString )
Ponik1ACV.postUpdate( y )
end
Edit: thank you @mhilbush, added this and the missing toString.