Support UoM
9037568 opened this issue · comments
When attempting to use a UoM value in a widget (eg. Number:Temperature), statements that use sprintf fail. Getting the raw value still works.
For example, if the item tomTempL
is an Item of type Number:Temperature, the following statement produces a valid value (e.g. 79
):
<h2 style="margin-bottom:1em;">{{itemValue('tomTempL')}}</h2>
while this statement fails, producing the value {{'%.1f' | sprintf: itemValue('tomTempL')}}
:
<h2 style="margin-bottom:1em;">{{'%.1f' | sprintf: itemValue('tomTempL')}}</h2>
Can the sprintf function be updated to allow for UoM values? Failing that, can we get a new function to format them?
the following statement produces a valid value (e.g. 79)
Are you sure it's not suffixed with the unit e.g. 79 °F
? Normally states of dimensioned items include the unit after a space. If that's the case, it has to be removed from the state before you can use sprintf (or it won't be recognized as a number, this is probably mentioned in your browser's developer console i.e. "expected Number but got String").
Something like:
<h2 style="margin-bottom:1em;">{{'%.1f' | sprintf: itemValue('tomTempL').split(' ')[0]}}</h2>
In any case, proper handling of items with UoM is planned for the next release - so I'll keep this issue open for tracking ;)
openHAB 2.3.0 Release Build and #1316
My Item Number:Temperature Temp1 "T1[%.1f %unit%]"
sitemap works
number of decimals not limited
works, but no UoM-functions and only actualised after value is changed
All works fine, if it's a non UoM-item.
https://community.openhab.org/t/solved-split-item-result-in-temp/47988
As far as I can see, this was implemented in Habpanel itself with
itemValue('abc').split(' ')[0]
So, in every custom widget, this must also be done.
IMHO, it would be better to have another itemValue() variant that returns the raw value without the unit.
I hope that openHAB itself provides functionality for that, that could be used by Habpanel.