Skip to content

Fix BLE deep-sleep restore using minutes math instead of hours - #69

Open
bharvey88 wants to merge 2 commits into
betafrom
fix/ble-sleep-hours
Open

Fix BLE deep-sleep restore using minutes math instead of hours#69
bharvey88 wants to merge 2 commits into
betafrom
fix/ble-sleep-hours

Conversation

@bharvey88

@bharvey88 bharvey88 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Version: 26.7.24.1

What does this implement/fix?

TEMP-1B_BLE.yaml packages Battery.yaml, whose "Sleep Duration" number is in hours (unit_of_measurement: "h", initial_value: 12, and the deep_sleep default is 12h). The on_boot deep-sleep restore lambda multiplied the stored value by 60 * 1000 (minutes to ms) instead of 60 * 60 * 1000 (hours to ms).

The result: after every reboot the device restored a sleep duration 60x too short, waking roughly every 12 minutes instead of every 12 hours and draining the battery.

The fix changes the expression to * 60 * 60 * 1000, matching the correct math already used in TEMP-1B.yaml, TEMP-1B_Minimal.yaml, and Battery.yaml's own on_value handler. The non-battery variants (TEMP-1.yaml, TEMP-1_BLE.yaml, TEMP-1_Minimal.yaml) correctly keep * 60 * 1000 because NonBattery.yaml's Sleep Duration is in minutes. TEMP-1B_BLE_R2.yaml includes TEMP-1B_BLE.yaml, so it inherits the fix.

This is a sibling of the same hours-vs-minutes bug found in AIR-1 during the 26.7.23.1 release (ApolloAutomation/AIR-1#119).

Validated with esphome config on TEMP-1B_BLE.yaml, TEMP-1B.yaml, and TEMP-1B_BLE_R2.yaml: all report "Configuration is valid!".

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected deep sleep timing so the configured duration is interpreted in hours rather than minutes.

TEMP-1B_BLE.yaml packages Battery.yaml, whose "Sleep Duration" number is
in hours (unit_of_measurement "h", initial 12, deep_sleep default 12h).
Its on_boot restore lambda multiplied the stored value by 60 * 1000
(minutes to ms), so after every reboot the device slept 60x too short,
waking roughly every 12 minutes instead of 12 hours and draining the
battery.

Change the expression to * 60 * 60 * 1000 (hours to ms), matching the
correct math already used in TEMP-1B.yaml, TEMP-1B_Minimal.yaml, and
Battery.yaml's own on_value handler. The non-battery variants keep
* 60 * 1000 because NonBattery.yaml's Sleep Duration is in minutes.

Sibling of the same bug found in AIR-1 during the 26.7.23.1 release
(ApolloAutomation/AIR-1#119). Bumps version to 26.7.24.1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@bharvey88 bharvey88 added the bugfix Bug fix label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b98790ea-1e40-4a84-bde5-8df43170cf18

📥 Commits

Reviewing files that changed from the base of the PR and between 4983129 and 944881f.

📒 Files selected for processing (1)
  • Integrations/ESPHome/TEMP-1B_BLE.yaml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The ESPHome boot lambda now interprets the configured deep sleep duration in hours instead of minutes by converting it to milliseconds with an additional factor of 60.

Changes

Deep Sleep Duration

Layer / File(s) Summary
Update deep sleep duration conversion
Integrations/ESPHome/TEMP-1B_BLE.yaml
The boot lambda now calculates deep sleep duration as state * 60 * 60 * 1000, changing the unit from minutes to hours.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 94488

The change corrects BLE deep-sleep restoration from minutes-based to hours-based calculation for battery devices, preventing unnecessarily frequent wakeups. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the sleeping chart
Hours now guide the timer’s start
Sixty minutes, then sixty more
The sensor rests as planned before
Deep sleep waits behind the door

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the BLE deep-sleep restoration fix and the change from minutes-based to hours-based duration math.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ble-sleep-hours

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.

Conflicts were confined to `version` and `min_version`. Kept this
branch's content and took beta's newer values on both keys;
`channel_colors` requires ESPHome 2026.8.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant