unit
Metatdata is about storing the data, state description pattern
is how to display data.
So when using units of measurement, don’t care about converting values at all, this is the job of UoM, but set the unit ONCE to a reasonable unit (depends on the measurement itself, obviously) and set the state description pattern to whatever you want (well, at lest matching to your measurement unit).
So for example a given measurement, coming through mqtt is 853 (integer) and from documentation we know that this value is °F, but multiplied by 10 (just to make it a bit more complex…).
Instead of calculations just set the unit inside the channel to d*°F
(this is deci degree Fahrenheit, not very common…)
Now at the Item, as we want the measurement to be stored as Kelvin we set the Item to
Number:Temperature
and use metadata unit
to K
.
We want to get the display to be in °C (with one decimal), so we are setting the state description pattern to %.1f °C
and we’re good to go.
BUT: you should never change the unit metadata to another unit, as this will mix up the persistence. So be wise when starting configuration of an UoM Item
Of course you can change the unit afterwards, but then it’s best option to delete the persisted data to avoid messed up charts.
You can always change the pattern to your needs, though, as this will only affect the current displayed value.