Skip to content

Recover missed button release edges; expose button events as Z2M action - #549

Open
murjam wants to merge 2 commits into
romasku:mainfrom
murjam:fix/missed-release-edge-and-z2m-action
Open

murjam wants to merge 2 commits into
romasku:mainfrom
murjam:fix/missed-release-edge-and-z2m-action

Conversation

@murjam

@murjam murjam commented Nov 6, 2026

Copy link
Copy Markdown

Problem

On a BSEED TS0726 (SWITCH_BSEED_TS0726_1GANG, router) a quick short press sometimes registered as a long press: long_press arrived ~800 ms after the click, followed by a late released, and the press of the next click went missing.

Cause: the GPIO interrupt can miss a release edge while the contact bounces. The pin can change between arming the edge and enabling the IRQ, so the button stays "pressed" until the next real edge.

Changes

Firmware

  • button.c: the debounce task re-reads the pin level, and while the button is held it keeps polling (every 50 ms until the long press fires, then every 250 ms). A missed release gets picked up instead of turning into a long press.
  • telink/hal/gpio_interrupts.c: after enabling the IRQs, the pin levels are checked again against the levels the edges were armed for. If they differ, the dispatch runs again.

Z2M converter

  • New romasku.switchActions modern extend that exposes the standard action property (press, release, long_press, long_release, position_on, position_off, suffixed with the switch endpoint name, e.g. long_press_switch_1), derived from genMultistateInput reports. Zigbee2MQTT publishes it to <device>/action and creates Home Assistant device triggers for every press type, not only short presses. <switch>_press_action is unchanged.
  • Converters regenerated from the template.

Tests / stub

  • Stub: set_pin_silent simulates a missed edge.
  • Regression tests in tests/test_switch_cluster_momentary_mode.py.
  • Changelog entry under Upcoming.

Testing

  • Host stub tests pass (make stub/build && make tests).
  • Built for SWITCH_BSEED_TS0726_1GANG (router), flashed over OTA and used on a real device. The spurious long presses are gone, and action events (including long_press_* / long_release_*) show up in Z2M and Home Assistant.

🤖 Generated with Claude Code

murjam and others added 2 commits October 28, 2026 00:10
A release edge missed by the GPIO interrupt (possible while the contact
bounces: the pin can change between arming the edge and enabling the IRQ)
left the button 'pressed' until the next real edge. On a short press this
showed up as a spurious long_press 800 ms later, a late 'released', and a
missing 'press' on the next click.

- button: re-read the pin level in the debounce task and keep polling while
  the button is held (50 ms until the long press fires, 250 ms after), so a
  missed release is picked up instead of turning into a long press.
- telink gpio_interrupts: after enabling the IRQs, re-check the pin levels
  against the ones the edges were armed for and re-run the dispatch if they
  differ.
- stub: add set_pin_silent to simulate a missed edge; regression tests.
- z2m converter template: add romasku.switchActions, exposing the standard
  'action' property (press/release/long_press/long_release/position_on/
  position_off per switch endpoint) derived from genMultistateInput
  reports, so Z2M publishes every press type to <device>/action and
  creates Home Assistant device triggers.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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