UoM and pressure unit issues

  • Platform information:
    • Hardware: Intel amd64
    • OS: Debian 12 stable
    • Java Runtime Environment: OpenJDK Runtime Environment 21.10-(Zulu-17.30+15-linux_x64)
    • openHAB version: 4.0.1-1

All,
My units have been behaving rather well with the OH4 upgrade, but I can’t figure out how to get air pressure values to do that.
My system is set to imperial units (living in the US), however, I’d like to use Pa (hPa, rather) for air pressure values.

I may be oldschool, but I prefer to do configuration in .things and .items files, so I hope I can get this figured out using those.

Data feeds into OH via MQTT in a .things file. That does not incluce a unit, although adding one in the .things file does not affect anything. Here’s the relevant part"

Type number : pressure1 "Pressure1" [ stateTopic="raspi1/pressure1" ]

The item is defined in an .items file. I’ve tried two different versions (not at the same time, of course):

Number:Pressure weather_raspi1_pressure1 "Pressure1 RPi BME280" <pressure> (pressure) {channel="mqtt:topic:home:Raspi1:pressure1",stateDescription=" "[pattern="%.2f hPa"]}
Number:Pressure weather_raspi1_pressure1 "Pressure1 RPi BME280 [%.2f hPa]" <pressure> (pressure) {channel="mqtt:topic:home:Raspi1:pressure1"}

Both give me the same result, which is the hPa-Value (as delivered by MQTT) with “inHg” as the unit.
Visible on Karaf:

weather_raspi1_pressure1 (Type=NumberItem, State=1015.89 inHg, Label=Pressure1 RPi BME280, Category=pressure, Groups=[pressure])

The sitemap even tries to convert that value to hPa.
Of course, I can fix this by creating the item as “Number” instead of “Number:Pressure”, but there must be a better way than that.

Thanks!

You need to apply the unit like described here:

It’s also possible to provide unit for the MQTT Thing. So probably something like:

Type number : pressure1 "Pressure1" [ stateTopic="raspi1/pressure1", unit="hPa" ]

and:

Number:Pressure weather_raspi1_pressure1 "Pressure1 RPi BME280" <pressure> (pressure) {channel="mqtt:topic:home:Raspi1:pressure1", unit="hPa"}

Now this is strange. Setting the unit in the MQTT-things file before I wrote the post resulted in no change.

Configuring the item like you suggested did not change anything, either.
But changing the order in the items file like the release notes suggest, that worked:

Number:Pressure weather_raspi1_pressure1 "Pressure1 RPi BME280 [%.2f hPa]" <pressure> (pressure) {unit="hPa", channel="mqtt:topic:home:Raspi1:pressure1"}

I really did not expect the order to matter here, but it seems it does.