Calculation with items that use Units of Measurement ("%" or "°C")

I’m running openHAB 3.3 and would like to calculate something (here: the heat index as mentioned here: [SOLVED]How to calculate temperature real feel (feels like, heat index) - #10 by martiniman). I encounter problems during the calculation probably because I calculate with items that use Units of Measurement.

Problem:

  • The code runs smoothly, but the heat index calculation is off (e.g. 5450 °C)
  • From what I can see, it’s because of the way the temperature and relative humidity is formated on my system / comes in via HomematicIP without any stateDescription / Pattern formating. When I print out those two variables via…
    logWarn("notifications", "Temperature: " + Thermostat_Wohnzimmer_ActualTemperature.state.toString + ", Relative humidity: " + Thermostat_Wohnzimmer_Humidity.state.toString)
    it reads:
    “Temperature: 26.2 °C, Relative humidity: 41 %
  • I believe the wrong calculation occurs because the items use “Units Of Measurement” (the strings “°C” and “%”).

Question: Is there a way to get rid of the strings during the calculation?

Should help

Try not to do that; work with the units.

Thanks!

… is a fair description btw. :wink:

This example here…

… was the puzzle piece which I was missing.

Got the formula working, so thanks a lot! :slight_smile: