A Python package for detecting Apple AirTags on Raspberry Pi with HomeKit integration. Automatically controls smart plugs when AirTags are detected within approximately 3 feet.
# Using pipx (recommended)
pipx install airtag-detector
# Or using pip
pip install airtag-detector- Quick Start Guide - Get up and running in minutes
- Installation Guide - Handle modern Python environments
- Publishing Guide - For developers
- Package Documentation - Complete package reference
This repository contains the source code for the airtag-detector PyPI package.
airtag_detector/ # Main package
βββ detector.py # Core detection logic
βββ homekit_controller.py # HomeKit integration
βββ homekit_setup.py # Setup wizard
βββ setup.py # Installation utilities
βββ test_bluetooth.py # Bluetooth testing
βββ templates/ # Service templates
βββ configs/ # Configuration templates
docs/ # Documentation
install.sh # Smart installer script
quick_install.sh # One-line installer
publish.sh # Publishing script
# Clean build
./publish.sh testpypi # Test on TestPyPI first
./publish.sh pypi # Publish to production PyPI- 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
- 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)
-
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
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
Start the service:
sudo systemctl start airtag-detector.serviceCheck service status:
sudo systemctl status airtag-detector.serviceView logs in real-time:
sudo journalctl -u airtag-detector.service -fStop the service:
sudo systemctl stop airtag-detector.servicesudo python3 airtag_detector.pyPress Ctrl+C to stop.
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
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"
- RSSI threshold: -70 dBm (approximately 3 feet)
- Higher RSSI values indicate closer proximity
- You may need to adjust the threshold based on your environment
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 are written to:
- Console output
/home/ubuntu/dogpi/airtag_detector.log- System journal (viewable with
journalctl)
- Run with
sudofor Bluetooth access - Ensure the user is in the
bluetoothgroup
sudo systemctl status bluetooth
sudo hciconfig hci0 up- 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
sudo systemctl status airtag-detector.service
sudo journalctl -u airtag-detector.service- 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
- 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
Feel free to submit issues and pull requests to improve the detector.
This project is licensed under the terms specified in the LICENSE file.