Skip to content

feat: Add path tracking timeout and adaptive thresholds (v1.6.0)#150

Open
Lyr3x wants to merge 1 commit into
masterfrom
priority-ranking-and-adaptive-threshold
Open

feat: Add path tracking timeout and adaptive thresholds (v1.6.0)#150
Lyr3x wants to merge 1 commit into
masterfrom
priority-ranking-and-adaptive-threshold

Conversation

@Lyr3x

@Lyr3x Lyr3x commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces two high-priority robustness features to improve people counting reliability:

  • Path Tracking Timeout: Automatically resets the state machine when someone enters halfway and turns back, preventing stuck states
  • Adaptive Thresholds: Continuously adjusts idle baseline to handle environmental drift (temperature changes, lighting variations)

Changes

New Features

Feature Description Default
path_tracking_timeout Resets state if no activity within timeout 3s
adaptive_threshold.enabled Enable/disable adaptive updates true
adaptive_threshold.update_interval How long zones must be empty before updating 60s
adaptive_threshold.alpha EMA smoothing factor (0.01-0.5) 0.05

Code Improvements

  • Moved path tracking state from static variables to class members for better encapsulation
  • Added sanity checks for adaptive threshold updates (rejects readings >20% different from idle)
  • Enhanced logging for debugging path tracking and threshold updates
  • Version bumped to 1.6.0

Documentation

  • Updated README with new configuration options and FAQ entries
  • Modernized home_assistant.md with example automations and dashboard cards
  • Added CHANGELOG entry for v1.6.0

Testing from Feature Branch

To test these changes before they're merged, update your ESPHome configuration:

external_components:
  - source: github://Lyr3x/Roode@priority-ranking-and-adaptive-threshold
    refresh: always

Example Configuration

roode:
  id: roode_platform
  sampling: 2
  roi: { height: 16, width: 6 }
  detection_thresholds:
    max: 85%

  # New v1.6.0 features - test these!
  path_tracking_timeout: 3s
  adaptive_threshold:
    enabled: true
    update_interval: 60s
    alpha: 0.05

  zones:
    invert: false

Test Plan

Testing Path Tracking Timeout

  1. Flash the firmware with the feature branch
  2. Monitor logs: esphome logs <your-device>.yaml
  3. Walk partially into the detection zone and step back without completing the crossing
  4. Expected: After 3 seconds, you should see:
    • Log message: Path tracking timeout after XXXX ms - resetting state
    • entry_exit_event sensor shows "Timeout"
    • People counter remains unchanged

Testing Adaptive Thresholds

  1. Flash the firmware and let it calibrate
  2. Note the initial threshold values in Home Assistant (or logs)
  3. Wait 60+ seconds with no one in the detection area
  4. Expected:
    • Log message: Updating adaptive thresholds (zones empty for XXXX ms)
    • Threshold sensors may show small adjustments
  5. To simulate drift: slightly change sensor mounting angle, wait for update
  6. Verify thresholds adapt (within 20% sanity limit)

Testing Backward Compatibility

  1. Use default configuration (no new options specified)
  2. Expected: Features work with defaults, no breaking changes

Log Messages to Look For

# Timeout detection
[W][Roode]: Path tracking timeout after 3500 ms - resetting state (incomplete crossing)

# Adaptive threshold update  
[D][Roode]: Updating adaptive thresholds (zones empty for 65000 ms)
[D][Zone calibration]: Adaptive threshold update zone 0: idle 2180 -> 2185, max: 1857, min: 0

# Skipped update (sanity check)
[D][Zone calibration]: Skipping adaptive update: reading 1800 too far from idle 2200

Feedback Requested

  • Does the 3-second default timeout feel right for your doorway?
  • Is the adaptive threshold updating correctly in your environment?
  • Any issues with the new configuration options?

Please report any issues or feedback in the comments!

New Features:
- Path tracking timeout: Automatically resets state machine when someone
  enters halfway and turns back, preventing stuck states. Configurable
  via `path_tracking_timeout` (default: 3s). Publishes "Timeout" event.

- Adaptive thresholds: Continuously adjusts idle baseline to handle
  environmental drift (temperature, lighting changes). Uses Exponential
  Moving Average for smooth updates. Configurable via `adaptive_threshold`
  block with `enabled`, `update_interval`, and `alpha` options.

Improvements:
- Moved path tracking state from static variables to class members
- Added sanity checks for adaptive updates (rejects >20% changes)
- Enhanced logging for debugging

Documentation:
- Updated README with new features, configuration examples, and FAQ
- Modernized home_assistant.md with automations and dashboard cards
- Added CHANGELOG entry for v1.6.0

Examples:
- Updated peopleCounter32.yaml and peopleCounter8266.yaml
- Removed broken API service calls (set_max/min_threshold_percentage)
- Updated CI configs to test new features
@Lyr3x Lyr3x mentioned this pull request Mar 1, 2026
@TheStigh

Copy link
Copy Markdown

Hi @Lyr3x, I've been testing this and it seems quite good so far! :)
Question - is there a particular reason why you have limited the max_value for number: to -128/128 ?

Also, your yaml is not up-to-date when it comes to api: and ota:

api need to be proper formatted for the key:, now using encryption

api:
  encryption:
    key: !secret XYZ

Same for ota, need to use platform

ota:

  - platform: esphome
    id: ota_esphome
    password: !secret XYZ

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