# Calculate sealevel pressure

I’m just getting started with openhab2. I got myself a pressure sensor (BME280) and it is working fine so far However I’d like to be able to convert the absolute pressure from the sensor to sealevel equivalent pressure.

I understand there was an action for this in openhab 1.9 (https://docs.openhab.org/addons/actions/weather/readme.html) but it seems like it hasn’t been ported to openhab2 yet.

So without the action available I tried to do the calculation myself according to this PHP example (https://www.symcon.de/forum/threads/6480-Relativen-Luftdruck-aus-absoluten-Luftdruck-errechnen#post53339) which I’m trying to recreate as a rule.

I’m not really sure about all the Types and how to use the java operations, and I’m getting all kinds of errors… so maybe someone can help me with my “draft” for a rule.

``````rule "Sealevel Pressure"

when

then

var Number h = 481.9
var Number temp = Temp_aussen.state as DecimalType
var Number pascal = Druck_hpa.state as DecimalType
var Number g = 9.80665
var Number R = 287.05
var Number T = 273.15
var Number Ch = 0.12
var Number E

if (temp < 9.1) {
var Number E = 5.6402 * (-0.0916 + Math::log(0.06 * temp))
}

if (temp >= 9.1) {
var Number E = 18.2194 * (1.0463 + Math::log(-0.0666 * temp))
}

var Number a = 0.0065
var Number xp = (h * g) / (R * (T + temp + (Ch * E) + (a * (h/2))))

var Double sealevel = pascal * (Math::log(xp))
postUpdate(Druck_sealevel, sealevel)

end
``````

Of course if there is an easier way like installing the 1.9 action, I’d be happy with that as well.