├── README.md └── findmy.sh /README.md: -------------------------------------------------------------------------------- 1 | # FindMy 2 | Retrieve FindMy Objects data (Airtags, Airpods, etc.) from a jailbroken device and publish it through MQTT for use in Home Assistant 3 | 4 | First of you'll need to install the Terminal & SSH addon (https://github.com/home-assistant/addons/blob/master/ssh/DOCS.md). 5 | Secondly you'll need a (jailbroken) iOS device (iPhone / iPad) that supports Find My (iOS 14.0 or higher), I've used an iPhone 7 with iOS 15.7.5 and applied the Palera1n jailbreak. 6 | 7 | ## Jailbreaking the iPhone: 8 | Download the .ISO from https://github.com/palera1n/palen1x/releases and follow the instructions as mentioned on https://ios.cfw.guide/using-palen1x. 9 | 10 | ## Setup a passwordless connection 11 | - Follow the instructions from Smart Home Junkie on creating SSH-keys https://youtu.be/_ANmn9QSLtA 12 | - If you have got your private and public key copy that key to the iOS device: use ssh-copy-id -i {location of your public key} {username}@{iosdevice--ip-address}, you'll be prompted for your password and after that the SSH-key should be copied. 13 | 14 | With Home Assistant now able to download the Items.data file the find_my.sh script will generate a device_tracker that you can use in your Maps-card for example. 15 | 16 | The script is under development, so changes will me made. 17 | 18 | ## Home Assistant Configuration 19 | 20 | ### Find_my.sh 21 | Copy the shell script to your prefered shell scripts location e.g. /config/shell/find_my 22 | Change the listed variables to match your setup: 23 | - scriptlocation 24 | - iosdevice 25 | - mqttbroker 26 | - username 27 | - password 28 | 29 | ### Configuration.yaml 30 | Add the following line to your configuration and modify it to match your setup: 31 | 32 | - `/config/ssh/id_rsa` should match the location of your ssh-key 33 | - `root@192.168.1.100` should match your SSH login 34 | - `/config/shell/find_my/find_my.sh` should match the location of find_my.sh 35 | 36 | ``` 37 | shell_command: 38 | find_my: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' root@192.168.1.100 '/config/shell/find_my/find_my.sh' 39 | ``` 40 | 41 | ### Automation 42 | You can create an automation as basic as: 43 | ``` 44 | alias: "Run the Find_my script" 45 | description: "" 46 | trigger: 47 | - platform: time_pattern 48 | minutes: /5 49 | condition: [] 50 | action: 51 | - service: shell_command.find_my 52 | data: {} 53 | mode: single 54 | ``` 55 | -------------------------------------------------------------------------------- /findmy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Thanks for Airtag Alex for the inspiration and borrowing some of his code 4 | # Visit his Youtube channel https://www.youtube.com/c/AirtagAlex or https://github.com/icepick3000/AirtagAlex 5 | 6 | # This project is far from done and it still needs some work: 7 | # - Instead of a device_tracker I would like to create a Device with a Device_tracker entity, 8 | 9 | # Setting the variables 10 | # location of the script 11 | scriptlocation=/config/shell/find_my 12 | 13 | # IP address of the jailbroken iOS device, accessible from HA through SSH 14 | iosdevice=192.168.1.110 15 | 16 | # IP address of the MQTT broker 17 | mqttbroker=192.168.1.100 18 | 19 | # MQTT broker username 20 | mqttusername=username 21 | 22 | # MQTT broker password 23 | mqttpassword=password 24 | 25 | # The script 26 | rm $scriptlocation/Items.data > /dev/null 2>&1 27 | echo $(date -u) "- Delete Items.data" 28 | echo $(date -u) "- Download Items.data from iOS device ($iosdevice)" 29 | scp root@$iosdevice:/User/Library/Caches/com.apple.findmy.fmipcore/Items.data $scriptlocation/Items.data > /dev/null 2>&1 30 | 31 | object=`cat $scriptlocation/Items.data | jq ".[].serialNumber" | wc -l` 32 | echo $(date -u) "- Number of Apple Find My objects to process: $object" 33 | object=`echo "$(($object-1))"` 34 | echo "-----------------------------------------------------------------------------------------------------------------------------" 35 | for j in $(seq 0 $object) 36 | 37 | do 38 | echo $(date -u) "- Gathering data from $scriptlocation/Items.data for next Apple Find My object to process" 39 | datetime=`date +"%Y-%m-%d %T"` 40 | 41 | serialnumber=`cat $scriptlocation/Items.data | jq -r ".[$j].serialNumber"` 42 | manufacturerName=`cat $scriptlocation/Items.data | jq -r ".[$j].productType.productInformation.manufacturerName"` 43 | modelName=`cat $scriptlocation/Items.data | jq -r ".[$j].productType.productInformation.modelName"` 44 | systemversion=`cat $scriptlocation/Items.data | jq -r ".[$j].systemVersion"` 45 | 46 | antennapower=`cat $scriptlocation/Items.data | jq -r ".[$j].productType.productInformation.antennaPower"` 47 | batterystatus=`cat $scriptlocation/Items.data | jq -r ".[$j].batteryStatus"` 48 | name=`cat $scriptlocation/Items.data | jq -r ".[$j].name"` 49 | 50 | locationtimestamp=`cat $scriptlocation/Items.data | jq -r ".[$j].location.timeStamp"` 51 | locationpositiontype=`cat $scriptlocation/Items.data | jq -r ".[$j].location.positionType"` 52 | locationlatitude=`cat $scriptlocation/Items.data | jq -r ".[$j].location.latitude"` 53 | locationlongitude=`cat $scriptlocation/Items.data | jq -r ".[$j].location.longitude"` 54 | locationverticalaccuracy=`cat $scriptlocation/Items.data | jq -r ".[$j].location.verticalAccuracy" | sed 's/null/0/g'` 55 | locationhorizontalaccuracy=`cat $scriptlocation/Items.data | jq -r ".[$j].location.horizontalAccuracy" | sed 's/null/0/g'` 56 | locationfloorlevel=`cat $scriptlocation/Items.data | jq -r ".[$j].location.floorlevel" | sed 's/null/0/g'` 57 | locationaltitude=`cat $scriptlocation/Items.data | jq -r ".[$j].location.altitude" | sed 's/null/0/g'` 58 | locationisinaccurate=`cat $scriptlocation/Items.data | jq -r ".[$j].location.isInaccurate" | awk '{ print "\""$0"\"" }'` 59 | locationisold=`cat $scriptlocation/Items.data | jq -r ".[$j].location.isOld" | awk '{ print "\""$0"\"" }' ` 60 | locationfinished=`cat $scriptlocation/Items.data | jq -r ".[$j].location.locationFinished" | awk '{ print "\""$0"\"" }' ` 61 | 62 | addressmapItemFullAddress=`cat $scriptlocation/Items.data | jq -r ".[$j].address.mapItemFullAddress" | sed 's/null/""/g'` 63 | addressstreetName=`cat $scriptlocation/Items.data | jq -r ".[$j].address.streetName"| sed 's/null/""/g'` 64 | addressstreetaddress=`cat $scriptlocation/Items.data | jq -r ".[$j].address.streetAddress"| sed 's/null/""/g'` 65 | addresslocality=`cat $scriptlocation/Items.data | jq -r ".[$j].address.locality"| sed 's/null/""/g'` 66 | addressadministrativearea=`cat $scriptlocation/Items.data | jq -r ".[$j].address.administrativeArea"| sed 's/null/""/g'` 67 | addressstatecode=`cat $scriptlocation/Items.data | jq -r ".[$j].address.stateCode" | sed 's/null/""/g'` 68 | addresscountry=`cat $scriptlocation/Items.data | jq -r ".[$j].address.country"| sed 's/null/""/g'` 69 | addresscountrycode=`cat $scriptlocation/Items.data | jq -r ".[$j].address.countryCode"| sed 's/null/""/g'` 70 | addressareaofinteresta=`cat $scriptlocation/Items.data | jq -r ".[$j].address.areaOfInterest[0]" | sed 's/null/""/g'` 71 | addressareaofinterestb=`cat $scriptlocation/Items.data | jq -r ".[$j].address.areaOfInterest[1]" | sed 's/null/""/g'` 72 | echo $(date -u) "- Data gathered, going to send data to MQTT broker $mqttbroker" 73 | 74 | echo $(date -u) "- Sending MQTT data of Apple Find My object: $name" 75 | mosquitto_pub -h $mqttbroker -u $mqttusername -P $mqttpassword -t homeassistant/device_tracker/findmy_$serialnumber/config -m '{"unique_id": "'$serialnumber'", "~": "homeassistant/device_tracker/findmy_'$serialnumber'", "stat_t": "~/state", "json_attr_t": "~/attributes", "name": "Apple FindMy '$name'"}' 76 | mosquitto_pub -h $mqttbroker -u $mqttusername -P $mqttpassword -t homeassistant/device_tracker/findmy_$serialnumber/state -m ''"$addressmapItemFullAddress"'' 77 | mosquitto_pub -h $mqttbroker -u $mqttusername -P $mqttpassword -t homeassistant/device_tracker/findmy_$serialnumber/attributes -m '{"latitude": '$locationlatitude', "longitude": '$locationlongitude', "altitude": '$locationaltitude', "vertical accuracy": '$locationverticalaccuracy',"horizontal accuracy": '$locationhorizontalaccuracy', "battery_level": '$batterystatus', "antenna_power": '$antennapower'}' 78 | echo -e $(date -u) "- Transfer of MQTT data completed \n" 79 | done 80 | --------------------------------------------------------------------------------