I’ve pretty much finished my Awair air quality sensor binding, but I had to force the precision of the temperature value to two decimal places in code:
return new QuantityType<>(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP), stateUnit);
value, which contains the temperature reading in this case, has a crazy level of precision (10 decimal places or more). The state unit is SIUnits.CELSIUS (when using metric measurements). The corresponding channel is defined in
thing-types.xml as follows:
<channel-type id="temperature"> <item-type>Number:Temperature</item-type> <label>Temperature</label> <description>Temperature</description> <category>Temperature</category> <state readOnly="true" pattern="%.2f %unit%"/> </channel-type>
but the formatting seems to be ignored. I had the same problem with humidity, which came with a ton of decimals. Humidity has the state unit SmartHomeUnits.PERCENT. This is the channel definition:
<channel-type id="humidity"> <item-type>Number:Dimensionless</item-type> <label>Humidity</label> <description>Humidity level</description> <category>Humidity</category> <state readOnly="true" pattern="%.2f %%"/> </channel-type>
I set the precision to zero in code in the same way as temperature.
Is this the right way to do it, or is there some other configuration somewhere? Thanks.