Number to number Transformation


I am desperately looking for a way to assess a temperature reading. So 0-15°C = 0 points 15-20°C is then one point.
I have realized this by using an if structure. But now I need the function several times. I tried a SCALE transformation but I always get strings back but I want to continue to calculate with it.
It may well be that I have not yet arrived at the OpenHAB universurm and still think too much in C.
Thanks for your help.


var hour_point6 = transform("SCALE", "temp_points.scale",localDailyForecast6hMinTemperature.state.toString) + transform("SCALE", "temp_points.scale",localDailyForecast6hMaxTemperature.state.toString)

  • Platform information:
    • Hardware: Raspberry 3 und 4
    • OS: Openhabian
    • openHAB version:2.5

That’s correct, but strings like “3” can be parsed to decimal or integer numbers e.g.

If you’re going to do something like postUpdate to an Item, that will parse by itself

Your scale is strange, since you repeat some numbers. Is 15 °C 0 or 1?

Instead of the transform, how about this?

var hour_point6 = (if ((localDailyForecast6hMinTemperature.state as DecimalType) - 15 > 0) ((localDailyForecast6hMinTemperature.state as DecimalType)  - 15 + 5) / 5 else 0) + (if ((localDailyForecast6hMaxTemperature.state as DecimalType) - 15 > 0) ((localDailyForecast6hMaxTemperature.state as DecimalType) - 15 + 5) / 5 else 0)

Thanks a lot. I have implemented the solution of rossko57 and it works fine.
The solution using IF queries I had so far but when I use it on more than two places I get the wish to do it in a sub-function. Especially because the values are not fixed yet.