
Automatically Lock Your Z-Wave Smart Locks When You Leave Home Using iPhone Device Tracking in Home Assistant
Smart home automation becomes truly useful when it quietly handles everyday tasks in the background. One of the best examples is automatically locking your doors when everyone leaves home. Instead of wondering whether the front door was locked after driving away, Home Assistant can detect when your iPhone leaves the house and secure your Z-Wave smart locks automatically.
In this guide, we will build a reliable automation using Home Assistant, iPhone device tracking, and Z-Wave smart locks. The result is a seamless security feature that works without requiring any manual interaction.
This setup is especially useful for busy families, frequent travelers, or anyone who wants a safer and smarter home.
Why Automate Door Locking?
Automatic locking provides several advantages:
- Improved home security
- Reduced risk of forgetting to lock doors
- Fully automated daily routines
- Peace of mind while away
- Better integration with alarm systems and presence detection
Instead of relying on memory, Home Assistant continuously monitors whether your phone is home or away and reacts instantly.
Components Required
To build this automation, you need a few components working together.
Home Assistant
The automation platform that ties everything together.
Home Assistant supports device tracking, automations, Z-Wave integration, notifications, and advanced logic.
A Raspberry Pi, mini PC, or Home Assistant Green works perfectly for this setup.
iPhone Device Tracking
Presence detection is the core of this automation.
The easiest method for iPhone users is the official Home Assistant Companion App:
Home Assistant Companion
The app provides reliable device tracking using:
- GPS location
- Wi-Fi connection status
- Bluetooth
- Background location updates
Once configured, Home Assistant creates a device tracker entity such as:
device_tracker.john_iphone
The tracker usually reports states like:
homenot_home
Z-Wave Smart Locks
A compatible Z-Wave smart lock is required.
Popular options include:
- Yale Assure Lock
- Danalock V3
- Schlage Connect
- ID Lock series
The lock is typically exposed as an entity like:
lock.front_door
Users with Scandinavian smart homes often use:
ID Lock 150
which integrates well with Home Assistant through Z-Wave JS.
Z-Wave Controller
You also need a Z-Wave USB controller connected to Home Assistant.
Common controllers include:
- Aeotec Z-Stick
- Zooz controllers
- Home Assistant ZBT-1
These are integrated using:
Z-Wave JS
How Presence Detection Works
The automation logic is straightforward:
- Your iPhone leaves the Home zone
- Home Assistant detects the change
- The automation waits briefly to avoid false triggers
- Home Assistant checks whether anyone is still home
- If nobody is home, the door locks automatically
This creates a very reliable system while avoiding accidental locking when family members remain inside.
Improving Reliability
Before creating the automation, there are a few important best practices.
Enable Background Location Access
On iPhone:
- Set the Home Assistant app location permission to:
- Always
- Enable:
- Precise Location
- Background App Refresh
Without these settings, presence updates may become delayed.
Use Wi-Fi Detection Together With GPS
Wi-Fi presence improves reliability significantly.
When the phone disconnects from home Wi-Fi and GPS also reports away status, false triggers become much less common.
Add a Delay Before Locking
Phones sometimes briefly disconnect from Wi-Fi or report incorrect GPS positions.
A delay of 2–5 minutes prevents accidental locking events.
Example Automation
Below is a practical Home Assistant automation example.
This automation:
- Detects when the iPhone leaves home
- Waits 3 minutes
- Checks whether the phone is still away
- Verifies the door is unlocked
- Locks the door automatically
YAML Automation Example
alias: Auto Lock Door When Leaving Home
description: Automatically locks the front door when the iPhone leaves home
mode: single
trigger:
- platform: state
entity_id: device_tracker.john_iphone
from: home
to: not_home
condition:
- condition: state
entity_id: lock.front_door
state: unlocked
action:
- delay:
minutes: 3
- condition: state
entity_id: device_tracker.john_iphone
state: not_home
- service: lock.lock
target:
entity_id: lock.front_door
- service: notify.mobile_app_john_iphone
data:
title: Front Door Locked
message: The front door was automatically locked because you left home.
Adding Multiple Family Members
Most households have more than one person.
In that case, the automation should only lock the door when everyone has left.
A better approach is using a group entity.
Example:
group:
family:
name: Family
entities:
- device_tracker.john_iphone
- device_tracker.jane_iphone
Updated condition:
condition:
- condition: state
entity_id: group.family
state: not_home
This prevents locking while someone is still inside the house.
Adding Alarm Integration
Many users combine automatic locking with alarm activation.
Example actions:
- service: alarm_control_panel.alarm_arm_away
target:
entity_id: alarm_control_panel.home_alarm
This creates a complete “everyone left home” security routine.
Useful Optional Enhancements
Send Notifications
Notifications help confirm that the automation worked.
Example:
message: Front door locked automatically.
You can also include timestamps or battery levels.
Skip Locking at Night
Some users prefer different behavior during late hours.
Example condition:
condition:
- condition: time
after: "06:00:00"
before: "23:30:00"
Avoid Locking During Vacation Maintenance
If cleaners, pet sitters, or maintenance workers are present, you may want to disable the automation temporarily.
This can be done using:
- Input booleans
- Guest mode
- Vacation mode
Example:
condition:
- condition: state
entity_id: input_boolean.guest_mode
state: "off"
Security Considerations
Automated locking is convenient, but security should remain the priority.
Use Secure Z-Wave Inclusion
Always include locks using:
- Z-Wave S2 Security
- Strong network encryption
Avoid insecure inclusion methods.
Protect Home Assistant
Your Home Assistant installation should include:
- Strong passwords
- Two-factor authentication
- HTTPS access
- Regular backups
Test Carefully
Always test:
- Leaving home
- Returning home
- Multiple phones
- Temporary GPS loss
- Wi-Fi outages
Reliable automations require real-world testing.
Troubleshooting Common Problems
Phone Does Not Update Location
Check:
- Background permissions
- Battery saving mode
- iOS Low Power Mode
- VPN interference
Door Locks Too Early
Increase the delay:
minutes: 5
You can also combine:
- Wi-Fi presence
- GPS presence
- Bluetooth presence
for more accurate tracking.
Z-Wave Commands Are Slow
Possible causes:
- Weak Z-Wave mesh
- Long distances
- Poor routing
- Missing mains-powered repeaters
Adding powered Z-Wave devices improves network reliability significantly.
Why This Automation Is So Useful
This automation quickly becomes one of those smart home features you stop thinking about because it simply works.
You leave home.
The house secures itself.
No manual interaction required.
Combined with:
- alarm systems
- cameras
- lighting
- energy-saving automations
it becomes part of a much larger smart home ecosystem.
And unlike gimmicky automations, this one genuinely improves everyday life.
Final Thoughts
Using iPhone presence detection together with Z-Wave smart locks in Home Assistant is a simple but powerful automation.
It improves security, removes daily friction, and ensures your home stays protected even when you forget to lock the door manually.
With proper delays, family grouping, and reliable device tracking, the automation becomes highly dependable and works quietly in the background.
If you already use Home Assistant and Z-Wave devices, this is one of the most practical automations you can add to your smart home.
Some of the links in this article are "affiliate links", a link with a special tracking code. This means if you click on an affiliate link and purchase the item, we will receive an affiliate commission. The price of the item is the same whether it is an affiliate link or not. Regardless, we only recommend products or services we believe will add value to our readers. By using the affiliate links, you are helping support our Website, and we genuinely appreciate your support.