Hi.
This feels like a question that could be answered by reading documentation and forum, so apologies in advance, but I can’t seem to find it…
I have some Items that I’ve been keeping in .items files because I needed Expire for them. Since upgrading to 3.0 I thought I might as well move them in to the gui instead. It’s just that since doing that I can’t seem to get the value from them without also getting the unit.
When having them in .items files I could set their label to something like “Utetemperatur [%.1f °C]” and the value I got out was simply “7.2” for Utetemperatur.state in my rules (though I never really understood the logic of the label controlling the format of the value), but now that doesn’t seem to work any more.
When doing something like “(Utetemperatur.state as DecimalType).doubleValue” now I get “Could not cast 7.3 °C to org.openhab.core.library.types.DecimalType”.
10:42:48.391 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'temp.rules', using it anyway:
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
edit: I think it should be QuantityType<Temperature>. Testing and reporting back
There are situations where it makes sense to strip the units, but rather than stepping backwards, why not modify your rules to take advantage of QuanityType? If you post a rule example using DecimalType, we could show you how to migrate it.
That’s exactly what I did After the suggestion from @crnjan above I changed DecimalType to QuantityType<Temperature> and after that everything works nice again.
I guess what others are trying to point out is that there is more than meets the eye with QuanityType - if you “strip” out just the doubleValue as an example, you are loosing the unit - consider having
if((Utetemperatur.state as QuantityType).doubleValue > 20)
vs
if (Utetemperatur.state > 20|°C)
both works fine if Utetemperatur has temperature in °C, but you will see strange results if Utetemperatur would have °F for first example above, while the second one would take unit into account and convert values before comparing them.
Ah… Good points. I guess the core learning of this is that if the system knows more about my value than just a pure digit it can do smarter stuff
However, in this particular case I need the pure value in order to send it to a rest api that only accepts a number. Converting it to a double is perfect for that.