A number dimension for concentrations


As it is now possible to use unit hints, I was trying to add them to my Open meteo binding, in particular to the Air quality thing that I’m currently writing.
It offers multiple channels that report the current pollution status, most of which are expressed in μg/m³ and that get updated with State like this:

    new QuantityType<>(value, Units.MICROGRAM_PER_CUBICMETRE);

While this shows in the UI as a float value, it does not have any unit associated to it by default.
So I went to my xml definition file and tried this:

	<channel-type id="particulate-concentration" advanced="false">
		<item-type unitHint="μg/m³">Number</item-type>

but when I use the addon, I get this error:

cause-exception     : java.lang.IllegalArgumentException
cause-message       : A unit hint must not be set if the item type is not a number with dimension!

Sadly, I can’t figure out which of the Number: allowed item types to use, as I can’t see any related to the concentration of a matter in a given volume.

Would you have any suggestion?

Number:Density doesn’t work?

Ah yes, indeed, it could work as μg/m³ is tightly related to kg/m³

But what about grains/m³ used for pollens or even ppm/ppb used in some units.
For the last one, I could use Number:Dimensionless with a unit hint set to ppb, but for pollens, I’m not too sure.

I’ve found that density works with more than just weight in the numerator and any volume works in the denominator.

For example, I’ve used ‘Bq/m³’ with Bq being a measurement for radioactivity.

Sadly, this does not work as well as it should because I can’t properly define the grains/m³ unit in my addon code

As a result, this gives me this kind of wrong display:

The Unit metadata is totally ignored and the default kg/m³ is wrongly used instead, despite the State Description being set to %.2f %unit%

I also have the issue with a J/kg channel that I setup as Number:Energy and thus defaults to kWh which is definitely wrong.

I guess I’ll have to settle for a number without dimension and no unit hint until the addon can provide its own units.

I would say this is a bug. Assuming you don’t have errors in the logs it should not simply ignore the unit metadata and use the system default. Have you tried gr instead of the word grains? There is a small chance UoM doesn’t support the Troy weight system.

I don’t thing J/kg is an Energy type. If Joule by itself is an Energy type I don’t think the unit would support a modifier like /kg in the same unit type.

Since it measures heat capacity maybe Force would work? It might work with a Density assuming the denominator can be a weight and not just a volume. I do know that all the possible units in the world are not yet supported by OH and new units are added with some regularity.

An add-on cannot invent it’s own units though. That’s implemented in core.

Well, thing is, it’s the unit used for CAPE which is a “potential energy” measurement.

I’ll stick with “dumb” numbers for the time being, this addon needs to work with version 4.1 anyway.