How to add custom UOM for absolute humidity

Hi everyone,

I am currently working through my UOMs to get them working with OH4.

While I have no issue with relative humidity in % (add unit=“%” in item description), I could not figure out, how to display UOMs that are not pre-defined in OpenHAB like absolute humidity in g/m³.


Number:Dimensionless UG_AZ_WRG_abs_Humidity_In "Absolute Humidity Office In [%.1f g/m³]" {channel="http:url:bayernluft_wrg:abs_Humidity_In" [profile="transform:REGEX", function="s/,/\\./g"] }

Is there a way to set “custom UOMs”?

Well, I just found out that I can solve this specific topic by changing the item to Number:Density.

Number:Density UG_AZ_WRG_abs_Humidity_In "Absolute Humidity Office In [%.1f g/m³]" {unit="g/m³",channel="http:url:bayernluft_wrg:abs_Humidity_In" [profile="transform:REGEX", function="s/,/\\./g"] }

But it would still be nice to know if it is possible to also define custom UOMs.

No, it’s not possible to define custom UoM. It’s more than just a collection of characters after a number. OH can automatically convert between compatible units and combine units in ways that make sense. That requires code.

You can submit a PR with the code necessary to support a new unit for sure (that’s how absolute humidity got added not that long ago). And if your new unit is a combination of already existing units and modifiers you can combine those (e.g. l/h is a combination of liters and hours).