Skip to content

Add Lock Active binary sensor for Z-Wave lock automation#3

Merged
chschafl merged 2 commits into
mainfrom
claude/zen-feynman-NjKIH
Jun 9, 2026
Merged

Add Lock Active binary sensor for Z-Wave lock automation#3
chschafl merged 2 commits into
mainfrom
claude/zen-feynman-NjKIH

Conversation

@chschafl

@chschafl chschafl commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces a new Lock Active binary sensor that indicates whether the current time falls within the lock-access window (between Lock Access Start and Lock Access End). This sensor enables users to automate Z-Wave smart locks directly without requiring Keymaster, by gating when guest PIN codes should be active.

Key Changes

  • New LockActiveSensor binary sensor: Returns on when the current time is within the lock-access window, off otherwise or when the house is vacant. This provides a simple boolean flag for automations to gate door code activation.

  • Updated binary sensor setup: Modified async_setup_entry to register both GuestPresentSensor and the new LockActiveSensor.

  • Comprehensive test coverage: Added tests/test_binary_sensors.py with test cases covering:

    • GuestPresentSensor behavior (on when in_house, off otherwise)
    • LockActiveSensor behavior (on inside window, off before/after window, off when vacant)
  • Localization support: Added lock_active translation keys to all supported languages (English, German, Spanish, Dutch).

  • Documentation: Added a new "Driving a Z-Wave lock directly (no Keymaster)" section in README with step-by-step automation recipes showing how to:

    • Write a guest PIN to a Z-Wave lock slot on booking change
    • Activate/deactivate the PIN based on the Lock Active sensor state
    • Handle edge cases and provide implementation tips

Implementation Details

The LockActiveSensor checks if datetime.now(UTC) falls within the inclusive range [lock_access_start, lock_access_end]. It returns False if either boundary is None (no guest or incomplete configuration) or if the house is vacant, ensuring the lock code is never active when there's no guest.

https://claude.ai/code/session_01DN98zCyvmAyKUgbvzSiggb

claude added 2 commits June 8, 2026 05:34
A new binary sensor reports `on` while the current time sits inside the
lock-access window (`Lock Access Start ≤ now ≤ Lock Access End`) and
`off` otherwise. It gives automations a single boolean to gate "should
the door code be live right now?" — useful for locks driven directly by
Z-Wave JS (no Keymaster), where the PIN slot has to be written and
cleared on the window edges.

The README gains a worked end-to-end recipe that uses the new sensor to
push the PMS-supplied door code into a numbered Z-Wave user-code slot at
the start of the access window and clear it again at the end.
The sensor's state depends on wall-clock time crossing the lock-access
window edges, not on coordinator data. Schedule a 1-minute interval
callback in `async_added_to_hass` that just writes state, so the flip at
`lock_access_start` / `lock_access_end` is at most ~60s late regardless
of the coordinator's poll interval.
@chschafl chschafl merged commit 3b43e01 into main Jun 9, 2026
4 checks passed
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