You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not a bug. You cannot divide temperatures unless you are working in K. °C and F are not on an absolute scale.
QuantityTypes also allow dividing e.g. °C by F, and the result would become unpredictable.
Here is a PR with a discussion on this and related topics, that intended to fix unexpected behaviour: openhab/openhab-core#3792
Thanks for the info. It explains well the recognized behavior.
Quantity('13.57 K').divide('25 K') provides the expected result OK: 0.5428
In my examples, °F and °C have been implicitly transformed to K before doing the divide operation. This also explains the result >= 0,9.
Actually in my use case I'm dividing two Δ temperatures with each other - now I know, that I need to implement the entire formula in K.
const min = Quantity("40 °C");
const max = Quantity("66.5 °C");
let water_SOC_wrong = water.subtract(min).divide(max.subtract(min)).toUnit('%');
let water_SOC_right = water.toUnit("K").subtract(min.toUnit("K")).divide(max.toUnit("K").subtract(min.toUnit("K"))).toUnit('%');
I hope the discussion helps others who have the same issue.
When dividing Temperature Quantities (°C or °F) the result is unexpected:
My test code:
Expected Behavior
4 times
0.5428
Current Behavior
Your Environment
openHAB 4.1.1 Release Build
The text was updated successfully, but these errors were encountered: