Apple AirTag Detector for Raspberry Pi with HomeKit Integration
This project provides a Python script that runs continuously on a Raspberry Pi to detect Apple AirTags within approximately 3 feet using Bluetooth Low Energy (BLE) scanning. When an AirTag is detected, it automatically turns off a HomeKit-enabled smart plug until the AirTag is no longer detected.
Features
- Continuous BLE scanning for Apple AirTags
- RSSI-based proximity detection (approximately 3 feet)
- HomeKit Integration: Automatically controls smart plugs when AirTags are detected
- Home Assistant Support: Recommended integration method
- Logging to both file and console
- Systemd service for automatic startup
- Graceful shutdown handling
- Automatic cleanup of devices that leave range
- Configurable delay before turning plug back on
Requirements
- Raspberry Pi with built-in Bluetooth (Pi 3, Pi 4, Pi Zero W, etc.)
- Raspberry Pi OS (Raspbian)
- Root access for Bluetooth operations
- HomeKit-enabled smart plug or Home Assistant setup
- Home Assistant with the smart plug integrated (recommended)
Installation
-
Clone or download this repository to your Raspberry Pi
-
Make the setup script executable and run it:
chmod +x setup.sh sudo ./setup.sh
-
Configure HomeKit Integration:
python3 setup_homekit.py
Manual Installation
If you prefer to install manually:
-
Install system dependencies:
sudo apt update sudo apt install python3 python3-pip bluetooth bluez libbluetooth-dev
-
Install Python dependencies:
pip3 install -r requirements.txt
-
Enable Bluetooth service:
sudo systemctl enable bluetooth sudo systemctl start bluetooth
Usage
Running as a Service (Recommended)
Start the service:
sudo systemctl start airtag-detector.service
Check service status:
sudo systemctl status airtag-detector.service
View logs in real-time:
sudo journalctl -u airtag-detector.service -f
Stop the service:
sudo systemctl stop airtag-detector.service
Running Manually
sudo python3 airtag_detector.py
Press Ctrl+C to stop.
How It Works
The detector works by:
- BLE Scanning: Continuously scans for Bluetooth Low Energy devices
- Apple Device Identification: Looks for devices with Apple's company identifier (0x004C) or relevant service UUIDs
- Proximity Detection: Uses RSSI (Received Signal Strength Indicator) to estimate distance
- Logging: Records detections with timestamps and device information
Detection Criteria
A device is considered a potential AirTag if it:
- Has Apple's company identifier in manufacturer data (0x004C)
- Advertises relevant service UUIDs (FD44, FEAA)
- Has a name containing keywords like "airtag", "findmy", or "apple"
Proximity Estimation
- RSSI threshold: -70 dBm (approximately 3 feet)
- Higher RSSI values indicate closer proximity
- You may need to adjust the threshold based on your environment
Configuration
You can modify the following parameters in airtag_detector.py:
PROXIMITY_RSSI_THRESHOLD: RSSI threshold for proximity detection (default: -70 dBm)scan_interval: Time between scans (default: 2.0 seconds)- Log level and file paths
Logs
Logs are written to:
- Console output
/home/ubuntu/dogpi/airtag_detector.log- System journal (viewable with
journalctl)
Troubleshooting
Permission Issues
- Run with
sudofor Bluetooth access - Ensure the user is in the
bluetoothgroup
Bluetooth Not Working
sudo systemctl status bluetooth
sudo hciconfig hci0 up
No Devices Detected
- Ensure AirTags are nearby and active
- Check if Bluetooth is enabled and working
- Verify RSSI threshold is appropriate for your environment
- Some AirTags may not be easily detectable when in "silent" mode
Service Not Starting
sudo systemctl status airtag-detector.service
sudo journalctl -u airtag-detector.service
Limitations
- AirTags use privacy features that may limit detectability
- Detection range is approximate and depends on environmental factors
- Some AirTags may enter sleep mode or use anti-tracking features
- False positives may occur with other Apple devices
Privacy and Legal Considerations
- This tool is for educational and security purposes
- Respect privacy laws in your jurisdiction
- Only use to detect AirTags on your own property
- Consider the privacy implications of tracking devices
Contributing
Feel free to submit issues and pull requests to improve the detector.
License
This project is licensed under the terms specified in the LICENSE file.
Metadata
Release files for airtag-detector 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| airtag_detector-1.0.1.tar.gz | 20.3 kB | Without provenance | Details for airtag_detector-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| airtag_detector-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for airtag_detector-1.0.1-py3-none-any.whl |
Total release size: 41.4 kB
Release files / airtag_detector-1.0.1.tar.gz
| Download URL | airtag_detector-1.0.1.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ef7a396882d86bcb44802d7bcb23ad590ff46180a129fc14d38dfd366e29ceb
|
|
BLAKE2b-256 checksum How to use checksums |
1de5bc75b967cf9647656cc0b0d4566a7de2676a235a71eb15e684ce4849fbaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / airtag_detector-1.0.1-py3-none-any.whl
| Download URL | airtag_detector-1.0.1-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd7d06b2b86bc5b0f7eca2227ddaaa915807aa582acabb96345e19c3a7b9a918
|
|
BLAKE2b-256 checksum How to use checksums |
949b2c9911d45108d6e32d4f3b2605b73813ef1e2260ca5b4004c453a84e0d35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for airtag-detector 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.