When you come to do maths with that later, that also involve some other unit, “ordinary °C” in this case, openHAB is going to treat the °C elements as absolute temps and do conversions.
EDIT- afterthought; rules are loosely typed. You might have declared k as Number, but it holds a quantity type now, with units.
It’s the 2°C + 1°C = 3°C conundrum.
We mean 2°C as an absolute measured temperature, and 1°C as an interval or increment, but there’s no way to tell the difference.
That doesn’t matter while everything is in same units.
The nature of your calculation is that it can’t all be in same units, one part is “1/°C” units.
might be a complaint about °C being difficult to handle because of the offset or point of origin that make temperatures different from other quantity types.
Will this calculation work if all done in Kelvin, willit think that is linear? Conversions are easy.
If I then further process that variable m with units K (which should be dimensionless, really) and add it to the dimensionless unit y1 (defined as number) results in d being a dimensionless number as well.
d = y1 - k * x1.toUnit("K")
logInfo("test.rules", "d: {}", d)
d: 76.17333333333333333333333333333334
and the whole interpolation works when using real input for the variable x from a temperature sensor:
y = k * (Temperaturmesser2Temperatur.state as QuantityType<Temperature>).toUnit("K") + d
logInfo("test.rules", "y: {}", y)
y: 4.10666666666666666666666666666666
which should be something between 2 and 6. 4.1 is nice (and correct as I verified with my calculator)
(I now can feed in the interpolated value into a heating control system as an on-time for the heating.)
Thank goodness for that!
The maths concepts were getting way beyond me, and quite how the framework deals with “invented” units like 1/K is not at all clear. I suspect there is some ‘disregarding’ of non-standard units going on.
As a rule of thumb I find it works best to make sure all the units of the calculation are the same or, if that isn’t possible, to strip the units off when doing your calculations.
x1.toUnit("K").floatValue
Once you are done with the calculation you can add the units back on if necessary, though often you end up with an unsupported unit.