Coder Social home page Coder Social logo

muehlt / home-assistant-findmy Goto Github PK

View Code? Open in Web Editor NEW
75.0 75.0 9.0 32 KB

A python script that reads local FindMy cache files to broadcast device locations (including those of AirTags, AirPods, Apple Watches, iPhones) to Home Assistant via MQTT.

License: Other

Python 100.00%

home-assistant-findmy's People

Contributors

muehlt avatar ndbroadbent avatar nohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

home-assistant-findmy's Issues

State flips state between "home" "unknown" and "unavailable" for items (AirTag)

The script works fine for devices but for items, an AirTag to be specific the state changes fast between "home", "unknown" and "unavailable".

Maybe not related to the script due to the state continues to change even after the script is killed!? Need to restart home assistant to get it to stop.

Dump from MQTT:

homeassistant/device_tracker/hasses_airtag/config {"name": "Hasses AirTag", "unique_id": "hasses_airtag", "state_topic": "homeassistant/device_tracker/hasses_airtag/state", "json_attributes_topic": "homeassistant/device_tracker/hasses_airtag/attributes", "device": {"identifiers": "hasses_airtag", "manufacturer": "Apple", "name": "Hasses AirTag"}, "source_type": "gps", "payload_home": "home", "payload_not_home": "not_home"}
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unavailable
XXXXXXXXXXXXXX
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/jonas_iphone_12_pro_max_2/state home
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unknown
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state home
homeassistant/device_tracker/hasses_airtag/state unavailable
homeassistant/device_tracker/hasses_airtag/state unavailable

zsh: command not found: findmy

Describe the bug
Running 'findmy' from the command line after installation on Mac OS 14.0 Sonoma results in an 'zsh: command not found' error.

To Reproduce
Steps to reproduce the behavior:

  1. Install using PIP3 as per instructions
  2. Launch via 'findmy...' as shown
  3. See error

Expected behavior
Application should launch

Desktop (please complete the following information):

  • OS: MacOS 14.0 Sonoma (clean install)

Happy to be told I've missed a step but I've tried both locally on this machine via Terminal and via a SSH session into the machine and both are giving the error.

PermissionError: [Errno 1] Operation not permitted: '/Users/jdyer/Library/Caches/com.apple.findmy.fmipcore/Items.data'

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. run application

Expected behavior
App to start

Screenshots

╭─    ~/Projects/home-assistant-findmy/findmy    main ?2                                                                               1 ✘  ▼  10:56:31 AM  ─╮
╰─ findmy -l ../test.json                                                                                                                                          ─╯
Traceback (most recent call last):
  File "/opt/homebrew/bin/findmy", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/findmy/__init__.py", line 320, in main
    scan_cache(privacy, force_sync)
  File "/opt/homebrew/lib/python3.11/site-packages/findmy/__init__.py", line 219, in scan_cache
    send_data_items(force_sync)
  File "/opt/homebrew/lib/python3.11/site-packages/findmy/__init__.py", line 107, in send_data_items
    for device in load_data(cache_file_location_items):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/findmy/__init__.py", line 78, in load_data
    with open(data_file, 'r') as f:
         ^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted: '/Users/jdyer/Library/Caches/com.apple.findmy.fmipcore/Items.data'
╭─    ~/Projects/home-assistant-findmy/findmy    main ?2                                                                               1 ✘  ▼  10:56:51 AM  ─╮
╰─ ls -la /Users/jdyer/Library/Caches/com.apple.findmy.fmipcore/Items.data                                                                                         ─╯
-rw-r--r--@ 1 jdyer  staff  18142 Sep 25 10:56 /Users/jdyer/Library/Caches/com.apple.findmy.fmipcore/Items.data
╭─    ~/Projects/home-assistant-findmy/findmy    main ?2                                                                                ✔ │ ▼  10:56:57 AM  ─╮
╰─

Desktop (please complete the following information):

  • OS: OSX
  • Browser n/a

Smartphone (please complete the following information):

  • Device: iPhone 15
  • OS: 17

Location finalisation can possibly not be finished

The data from findmy gives a locationFinished tag, and in my code i had to skip sending state to home assistant when that was false, since else it was still grabbing a more accurate state. I suggest doing the same here.

home-assistant-findmy 1.1.0 stopped working after macOS update to 14.4(23E214)

Describe the bug
Thank you very much for maintain home-assistant-findmy
Home-assistant-findmy 1.1.0 does not start at all after I update macOS to 14.4 (23E214).

To Reproduce
/Users//Library/Python/3.9/bin/findmy -l /Users//FindMytoHA/known_locations.json --ip 192.168.x.xxx --username YYYYY --password ZZZZZ

