Enable CO2 auto calibration by default with toggle to disable#72
Enable CO2 auto calibration by default with toggle to disable#72bharvey88 wants to merge 2 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 21 minutes and 18 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR updates the ESPHome Core configuration with CO2 auto-calibration functionality. Version is bumped to 26.6.10.1, automatic self-calibration is enabled in the SCD4x sensor, and a new switch entity allows users to toggle the feature dynamically via an automation script. ChangesCO2 Auto-Calibration Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Integrations/ESPHome/Core.yaml (1)
834-846: 💤 Low valueConsider adding error handling for stop/start I2C commands.
The ASC command (0x2416) has proper error logging, but the stop (0x3F86) and start (0x21B1) commands do not check return values. If
start_periodic_measurementfails, the sensor would stop reporting CO2 until the next reboot.Since this mirrors ESPHome's pattern for forced calibration and I2C failures are rare, this is a minor resilience improvement.
♻️ Suggested improvement
- lambda: |- - id(scd40).write_command((uint16_t) 0x3F86); //stop periodic measurement + if (!id(scd40).write_command((uint16_t) 0x3F86)) { + ESP_LOGW("Apollo", "Failed to stop periodic measurement"); + } - delay: 500ms - lambda: |- id(scd40).set_automatic_self_calibration(enable); if (!id(scd40).write_command((uint16_t) 0x2416, (uint16_t) (enable ? 1 : 0))) { ESP_LOGE("Apollo", "Failed to set CO2 auto calibration"); } else { ESP_LOGI("Apollo", "CO2 auto calibration %s", enable ? "enabled" : "disabled"); } - delay: 10ms - lambda: |- - id(scd40).write_command((uint16_t) 0x21B1); //start periodic measurement + if (!id(scd40).write_command((uint16_t) 0x21B1)) { + ESP_LOGE("Apollo", "Failed to restart periodic measurement"); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Integrations/ESPHome/Core.yaml` around lines 834 - 846, The stop/start I2C commands around id(scd40) use id(scd40).write_command((uint16_t) 0x3F86) and id(scd40).write_command((uint16_t) 0x21B1) without checking return values; add the same error handling pattern used for the ASC command (0x2416) so both the stop (0x3F86) and start (0x21B1) calls check the boolean result of id(scd40).write_command, log failures with ESP_LOGE("Apollo", "... failed to stop/start periodic measurement") and optionally ESP_LOGI on success to ensure the code detects and reports I2C failures (use the existing id(scd40).set_automatic_self_calibration and the surrounding lambda blocks to place these checks).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 834-846: The stop/start I2C commands around id(scd40) use
id(scd40).write_command((uint16_t) 0x3F86) and
id(scd40).write_command((uint16_t) 0x21B1) without checking return values; add
the same error handling pattern used for the ASC command (0x2416) so both the
stop (0x3F86) and start (0x21B1) calls check the boolean result of
id(scd40).write_command, log failures with ESP_LOGE("Apollo", "... failed to
stop/start periodic measurement") and optionally ESP_LOGI on success to ensure
the code detects and reports I2C failures (use the existing
id(scd40).set_automatic_self_calibration and the surrounding lambda blocks to
place these checks).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 313af0e4-7a5b-428b-a577-0f614a3c3524
📒 Files selected for processing (1)
Integrations/ESPHome/Core.yaml
Enable the SCD40's automatic self-calibration by default (ESPHome default) so users no longer need to manually recalibrate every 1-2 years. Adds a "CO2 Auto Calibration" switch so users in spaces that never see fresh-air CO2 levels can turn ASC off and keep using the manual 420ppm calibration button instead. The switch re-applies the saved choice after every boot, since the sensor loses the setting on power loss and the scd4x component re-applies the YAML default during setup.
0c8e3a0 to
289987e
Compare
Version: 26.6.10.1
What does this implement/fix?
Enables the SCD40's automatic self-calibration (ASC) by default and adds a "CO2 Auto Calibration" switch so users can turn it off.
write_command), and restarts measurement, the same sequence the component uses for forced calibration. The saved choice is re-applied ~20 seconds after every boot, since the SCD40 loses the setting on power loss and ESPHome re-applies the YAML default during setup.calibrate_co2_valueaction are unchanged and keep working whether ASC is on or off.Why a breaking change: existing devices get ASC turned on when they update. Readings may shift over the first days as the baseline self-corrects. Users whose device sits in a space that rarely gets fresh air (a sealed office, a basement, a grow room) should turn the new switch off and keep calibrating manually. Suggest including this in the release notes.
The same change is rolling out to AIR-1 and MTR-1 (identical), and R_PRO-1 (toggle fix/rename; its ASC was already on by default). A wiki update covering all four products is ready to merge alongside the firmware releases.
Verification:
esphome compilepasses for MSR-2.yaml, MSR-2_BLE.yaml, and MSR-2_Factory.yaml (ESPHome 2026.1.3). Not yet tested on hardware.Types of changes
Checklist / Checklijst:
If user-visible functionality or configuration variables are added/modified:
🤖 Generated with Claude Code
Summary by CodeRabbit