Good, please tick the solution post, thanks
Just out of curiousity (since I donāt fully understand this piece of code), what does the pipe character do here?
It tells the DSL compiler to use UoM
DSL: Domain specific Language (The language used for rules)
UoM: Units Of Measurements
To put it another way, that is all one āvariableā. Not a number, a temperature. Not just 0 , but 0Ā°C
The pipe bar ("|") is the unit delimiter used in the rules DSL for separating the Number from the AbstractUnit when defining a QuanityType.
Originally, this was []ā¦
The OH documentation has a general discussion of Units of Measure and also details on the use of QuantityType in the rules DSL. The helper library documentation has an example of defining a QuantityType in scripted automation.
Okā¦ but which difference does it make in this context? Is there any difference between comparing Outsite_Temp.state with this as opposed to comparing to just zero?
Because apples donāt compare with oranges. If you compare a temperature with a number, it makes no sense.
āIs the current temperature above 15?ā is nonsense without saying 15 what - C? F? K?
But I make comparisons like that all the time in my rulesā¦ Is it a matter of how the Item is set up?
Yes. Is your Item just a Number or is it a Number:Temperature
Ah. Yep, theyāre all just Number. Iāll put on my remember-list not to ever change that, seems like it would break quite much here
Thanks for the explanations!
Many folks introduction to Quantity Types comes when they use a weather binding or zwave thermostat - when the binding knows what a value represents rather than being some arbitrary number, it may insist on correct Item type.
Itās worth discussing what UoM actually does for us.
Letās say you are in the U.S. so you are used to Ā°F but you are using some device that only reports the temperature in Ā°C. In this case the Item will be storing Ā°C. In the Rule, because you are used to the far superior Ā°F you want to compare the Itemās state to 50 Ā°F. Without UoM, you would have to add the calculation to convert from Ā°C to Ā°F prior to the calculation. If you want to see the value on your sitemap as Ā°F you would have to create a JS tranform or use a Rule and Proxy Item to see the Itemās state as Ā°F.
With UoM, all you need to do is indicate that you want to see the state as Ā°F or compare the state to a Ā°F and the conversion from Ā°C to Ā°F is handled for you.
With stuff like temperature (Number:Temperature) and percent (Number:Dimensionless) this doesnāt sound so compelling. But what about stuff like Angle, Energy (watts, joules, etc), Pressure, Speed, etc. If you need to do certain calculations, it can be really handy to have degrees converted to radians automatically.
It is unfortunate though that it does impose a little bit of a burden on the Rules coder as they have to know and understand the difference between a Number and a Number:Temperature since both are handled differently.
Thanks @rlkoshak for the explanation, makes me understand what itās about! All my sensors report in the same units (Celsius, Watts, Lux, mm/h) so Iāve never needed to think much about it.
Btw, I was about to say that I really prefer SI units. But then I realized that would mean I ought to use Kelvin for temperatures, so Iāll simply say nothing patronizing about Fahrenheit