Is there any way to track apple airtags via Home Assistant?

Hello

Is there any addons or any way to track apple airtags via Home Assistant?

Many thanks
Mark

7 Likes

not yet I’m afraid.

I believe this is because apple categorized airtags (and airpods FWIW) as “accessories”, not “devices” like phones / tablets.

Any updates on this?

Not yet I’m afraid.

Have you tried the icloud integration? It shows location of other apple devices. I don’t have an airtag to test.

It won’t work. Airtags are “accessories”, not “devices”, in apple’s view.
So while you can track iphones via icloud integration, you cannot track “accessories” such as airpods or airtags.

I suppose different api in the background, only reserved for apple’s official “find my” app.

Unless something else has changed…

I was also looking for this to track my cat, and found this: ios - Is there a way to access your own AirTag data via API? - Stack Overflow
I had to edit the privacy settings on my Macbook to allow full disk access from the terminal, and then I could read the jsonfile containing data from my airtags, including location.

So if you have an apple computer running (maybe virtual) logged in on your icloud account, and which has the findmy app open, you can create a commandline sensor to get the data over ssh or something. For now I have a cronjob on the apple computer uploading the data to a network share on my homeserver where also HA is running on.

Another approach could be to have some screenshot service running on that apple computer and integrate the latest screenshot from the findmy app, in your HA dashboard. But this would not give you the address in an entity state as the above method.

4 Likes

Can you describe in more detail how can we make a sensor using your approach? Thanks.

see https://www.home-assistant.io/integrations/sensor.command_line/#read-value-out-of-a-remote-text-file

a sensor entity looks like this:

  - platform: command_line
    command: python3 -c "import requests; print(requests.get('http://homeserver/airtag.txt').text)" | awk '{print $2}'
    name: airtag_lon
1 Like

Thanks for a quick reply. But I meant the whole idea how you achieve having a sensor with location of an airtag. I see how you read a txt file using command line, I guess you need to add how we produce this file. Do I have to keep my mac forever turned on?

ok, I moved forward and guess I understand your approach (followed the link btw), however, the file:

$HOME/Library/Caches/com.apple.findmy.fmipcore/Items.data

does not exist on my OSX Ventura. What OSX version you use?

However, this looks like a developed solution out of the box: fjxmlzn/FindMyHistory: Track your Apple devices and look up their past location, battery levels, and more (github.com)

1 Like

I also have Ventura v13.0 - no fresh install but an update from 12.x
not sure why you can’t see the cache file… if the Find My - app is running then I guess it’s a permissions issue? I remember my Terminal program couldn’t access the file by default due to privacy settings, so make sure to check that as well.
Nice to see there’s now something developed that does about the same (and more), I’ll give it a try, thanks!

And yeah, I missed your post about how to produce the file. I have no other solution than to keep a computer running the Find My application on. Ideally this would be a vm on my NAS as that is always on, but for now I run it on my Macbook which is on most of the time, so the downside is indeed when the laptop is offline, the sensor doesn’t update.

@Mommeke This is awesome! Thanks for the tip about the JSON data at ~/Library/Caches/com.apple.findmy.fmipcore/Items.data.

I wrote a small Ruby script to read the file and create entities in Home Assistant via MQTT discovery:

It’s only running if my Macbook is active, but this is a lot better than nothing! It’s very cool to have all my AirTag location data in Home Assistant.

9 Likes

I am a bit late on the ball here and feel a bit slow :frowning:
Would you mind sharing a redacted command line you are using to setup the mqtt broker?
Not getting it to work with any of the options except refresh.
Thanks

@petemagnusson I recommend setting up the MQTT add-on for Home Assistant:

This is the easiest way to set up an MQTT broker with one click, then it will be available at port 1883 on your Home Assistant IP address.

I’ve been looking into this some more, and setting it up on my wife’s Macbook so that we can track her Airtags as well. The only problem is that she doesn’t use her Macbook very often and it is often closed, so I think I might need to run macOS in a VM on my server.

I found Push-button installer of macOS on VirtualBox: GitHub - myspaghetti/macos-virtualbox: Push-button installer of macOS Catalina, Mojave, and High Sierra guests in Virtualbox for Windows, Linux, and macOS

