Skip to content

Fix for door contact sensors stuck in open state#192

Open
Hu1kSmash wants to merge 1 commit intoxaf:mainfrom
Hu1kSmash:fix-sensor-stuck-open-bug
Open

Fix for door contact sensors stuck in open state#192
Hu1kSmash wants to merge 1 commit intoxaf:mainfrom
Hu1kSmash:fix-sensor-stuck-open-bug

Conversation

@Hu1kSmash
Copy link
Copy Markdown

Problem

Door contact sensors get stuck in the "open" state when multiple doors are opened/closed simultaneously. The existing tamper detection logic interferes with normal sensor state updates, causing sensors to remain permanently stuck.

Root Cause Analysis

The issue occurs in the QolsysSensor.open() and closed() methods:

  1. Flawed tamper detection: Uses unreliable timing-based logic that triggers incorrectly during multi-sensor operations
  2. Status update blocking: When tamper is detected, the closed() method fails to update sensor status
  3. Race conditions: Simultaneous sensor events cause incorrect tamper flagging

Comprehensive Solution

Enhanced open() method:

  • Improved tamper detection: Uses 0.5-second rapid-sequence detection instead of complex timing logic
  • Robust state handling: Properly manages both normal opens and potential tamper events
  • Better timing tracking: Consistently updates timestamps for accurate detection

Enhanced closed() method:

  • Guaranteed status updates: Always sets status to 'Closed' when close events occur
  • Prevents stuck states: Sensors cannot remain permanently open
  • Maintains tamper handling: Still processes tamper flag clearing appropriately

Benefits

  • Fixes stuck-open bug: Sensors reliably transition from open → closed
  • Improves tamper detection: More accurate rapid-event detection
  • Handles multi-sensor scenarios: Robust during simultaneous operations
  • Backward compatible: No breaking changes to existing functionality
  • Production tested: Verified in real Home Assistant environment

Testing Performed

  • Multiple door sensors opening/closing in various combinations
  • Rapid open/close sequences to verify tamper detection
  • Extended monitoring to ensure no stuck states
  • Verified tamper events still detected appropriately
  • No AppDaemon errors or warnings during operations

Files Changed

  • apps/qolsysgw/qolsys/sensors.py: Enhanced open() and closed() methods

This comprehensive fix resolves the core sensor state management issues while improving the overall robustness of the sensor handling system.

- Problem: Multi-sensor operations caused sensors to remain stuck open
- Root cause: Flawed tamper detection logic interfering with status updates
- Solution: Improved both open() and closed() methods with better logic

Changes:
- open(): Enhanced tamper detection using rapid-sequence timing (0.5s window)
- closed(): Always updates status to prevent stuck-open states
- Maintains tamper detection while prioritizing actual state changes
- More robust handling of simultaneous sensor operations

Tested with multiple door sensors in various open/close combinations.
@xaf
Copy link
Copy Markdown
Owner

xaf commented Nov 8, 2025

when multiple doors are opened/closed simultaneously

Could you explain this?
The status tracker are per sensor, thus shouldn't have any situation where a sensor A opening/closing would influences the status of sensor B.

Would you be able to confirm which panel and panel version you are using?
What I've been able to observe for the 2+ and 4 is described here:

##### Special case: sensor tampering
The `ZONE_ACTIVE` zone event type is also used by the panel to indicate that
a sensor has been tampered with, or has been restored. The following behaviors
have been identified:
- `Open` and `Closed` have two layers for any given sensor:
- An `Open` sensor being `Open` through `ZONE_ACTIVE` is now tampered
- A tampered sensor being `Closed` through `ZONE_ACTIVE` is no more tampered
- Receiving two `ZONE_ACTIVE` for the same tampered sensor in the same second, the first `Open` and the second `Closed`, means the sensor is no more tampered, and the next `ZONE_ACTIVE` message indicates the current status of the sensor (whether it is currently `Open` or `Closed`)

This means that

Check if this might be a tamper event (rapid successive opens)

Is not exactly what I observed. An open sensor being tampered will only send another open message.

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.

2 participants