Blockly: quantity type gets lost when using persistence

In some cases the quantity type gets lost when using persistence services.
For example this is for “state average”:


I get this:

So [W] is missing on the first one.
I think it is a bug. What do you think?
I am on OH4.1.0M2.

Not in some cases. In all cases. Persistence doesn’t save the unit. You will always get just a number from a call to persistence. This is not a bug, it’s how it’s always worked.

With OH 4 and the changes to unit handling there is at least the possibility to add the units back to the value returned from persistence but that hasn’t been implemented yet (I believe there is an issue open though).

Not in all :slight_smile: When there is a return of a single value (and not a calculation) then the unit is given. See here for “minimum” or “maximum” also for “historic state”.


So from a user perspective this is not easy to understand.

There is a PR outstanding to solve this: Return units in persistence extension commands by mherwege · Pull Request #3736 · openhab/openhab-core · GitHub

1 Like

That must be new behavior then. I thought the units for all the returns were being handled by that outstanding PR @Mherwege linked to.

I think it was a result of
When setting the state of an number item with dimension, the unit will automatically be added if not provided. Restoring from persistence does not have a unit, so it is added. Persistence always returned an item when only one data point was requested, but the state of the item may not have had the unit before.

1 Like

Looking forward to test this.