Add Lock Active binary sensor for Z-Wave lock automation#3
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new
Lock Activebinary sensor that indicates whether the current time falls within the lock-access window (betweenLock Access StartandLock 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
LockActiveSensorbinary sensor: Returnsonwhen the current time is within the lock-access window,offotherwise 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_entryto register bothGuestPresentSensorand the newLockActiveSensor.Comprehensive test coverage: Added
tests/test_binary_sensors.pywith test cases covering:GuestPresentSensorbehavior (on whenin_house, off otherwise)LockActiveSensorbehavior (on inside window, off before/after window, off when vacant)Localization support: Added
lock_activetranslation 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:
Lock Activesensor stateImplementation Details
The
LockActiveSensorchecks ifdatetime.now(UTC)falls within the inclusive range[lock_access_start, lock_access_end]. It returnsFalseif either boundary isNone(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