Calculated Items Rule (questioen nr. 8.923.876.234)

Hello community

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

  Item Ponik1Amp changed or
  Item Ponik1AmaxCV changed
	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


What am I doing wrong?

kind regards

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.

  1. Rule Name not in double quotes
  2. out_max is not out_Max
  3. Ponik1AmaxCV is not Ponik1AmaxCV.state
  4. Object types Number vs. primitiv types.

Hope this helps a little:

rule "CalcCurrent"
    Item Ponik1Amp changed or
    Item Ponik1AmaxCV changed
    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 )

Edit: thank you @mhilbush, added this and the missing toString.

One other thing… Item methods are preferable to actions for the reasons described here.

1 Like

stupid me!

thanks a lot!!!

edit: @Josar THANK YOU VERY MUCH for the link - that helps a giga-lot!!!

1 Like