This looks awesome! I need to set these variables to get the VM to work with iCloud and the Find My app:

These are the variables that are usually required for iMessage connectivity:

    DmiSystemFamily    # Model name
    DmiSystemProduct   # Model identifier
    DmiBIOSVersion     # Boot ROM version
    DmiSystemSerial    # System serial number
    DmiSystemUuid      # Hardware unique identifier
    ROM                # ROM identifier, stored in NVRAM
    MLB                # Main Logic Board serial, stored in NVRAM
    DmiBoardSerial     # Main Logic Board serial, stored in EFI
    DmiBoardProduct    # Product (board) identifier
    SystemUUID         # System unique identifier, stored in NVRAM

This GitHub issue is really helpful: safe to keep using original apple hardware after `set_variables()`? · Issue #551 · myspaghetti/macos-virtualbox · GitHub
I found out that I can use GitHub - corpnewt/GenSMBIOS: Py script that uses acidanthera's macserial to generate SMBIOS and optionally saves them to a plist. to generate valid parameters for these.

This is a bit crazy and feels a bit overkill, but Airtags are super handy and the Find My coverage is amazing (via iPhones), so I think it will be quite cool to get them into Home Assistant.

I’m a bit concerned about the resource usage - this requires a minimum of 22GB disk space per VM, and it’s probably going to use a lot of RAM. Hopefully not too much CPU usage. Fortunately my server has 32GB of RAM so it should be ok. Will update this comment with the results.

EDIT: GenSMBIOS worked! Here’s an example of the fake IDs it can generate:

Type:         iMac18,3
Serial:       C02ZM6YCJ1GJ
Board Serial: C02944108CDJ0PG1F
SmUUID:       FAB32916-3705-403C-A220-06A2F9D9055A
Apple ROM:    48437CA7CA09

This script is so cool! It actually takes screenshots of the VM window and uses OCR to find text in the UI. Then it simulates mouse clicks and typing to automate the whole installation and setup process.

Super impressed so far.


Crashed:

stage: create_target_virtual_disk
Attempting to install macOS Catalina on a disk smaller than 25000MB will fail.
Please assign a larger virtual disk image size. Exiting.

Increasing from 22000 to 25000 and trying again…


Didn’t work unfortunately:

This was macOS Catalina, so either it was too old, or I didn’t set up the fake serial numbers properly.

I’m going to try again with OSX-KVM: GitHub - kholia/OSX-KVM: Run macOS on QEMU/KVM. With OpenCore + Big Sur + Monterey + Ventura support now! Only commercial (paid) support is available now to avoid spammy issues. No Mac system is required.
This one is maintained and has the latest versions of macOS, and it’s much more performant when running with qemu. I also found this detailed page about fixing iMessage and iCloud: Fixing iMessage and other services with OpenCore | OpenCore Post-Install

I think I’m going to leave it there for now, but I think this is the right track.

4 Likes

thanks for your work… do you think you can track the UUID with active BLE?
So you can find out - cat is at homeplace and with ble you can see its in the house?

at iBeacon its listet that you can track the UUID of an AirTag.

here is some similar way to get the AirTag informations and make an GPX out of it.

maybe it will help or you can have a look which one work better.

I’m currently having a blast modifying this code, adding things like device information, “last seen” sensors, and some fine-tuning of fetching the new cache file and accounting for some FindMy-initiated bugs.

I’m thinking of publishing the result via a brew tap + formula (via github), so it’s easy to install via some command like brew install airtagtap, which’d handle all the services part andsoforth, with only the MQTT host needing configuration.

I’ll keep this topic updated on it, if i ever get this far.

4 Likes

Hi guys, I made a python script that syncs the cache data to Home Assistant using MQTT and the auto-discovery feature. I just finished it, and it’s currently untested, but I’d appreciate it if we could improve it together:

The python script syncs data of Devices (iPhones, iPads, MacBooks, AirPods, Apple Watches, …) and Objects (AirTags, …), including metadata.

If the code works well in this phase, we could also release it as a more out-of-the-box package.

Have a nice day!

1 Like