diff --git a/lib/bme280/README.md b/lib/bme280/README.md index 5b91f94f..9432bb9e 100644 --- a/lib/bme280/README.md +++ b/lib/bme280/README.md @@ -186,6 +186,16 @@ sensor.sea_level_pressure_hpa = 1020.0 --- +### Dew Point + +```python +dp = sensor.dew_point() +``` + +Returns the dew point temperature in **degrees Celsius**, computed from the current temperature and humidity using the Magnus formula. + +--- + ## Data-Ready Status ```python @@ -313,7 +323,7 @@ Performs a soft reset, re-reads calibration data, and re-applies default configu | Standby time | ✅ | ❌ | ✅ | ❌ | ⚠️ Fixed 500ms | ❌ | | Altitude | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | | Sea-level pressure | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | -| Dew point | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | +| Dew point | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | | Soft reset | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | | Full reset + recalibration | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | | power_off / power_on | ✅ | ❌ | ⚠️ Via mode | ❌ | ❌ | ❌ | diff --git a/lib/bme280/bme280/device.py b/lib/bme280/bme280/device.py index a0108e07..c2ef8bab 100644 --- a/lib/bme280/bme280/device.py +++ b/lib/bme280/bme280/device.py @@ -409,3 +409,17 @@ def altitude(self, pressure_hpa=None): """ p = self.pressure_hpa() if pressure_hpa is None else pressure_hpa return 44330.0 * (1.0 - (p / self.sea_level_pressure_hpa) ** 0.1903) + + def dew_point(self): + """Return dew point temperature in degrees Celsius. + + Uses the Magnus formula (Alduchov & Eskridge, 1996) with the + current temperature and relative humidity readings. Both values + come from a single ``read()`` call to ensure consistency. + """ + from math import log + + t, _, rh = self.read() + rh = max(rh, 0.01) + gamma = log(rh / 100.0) + 17.625 * t / (243.04 + t) + return 243.04 * gamma / (17.625 - gamma) diff --git a/tests/scenarios/bme280.yaml b/tests/scenarios/bme280.yaml index fca42d32..c849596a 100644 --- a/tests/scenarios/bme280.yaml +++ b/tests/scenarios/bme280.yaml @@ -630,3 +630,27 @@ tests: result = abs(alt - 33.7) < 1.0 expect_true: true mode: [mock] + + # ----- Dew point ----- + + - name: "dew_point() returns plausible value" + action: script + script: | + # Mock: ~25.08°C, ~50.57%RH → dew point ~14.11°C + dp = dev.dew_point() + result = abs(dp - 14.11) < 0.5 + expect_true: true + mode: [mock] + + - name: "dew_point() matches Magnus formula for mock readings" + action: script + script: | + from math import log + t, _, rh = dev.read() + # Compute expected dew point from Magnus formula + gamma = log(rh / 100.0) + 17.625 * t / (243.04 + t) + expected = 243.04 * gamma / (17.625 - gamma) + dp = dev.dew_point() + result = abs(dp - expected) < 0.01 + expect_true: true + mode: [mock]