fjxmlzn / FindMyHistory

Track your Apple devices and look up their past location, battery levels, and more
MIT License
291 stars 31 forks source link

MQTT support would be great #3

Open duffy6 opened 2 years ago

duffy6 commented 2 years ago

MQTT support would be great. Then you can send the location updates to a mqtt server

joe248 commented 1 year ago

@duffy6 I just added MQTT support in my fork. I haven't tested it extensively yet but it seems to work okay.

lennarto commented 1 year ago

@joe248 @fjxmlzn

Nice project! However, I am not able to show the GPS coordinates in Home Assistant. Are you sure that your Home Assistant Configuration is correct?

I also needed to change "name" to "modelDisplayName" in the constansts.py since this generic name was not allowed.

joe248 commented 1 year ago

Are you getting a configuration error in Home Assistant, or you're just not getting any data populated in the sensor?

If you watch the MQTT topic mosquitto_sub -t "FindMyHistory/#" what does the data look like for the device(s) you're trying to track?

lennarto commented 1 year ago

I think the main problem is that I get a ValueError: Publish topic cannot contain wildcards. because of the line

MQTT_TOPIC_KEY = 'name' in the file "constants.py"

I tried to change the name, but that broke your code 😅 Try to find a solution now, but if you have any idea that would be great.

Seems to be related to https://stackoverflow.com/questions/64410064/java-paho-mqtt-publish-to-wildcard

joe248 commented 1 year ago

Do any of your device or item names contain any non-alphanumeric characters? Those probably need to be filtered out.

joe248 commented 1 year ago

I'm guessing you have a + or # in one of your device names. Try changing log_manager.py - add import re at the top, then towards the bottom right after topic_key_value is first defined, add this line: topic_key_value = re.sub(r"[\#\+]", '', topic_key_value) to remove any + or # in the names

lennarto commented 1 year ago

Thanks for your help !! I actually had an "#" in my name and now this error got away.

However, when stripping the name string in thetopic_key_value = line, the string will differ and therefore fail in the If loops in the def refresh_log(self) just before and therefore, no updates are pushed into Home Assistant.

joe248 commented 1 year ago

when stripping the name string in thetopic_key_value = line, the string will differ and therefore fail in the If loops in the def refresh_log(self) just before and therefore, no updates are pushed into Home Assistant.

Glad you got it working. The topic_key_value is only used to generate the topic that is published over MQTT. It's not used to do anything else within the script. The only reason that this statement: if topic_key_value and topic_key_value != "NULL": would be false is if topic_key_value == "NULL" or contains only # or + characters.

Acitta commented 1 year ago

Is it possible to do this on an iPad?

DShakar commented 9 months ago

Unless you can manage to jailbreak your iPad and install MacOS somehow. it is not