Skip to content

Add state_debounce option to UARTEx entities - #379

Merged
eigger merged 2 commits into
masterfrom
uartex-state-debounce
Nov 24, 2026
Merged

eigger merged 2 commits into
masterfrom
uartex-state-debounce

Conversation

@eigger

@eigger eigger commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a common per-entity state_debounce option to uartex (refs #378). Wallpads sometimes emit transient state packets (e.g. climate off↔heat for 1–2 s); these were published to Home Assistant immediately.

Behaviour

  • After the state pattern matches, the packet is held in a pending buffer instead of being published.
  • The timer starts when the change starts; later packets overwrite the pending data (latest wins). UARTExComponent::loop() applies it once the debounce time has elapsed.
  • A packet identical to the last applied state cancels the pending change and is re-published immediately (keeps HA correct when a command is ignored by the device).
  • First packet after boot is applied immediately; state_response/ACK handling is unchanged; HA commands still reflect immediately via control/optimistic.
  • Right after an entity transmits its own control command, a one-shot window of state_debounce length is armed: the first state packet that differs from the last applied state is treated as the confirmation and applied immediately (so command results are not delayed even without optimistic, e.g. switch). Polling (command_update), write_command and rx replies do not arm it; packets equal to the last state do not consume it; retries re-arm it. Only the first change after the latest command is immediate.
  • preserve_state commands wait while a change is pending (last_state is not settled yet).
  • Default 0 = previous behaviour. Requires state; max 60s.
climate:
  - platform: uartex
    state: ...
    state_debounce: 2s

Notes / limitations

  • Comparison is on the whole matched packet, so if the same packet carries changing bytes (e.g. current temperature), those values are also applied up to the debounce time later. A byte mask for the comparison could be added later if needed.

Tests

  • Native: new tests/native/uartex_parser/test_state_debounce.cpp (disabled path identical, first packet, glitch filtered, latest wins, stuck-state after control, loop() wiring, millis wraparound, preserve_state interaction, post-command bypass incl. polling/write_command/rx-reply not arming, one-shot, expiry, retry re-arm) — run.sh passes.
  • esphome config and compile --only-generate on tests/components/uartex/test.esp32-idf.yaml pass; negative checks (90s, missing state) rejected.
  • Not tested on hardware.

🤖 Generated with Claude Code

eigger and others added 2 commits November 24, 2026 11:49
Hold matched state packets and apply them only after the configured
time since the change started (latest packet wins). A packet equal to
the last applied state cancels the pending change and re-publishes,
so transient wallpad packets no longer reach Home Assistant.

Default 0 keeps the previous behaviour. Requires `state`, max 60s.

Closes #378

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When an entity transmits a control command, arm a one-shot window of
state_debounce length; the first differing state packet inside it is
the confirmation and is applied immediately. Polling (command_update),
write_command and rx replies do not arm it, packets equal to the last
applied state do not consume it, and retries re-arm it. This keeps
command results prompt for entities without optimistic, e.g. switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eigger
eigger merged commit bd88f85 into master Nov 24, 2026
17 checks passed
@eigger
eigger deleted the uartex-state-debounce branch November 24, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant