Skip to content

[apollo_air-1] Add configurable DPS310 pressure offset#78

Merged
TrevorSchirmer merged 4 commits intobetafrom
dps310-pressure-offset
Feb 27, 2026
Merged

[apollo_air-1] Add configurable DPS310 pressure offset#78
TrevorSchirmer merged 4 commits intobetafrom
dps310-pressure-offset

Conversation

@bharvey88
Copy link
Copy Markdown
Contributor

@bharvey88 bharvey88 commented Feb 24, 2026

Version: 26.2.24.1

What does this implement/fix?

Adds a user-configurable pressure offset (DPS310 Pressure Offset) to the DPS310 sensor, following the same pattern already used for the SEN55 temperature and humidity offsets. The offset is exposed as a number entity (CONFIG category, ±100 hPa range, 0.1 hPa step, persists across reboots). A lambda filter applies it to the reported pressure value.

The offset is applied in hPa (the sensor's native unit) regardless of how Home Assistant displays the value. The SCD40's ambient pressure compensation source (dps310pressure) automatically benefits from the corrected value.

Types of changes

  • Bugfix (fixed change that fixes an issue)
  • New feature (thanks!)
  • Breaking change (repair/feature that breaks existing functionality)
  • Dependency Update - Does not publish
  • Other - Does not publish
  • Website of github readme file update - Does not publish
  • Github workflows - Does not publish

Checklist / Checklijst:

  • The code change has been tested and works locally
  • The code change has not yet been tested

If user-visible functionality or configuration variables are added/modified:

  • Added/updated documentation for the web page

Summary by CodeRabbit

  • New Features
    • Added a user-configurable pressure offset for DPS310 sensor readings (adjustable -100.0 to 100.0 hPa, default 0.0, 0.1 increments).
    • Offset is applied to reported pressure values and is persisted across restarts for consistent calibration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 24, 2026

Warning

Rate limit exceeded

@bharvey88 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ea20805 and c1de808.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Walkthrough

Added a new public numeric template entity number.dps310_pressure_offset and updated the DPS310 pressure sensor to apply that offset via a lambda filter. Also bumped the substitutions.version value.

Changes

Cohort / File(s) Summary
DPS310 pressure offset + version bump
Integrations/ESPHome/Core.yaml
Added number.dps310_pressure_offset (template number; range −100.0–100.0 hPa, step 0.1, restore_value, initial 0.0, entity_category: CONFIG, optimistic). Updated sensor.dps310pressure to apply offset with filters: - lambda: return x + id(dps310_pressure_offset).state;. Bumped substitutions.version from "25.12.18.2" to "26.2.24.1".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble code with whiskers bright,
A pressure tweak to set it right.
Offset dances, numbers play,
The sensor hums a clearer day. 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: adding a configurable pressure offset feature for the DPS310 sensor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dps310-pressure-offset

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Integrations/ESPHome/Core.yaml (1)

460-460: ⚠️ Potential issue | 🟡 Minor

DPS310 self-test checks offset-corrected pressure value, risking spurious failures

The condition at line 460 evaluates id(dps310pressure).state, which applies the offset filter (x + id(dps310_pressure_offset).state). With the offset range set to ±100 hPa, a user configuring a large offset before running the test could cause a healthy sensor to fail or a faulty one to pass. The test should either read the raw pre-filter pressure value or document this behavior and require the offset to be reset to 0.0 before testing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Integrations/ESPHome/Core.yaml` at line 460, The self-test currently compares
the offset-corrected value via id(dps310pressure).state (which includes
id(dps310_pressure_offset).state), so large user offsets can cause false
failures; change the lambda used for the test to read the sensor's
raw/pre-filter pressure value instead of the filtered .state (e.g., use the
sensor's raw/get_raw API or .raw_state accessor) or alternatively add a
precondition and documentation requiring id(dps310_pressure_offset).state == 0.0
before running the test; update the lambda reference (the lambda comparing
id(dps310pressure).state) and any docs to reflect the chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 228-229: The DPS310 pressure filter currently adds the stored
offset (lambda: return x + id(dps310_pressure_offset).state) which reverses the
sign convention used by SEN55 offsets; change the DPS310 filter lambda to
subtract the stored offset (use id(dps310_pressure_offset).state with a minus)
so a positive offset lowers the reported pressure like the existing
sen55_temperature_offset and sen55_humidity_offset do, and scan for other DPS310
or SEN55 offset usages to ensure consistent sign handling across filters.
- Around line 228-229: Add a NaN guard to the filter lambda so it does not
propagate NaN from the offset sensor into dps310pressure: inside the lambda used
in the sensor filters (the one referencing id(dps310_pressure_offset).state)
check whether id(dps310_pressure_offset).state is NaN (e.g. using isnan(...) or
std::isnan(...)) and if it is return the raw reading (x) unchanged, otherwise
return x + id(dps310_pressure_offset).state; update only that lambda to perform
this conditional check.

---

Outside diff comments:
In `@Integrations/ESPHome/Core.yaml`:
- Line 460: The self-test currently compares the offset-corrected value via
id(dps310pressure).state (which includes id(dps310_pressure_offset).state), so
large user offsets can cause false failures; change the lambda used for the test
to read the sensor's raw/pre-filter pressure value instead of the filtered
.state (e.g., use the sensor's raw/get_raw API or .raw_state accessor) or
alternatively add a precondition and documentation requiring
id(dps310_pressure_offset).state == 0.0 before running the test; update the
lambda reference (the lambda comparing id(dps310pressure).state) and any docs to
reflect the chosen approach.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e523911 and 7f8a507.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Comment thread Integrations/ESPHome/Core.yaml Outdated
Comment on lines +228 to +229
filters:
- lambda: return x + id(dps310_pressure_offset).state;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Offset sign convention is the opposite of existing SEN55 offsets — will confuse users

The existing temperature and humidity offsets both subtract the stored value:

# lines 257, 263 — existing pattern
lambda: return x - id(sen55_temperature_offset).state;
lambda: return x - id(sen55_humidity_offset).state;

The DPS310 filter adds the stored value:

lambda: return x + id(dps310_pressure_offset).state;

This creates an opposite semantic: for SEN55 a positive offset lowers the reported value ("sensor reads high, dial it down"), while for DPS310 a positive offset raises the reported value. A user who has already learned the SEN55 convention will enter the wrong sign when calibrating the DPS310.

For consistency with the existing offset pattern, consider flipping the sign (or, if the additive convention is intentional, apply it consistently to SEN55 too and document the difference explicitly):

🐛 Proposed fix to align sign convention
       filters:
-        - lambda: return x + id(dps310_pressure_offset).state;
+        - lambda: return x - id(dps310_pressure_offset).state;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Integrations/ESPHome/Core.yaml` around lines 228 - 229, The DPS310 pressure
filter currently adds the stored offset (lambda: return x +
id(dps310_pressure_offset).state) which reverses the sign convention used by
SEN55 offsets; change the DPS310 filter lambda to subtract the stored offset
(use id(dps310_pressure_offset).state with a minus) so a positive offset lowers
the reported pressure like the existing sen55_temperature_offset and
sen55_humidity_offset do, and scan for other DPS310 or SEN55 offset usages to
ensure consistent sign handling across filters.

⚠️ Potential issue | 🟡 Minor

Add a NaN guard in the filter lambda

If dps310_pressure_offset has not yet restored its value from flash when the first DPS310 reading arrives, id(dps310_pressure_offset).state will be NaN, which would propagate NaN into dps310pressure—and then straight into the SCD40 ambient_pressure_compensation_source. The guard is cheap and prevents silent compensation errors.

🛡️ Proposed fix
       filters:
-        - lambda: return x + id(dps310_pressure_offset).state;
+        - lambda: |-
+            float offset = id(dps310_pressure_offset).state;
+            return isnan(offset) ? x : x + offset;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Integrations/ESPHome/Core.yaml` around lines 228 - 229, Add a NaN guard to
the filter lambda so it does not propagate NaN from the offset sensor into
dps310pressure: inside the lambda used in the sensor filters (the one
referencing id(dps310_pressure_offset).state) check whether
id(dps310_pressure_offset).state is NaN (e.g. using isnan(...) or
std::isnan(...)) and if it is return the raw reading (x) unchanged, otherwise
return x + id(dps310_pressure_offset).state; update only that lambda to perform
this conditional check.

Comment thread Integrations/ESPHome/Core.yaml
@TrevorSchirmer TrevorSchirmer merged commit 5a3ffa6 into beta Feb 27, 2026
11 checks passed
@TrevorSchirmer TrevorSchirmer deleted the dps310-pressure-offset branch February 27, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants