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

This fella has just release a macOS app that does the same.
I like the muehlt’s MQTT approach though :slight_smile:

https://www.martinpham.com/findmysync/

2 Likes

Nice, have you tested it out yourself?

Hey all,
Wanted to follow up on this thread. I can see a few good use cases and am curious about getting this working without having to have my laptop running all the time!

There is a MacOS docker image. Would it be possible to use the sickcodes/docker-osx docker image and run it on a Raspberry pi that is running HA? (e.g. like other addons do)

My use case is my dog. We bring him along for car rides a lot and would be good to have him listed as away or with a human (who’s on HA).

2 Likes

Yes, it works well for me. But you need a Mac that runs it 24/7.

Yup - I see that. I was wondering if it it could work with the docker image for osx and that could perhaps run on the raspberry pi that runs HA?

thanks!

my previous response was to @nayd, not to you.

It will most likely work with the docker image and it will hardly work on a RPi, see Raspberry-pi 4 error: standard_init_linux.go:219: exec user process caused: exec format error: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested · Issue #234 · sickcodes/Docker-OSX · GitHub.

I can confirm this works, however it took me all day to get this figured out.
To get all you guys starting:

Requirements:
4gb RAM
25gb disk space

Start with a (fresh) docker host, can be virtualized and then make sure nested virtualization is turned on (on esxi in my case) for me it was Ubuntu.

-sudo groupadd docker (if you have not done this already)
-sudo usermod -aG docker $USER (if you have not done this already)
-sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager libguestfs-tools
-sudo systemctl enable --now libvirtd
-sudo systemctl enable --now virtlogd
-echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
-sudo modprobe kvm
-sudo reboot

run this docker command. DO NOT SUDO THIS!

docker run -i \
  --device /dev/kvm \
  -p 50922:10022 \
  -p 5999:5999 \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -e "DISPLAY=${DISPLAY:-:0.0}" \
  -e EXTRA="-display none -vnc 0.0.0.0:99,password=on" \
  -e GENERATE_UNIQUE=true \
  -e MASTER_PLIST_URL='https://raw.githubusercontent.com/sickcodes/osx-serial-generator/master/config-custom.plist' \
  -e CPU='Haswell-noTSX,vendor=GenuineIntel,+invtsc,+hypervisor,kvm=on,vmware-cpuid-freq=on' \
  sickcodes/docker-osx:ventura

-once you have a clear screen run: change vnc password YOURPASSWORD
-you may now connect with VNC to ip:5999 with the password entered before.

-Run the Disk Utility
-Erase the disk that is around 200/250GB large. do not touch the others!
-Exit the Disk Utility and install Ventura
-You may need to press enter here and there during reboots. always choose the pre-selected boot-selection!

-After install you have a working installation of MacOS Ventura
-When you restart the docker container you may have to rerun the VNC password command. (attach to the container and enter the command)

Apple didn’t like logging into my apple ID the first time. they locked my account but it was easy to restore it immediately. After that no further issues!

-Enable location services and launch the Find My app
-Download the findmy sync tool and set it up.

check GitHub for support and common issues: GitHub - sickcodes/Docker-OSX: Run macOS VM in a Docker! Run near native OSX-KVM in Docker! X11 Forwarding! CI/CD for OS X Security Research! Docker mac Containers.

9 Likes

When you say to start with a fresh docker host, are you saying it is important that the host running docker needs to be a freshly installed OS? Or is it just important that the docker configurations be fresh?

My Arch Linux server has been running for some time but never had docker installed, so I’m wondering if it should be fine to use that as my docker host (I’ll probably try it anyway).

Hi Benjamin

I think that will be fine. Check the reference topic because arch doesn’t use apt but pacman as a package manager. I suspect the other steps are the same.

Tried today your script, looks working fine for the moment. The only drawback is that one has to keep FindMy active in the foreground (not sure, but if I only minimise the window does not update caches). Also keep the script running in a terminal window, on an always running Mac. Would be nice to trigger FindMy every 5 minutes to update the caches, second to have the script running as a service or as a cron job. I like anyway the approach, I did something similar to grab web pages and transform some info in home assistant sensors. Also there is a similar approach used by GitHub - Sennevds/system_sensors: Logging of system sensor specific for the RPI and sending them to a MQTT broker, with use of yaml for configuration files.

1 Like

I’ve just started looking into this after getting a few AirTag’s and not being able to track them other than on my iPhone. So what I did was created a MacOS VM on my Unraid machine, ran the Find My application and am using @muehlt’s script in a terminal window. Because it is a VM, I am not using it for anything else and it can just pass the info straight to HA via MQTT. I increased the reporting time from 5s to 30s as there is no great need for such frequent updates (for me anyway).

So far it seems to be working pretty well. I have 15 devices in total that are found by the script and passed through to the MQTT server, however, I have encountered a few issues where only 9 my devices are coming directly to the MQTT integration automatically. At the moment I am trying to work out how to manually add them into my HA config, this is a work in progress as I am not great at that side of the scripting/config entry. Eventually I would like to have the entry as a device tracker for a person, etc.

I thought this may be useful for those wanting to integrate all your Apple devices/people/items (ie AirTags) into HA.

Update 1:
So I have added the following device tracker to configuration.yaml

device_tracker:
  - platform: mqtt_json
    devices:
      findmy_person1_iphone: homeassistant/device_tracker/person1_iphone/attributes
      findmy_airtag_1: homeassistant/device_tracker/airtag1/attributes
      findmy_airtag_2: homeassistant/device_tracker/airtag2/attributes
      findmy_airtag_3: homeassistant/device_tracker/airtag3/attributes
      findmy_airtag_4: homeassistant/device_tracker/airtag4/attributes
      findmy_person2_iphone: homeassistant/device_tracker/person2/attributes
      findmy_person3_ipad: homeassistant/device_tracker/person3's_ipad/attributes

This appears to give me device entries now, I am not sure if it is the best way, but appears to be working nonetheless.

4 Likes

Is this still working well for you? I’m interested in trying it. I also use Unraid and want to give it a try with AirTags .

@Groto, unfortunately I had to put this one on hold as my Unraid machine has been crashing a bit since my last update. So I’ve turned off any extra things to track down what is wrong. I should have a new server soon which I will run Proxmox on and then get this going again

@Groto, I’ve got my new VM up & running and this time I am using Martin Pham’s Findmysync that @s0ftice posted above. Only going for a day but working so far. I just need to work out how to get the MacOS VM to boot by itself. At the moment when it boots I have to select the boot drive and then put a password in for the login…

Sounds good. Thanks for the update!

Sorry, I’ve been busy for quite a while :frowning: If you like we could collaborate on this, if you want to create an issue? I think I read something about a FindMy workaround in this thread which might have addressed this, but without further details. I have it running on a spare Macbook where I can have FindMy in the foreground all the time, but I also noticed that updates might stop if Apple thinks FindMy is not being used when in the background…

I also wanted to let all of you know that I released the script on PyPI so you can install it using pip. The released package also has some major updates regarding configuration, some UI changes and, the most important one that I wanted to update for a while, data is now only published if the location timestamp changes, which should drastically improve the performance and reduce some issues. This mainly affected the HA instance but if performance was an issue for you client side, letting the updated script run in the background should not really impact your system anymore.

I’d really appreciate if you could try the new release and see if this reduction in frequency affects the reliability of your home assistant automations etc., or if (as suspected and observed on my devices) meta data is only updated with a new location timestamp.

You can install the script using pip3 install home-assistant-findmy

If you ran a previous verison, I wrote a short migration guide for you (since the configuration changed slightly). Otherwise you can just checkout the README.

I also enabled Discussions so be invited to brainstorm on features you’d like to see implemented or let me know about any issues. I’d really love this to be a project where everyone can provide feedback and assistance to continue a development in the right direction :slight_smile:

3 Likes

Your issue might be related to two things I fixed with the last update (duplicate reporting, updated entity structure). If you want to give it another try or want to check on things together feel free to reach out to me! If it’s not fixed I’d really like to get to the bottom of this.

If you have an existing configuration: Migration guide
If you have no config: Repo

After some extended testing, I also found that AirTags update faster and more reliable now, which can make a big difference in automations :+1:

Thanks @muehlt, I’ve just set up a macOS VM on Proxmox and am using your script.

I set up “Find My” to start on boot as a Login Item:

Then I set up the script to run on boot using a LaunchDaemon plist.

/Library/LaunchDaemons/com.muehlt.home-assistant-findmy.plist:

<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.muehlt.home-assistant-findmy</string>
        <key>Program</key>
        <string>/Users/ndbroadbent/home-assistant-findmy/start.sh</string>
        <key>WorkingDirectory</key>
        <string>/Users/ndbroadbent/home-assistant-findmy</string>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
    </dict>
</plist>

Then run this command to enable it and start the service: launchctl load -w /Library/LaunchDaemons/com.muehlt.home-assistant-findmy.plist


Here’s my start.sh script:

/Users/ndbroadbent/home-assistant-findmy/start.sh:

#!/bin/bash
set -euo pipefail
cd /Users/ndbroadbent/home-assistant-findmy

export MQTT_CLIENT_USERNAME=***********
export MQTT_CLIENT_PASSWORD="***********"
export MQTT_BROKER_IP=***********
export MQTT_BROKER_PORT=1883
export FINDMY_FILE_SCAN_INTERVAL=5

/Users/ndbroadbent/Library/Python/3.9/bin/findmy -l locations.json

(I couldn’t get the .env file to work for some reason, so I had to export the variables in my script.)

/Users/ndbroadbent/home-assistant-findmy/locations.json:

{
    "home": {
        "latitude": **********,
        "longitude": ***********,
        "tolerance": 70
    }
}

Seems to be working quite well so far!

I followed this guide to get macOS running on Proxmox: Installing macOS 13 Ventura on Proxmox 7.2 – Nicholas Sherlock

It’s a really complicated process and took a bit of trial and error. Hopefully it will keep running for a while without too much maintenance required.

4 Likes

I didn’t see this having been mentioned in the thread, so just wanted to point out that when you’re running “Find My” with the intention of tracking “items” (such as AirTags) the version of “Find My”-app needs to be one that actually supports tracking them.

For example, the version that shipped with MacOS Catalina does not support tracking items (only devices and people) and thus can’t be used … so you can’t simply grab any old old hardware and expect to be able to use that for this purpose since Apple doesn’t allow installing latest versions of the operating system on too old hardware. I have not tried using a version of “Find My” from a newer OS on an older machine - which could work in theory, but I’m afraid that Apple may have limited running the software on older OS-versions … or it may rely on something that is not available on those versions or something.

In retrospect this does make sense, but caused a minor “why isn’t it working at all?” -confusion for me for a while.