Mapdb not restoring 'Number:Length' values correctly

I’m having a weird problem with restoring number values for mm of rainfall with mapdb. Everything else is restoring on start up successfully, except these number.

Example item:
Number:Length rain_23pm "Rain from 11pm [%.1f %unit%]" (gRain)

This value is updated every day at 11pm with the past hours rain fall. gRain calculates the total rainfall for the last 24 hours from the 24 hourly values.

When these values are updated each hour, the value is stored as mm:
2020-06-06 23:00:00.055 [vent.ItemStateChangedEvent] - rain_23pm changed from 0.0 mm to 0.25 mm

However, when these values are restored, they are all restored as 0.0m (not mm). Even in the above case where the value is 0.25mm, the stored value is 0.0m.

Here is the log from a system restore:
2020-06-06 23:36:04.313 [vent.ItemStateChangedEvent] - rain_23pm changed from NULL to 0.0 m

I’m thinking that is it maybe converting 0.25mm and rounding to 0.0m, but not sure.

Any ideas on what i’m doing wrong or why the values are not being restored correctly?


I believe the formatting also doubles as default units for Quantity Types.
So, here you haven’t given a default for your Item.
I think it will then use the system default - metres I’d guess.

When your binding updates the Item, it will do so with units. mm in your case. And update the Item to use mm.

I’m not quite sure what gets stored in persistence under these circumstances - you can find out with REST API. Certainly it’s just a number, persistence has as yet no idea about units.

Come restore time, your Item won’t yet have any units. I would however expect either 0.25m or 0.00025m, 0.0m is a puzzle.

Thanks for the information! How do i set a default unit for an item? Will start there and see where i get to.


[%.1f mm]

Originally envisaged for UI purposes only, the openAB framework now also looks at this sometimes for QuantityType default handling. I don’t know if that includes persistence.