8000
Skip to content

[ultrasonic] Fix timeout issues and deprecate timeout option - #12897

Merged
swoboda1337 merged 1 commit into
esphome:devfrom
swoboda1337:fix-ultrasonic-timeout-margin
Jan 4, 2026
Merged

[ultrasonic] Fix timeout issues and deprecate timeout option#12897
swoboda1337 merged 1 commit into
esphome:devfrom
swoboda1337:fix-ultrasonic-timeout-margin

Conversation

@swoboda1337
@swoboda1337 swoboda1337 commented Jan 4, 2026
Copy link
Copy Markdown
Member

What does this implement/fix?

At least some boards have a delay of 12.3ms before sending the pulse. Now that this component is using interrupts and not busy waiting it doesn't make sense to have a configurable timeout (not saving any time). Use a fixed 80ms measurement timeout instead of the user-configurable timeout which didn't work reliably due to processing delays on the SR04.

The timeout option is deprecated and will be removed in 2026.8.0.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • nRF52840

Example entry for config.yaml:

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO12
    echo_pin: GPIO14
    name: "Ultrasonic Distance"

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

πŸ€– Generated with Claude Code

Use a fixed 80ms measurement timeout instead of the user-configurable
timeout which didn't work reliably due to processing delays on the SR04.

The timeout option is deprecated and will be removed in 2026.8.0.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
github-actions Bot commented Jan 4, 2026
Copy link
Copy Markdown
Contributor

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#12897
    components: [ultrasonic]
    refresh: 1h

(Added by the PR bot)

@github-actions
github-actions Bot commented Jan 4, 2026
Copy link
Copy Markdown
Contributor

πŸ‘‹ Hi there! I've automatically requested reviews from codeowners based on the files changed in this PR.

@OttoWinter - You've been requested to review this PR as codeowner(s) of 3 file(s) that were modified. Thanks for your time! πŸ™

@codecov-commenter
codecov-commenter commented Jan 4, 2026
Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 73.44%. Comparing base (facf477) to head (ffa8a69).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #12897   +/-   ##
=======================================
  Coverage   73.44%   73.44%           
=======================================
  Files          53       53           
  Lines       11303    11303           
  Branches     1534     1534           
=======================================
  Hits         8302     8302           
  Misses       2602     2602           
  Partials      399      399           

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
github-actions Bot commented Jan 4, 2026
Copy link
Copy Markdown
Contributor

Memory Impact Analysis

Components: ultrasonic
Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 28,400 bytes 28,400 bytes ➑️ +0 bytes (0.00%)
Flash 276,523 bytes 276,431 bytes πŸ“‰ βœ… -92 bytes (-0.03%)
πŸ“Š Component Memory Breakdown
Component Target Flash PR Flash Change
[esphome]ultrasonic 879 bytes 798 bytes πŸ“‰ πŸŽ‰ -81 bytes (-9.22%)
app_framework 1,584 bytes 1,576 bytes πŸ“‰ -8 bytes (-0.51%)
πŸ” Symbol-Level Changes (click to expand)

Changed Symbols

Symbol Target Size PR Size Change
esphome::ultrasonic::UltrasonicSensorComponent::loop()::__pstr__ 77 bytes 40 bytes πŸ“‰ -37 bytes (-48.05%)
esphome::ultrasonic::UltrasonicSensorComponent::loop() 196 bytes 172 bytes πŸ“‰ -24 bytes (-12.24%)
esphome::ultrasonic::UltrasonicSensorComponent::dump_config()::__pstr__ 37 bytes 20 bytes πŸ“‰ -17 bytes (-45.95%)
setup 454 bytes 446 bytes πŸ“‰ -8 bytes (-1.76%)
esphome::ultrasonic::UltrasonicSensorComponent::dump_config() 88 bytes 85 bytes πŸ“‰ -3 bytes (-3.41%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

8000

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@swoboda1337
Copy link
Copy Markdown
Member Author

Thanks

@swoboda1337
swoboda1337 merged commit 9ae19d5 into esphome:dev Jan 4, 2026
42 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ultrasonic sensor timeout bug

3 participants

0