Expected behavior
Before OS update, It worked fine.

Smartphone (please complete the following information):

  • Device: MacMini M1
  • OS: macOS 14.4(23E214)

Additional context
Traceback (most recent call last):
File "/Users//Library/Python/3.9/bin/findmy", line 8, in
sys.exit(main())
File "/Users/
/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1157, in call
return self.main(*args, kwargs)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, ctx.params)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/click/core.py", line 783, in invoke
return __callback(*args, kwargs)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/findmy/init.py", line 322, in main
scan_cache(privacy, force_sync)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/findmy/init.py", line 221, in scan_cache
send_data_items(force_sync)
File "/Users/
/Library/Python/3.9/lib/python/site-packages/findmy/init.py", line 107, in send_data_items
for device in load_data(cache_file_location_items):
File "/Users/
***/Library/Python/3.9/lib/python/site-packages/findmy/init.py", line 79, in load_data
data = json.load(f)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/init.py", line 293, in load
return loads(fp.read(),
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 8: invalid continuation byte

ModuleNotFoundError: No module named 'six'

I'm getting the following issue when trying to execute the class

~/home-assistant-findmy(main*) » sudo python3 findmy.py                                                                                                                                                                                                    JORGE.ANZOLAOROPEZA@macbook
Password:
Traceback (most recent call last):
  File "/Users/JORGE.ANZOLAOROPEZA/home-assistant-findmy/findmy.py", line 35, in <module>
    from halo import Halo
  File "/Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages/halo/__init__.py", line 7, in <module>
    from .halo import Halo
  File "/Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages/halo/halo.py", line 18, in <module>
    from halo._utils import (
  File "/Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages/halo/_utils.py", line 6, in <module>
    import six
ModuleNotFoundError: No module named 'six'
~/home-assistant-findmy(main*) » pip3 install -r requirements.txt                                                                                                                                                                                          JORGE.ANZOLAOROPEZA@macbook
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: halo==0.0.31 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from -r requirements.txt (line 1)) (0.0.31)
Requirement already satisfied: paho_mqtt==1.6.1 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from -r requirements.txt (line 2)) (1.6.1)
Requirement already satisfied: python-dotenv==0.21.0 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from -r requirements.txt (line 3)) (0.21.0)
Requirement already satisfied: Unidecode==1.3.6 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from -r requirements.txt (line 4)) (1.3.6)
Requirement already satisfied: spinners>=0.0.24 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from halo==0.0.31->-r requirements.txt (line 1)) (0.0.24)
Requirement already satisfied: six>=1.12.0 in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages (from halo==0.0.31->-r requirements.txt (line 1)) (1.15.0)
Requirement already satisfied: colorama>=0.3.9 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from halo==0.0.31->-r requirements.txt (line 1)) (0.4.6)
Requirement already satisfied: termcolor>=1.1.0 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from halo==0.0.31->-r requirements.txt (line 1)) (2.2.0)
Requirement already satisfied: log-symbols>=0.0.14 in /Users/JORGE.ANZOLAOROPEZA/Library/Python/3.9/lib/python/site-packages (from halo==0.0.31->-r requirements.txt (line 1)) (0.0.14)

Add option to not send state (or send unavailible) when location is old

There is a flag in findmy's data, isOld, that I based another skip on when encountered, so that I know that that location data is possibly too old to be used for the device tracker.

(There is also a concern that, since the MQTT is always sending old data, that the device trackers aren't usable for person entities, since those rely on how/when the device tracker has last updated; https://www.home-assistant.io/integrations/person/, "then the most recently updated tracker will be used.")

Home Assistant MQTT discovery or manual entries? Discussions relating to HA

@muehlt, I just wanted to say that I've started using your script and it is great. I am running it in a MacOS VM on my Unraid machine and then the script in the terminal. I am getting most of my devices appearing natively in the MQTT section of Home Assistant.

It is a little strange, I am getting 9 devices come through to the MQTT integration within Home Assistant, however, there are 15 devices that are appearing when I connect directly to the MQTT server via MQTT explorer. I am not sure why 6 devices are not making it into Home Assistant...

I guess the reason for my post is to thank you and also to see if anyone else out there has created any MQTT sensors or device trackers via Home Assistant MQTT scripting/manual configuration?

Is there a good place to find them, is it possible to have a discussion area within this Github?

Timestamp can regress

I've added code to my own script that takes the device's identifier and caches the time from the last-seen property from it, since it could regress when new data came in.

  def regressed?(identifier, location)
    return true if @timestamps[identifier] > location.timestamp

    @timestamps[identifier] = location.timestamp
    false
  end

just one of those fun quirks that you notice when you use this for a while

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.