Skip to main content

Apple AirTag detector for Raspberry Pi with HomeKit integration

Project description

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

  1. Clone or download this repository to your Raspberry Pi

  2. Make the setup script executable and run it:

    chmod +x setup.sh
    sudo ./setup.sh
    
  3. Configure HomeKit Integration:

    python3 setup_homekit.py
    

Manual Installation

If you prefer to install manually:

  1. Install system dependencies:

    sudo apt update
    sudo apt install python3 python3-pip bluetooth bluez libbluetooth-dev
    
  2. Install Python dependencies:

    pip3 install -r requirements.txt
    
  3. 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:

  1. BLE Scanning: Continuously scans for Bluetooth Low Energy devices
  2. Apple Device Identification: Looks for devices with Apple's company identifier (0x004C) or relevant service UUIDs
  3. Proximity Detection: Uses RSSI (Received Signal Strength Indicator) to estimate distance
  4. 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 sudo for Bluetooth access
  • Ensure the user is in the bluetooth group

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airtag_detector-1.0.1.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airtag_detector-1.0.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file airtag_detector-1.0.1.tar.gz.

File metadata

  • Download URL: airtag_detector-1.0.1.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for airtag_detector-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9ef7a396882d86bcb44802d7bcb23ad590ff46180a129fc14d38dfd366e29ceb
MD5 912da0e1d11c2671de6730981847395c
BLAKE2b-256 1de5bc75b967cf9647656cc0b0d4566a7de2676a235a71eb15e684ce4849fbaf

See more details on using hashes here.

File details

Details for the file airtag_detector-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for airtag_detector-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd7d06b2b86bc5b0f7eca2227ddaaa915807aa582acabb96345e19c3a7b9a918
MD5 545a092eda84b1be513b303dcc7b8532
BLAKE2b-256 949b2c9911d45108d6e32d4f3b2605b73813ef1e2260ca5b4004c453a84e0d35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page