gcobb321 / icloud3

iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.
MIT License
546 stars 54 forks source link

Family sharing fails to get location until iCloud3 restart #288

Closed christopher-wong closed 2 months ago

christopher-wong commented 10 months ago

Home Assistant 2023.10.5 Frontend 20231005.0 - latest

iCloud3 v3.0.rc8.1

I noticed an issue on the latest release candidate where I need to restart iCloud3 about once a week before it’ll begin successfully fetching Family Sharing location data again.

Event Log shows dozens of Old Location log messages and eventually pauses tracking. Resuming tracking doesn’t fix the issue. If I restart iCloud3, location tracking immediately starts working. I’ve been doing this about once a week.

IMG_3553

gcobb321 commented 10 months ago

The messages show the location is being updated but the location iCloud is really returning the position of the device from 3, r or 5-mins ago. Some of the messages show the OldThreshold of 30-secs. The interval between Location request is probably 15-secs so anything older than that will be requested. Otherwise, the device will not be properly tracked.

This is probably due to poor cell coverage at that time p poor gps positioning.

Resuming tracking refreshes all of the old location and error counts and requests the location data again. If that doesn’t work, try Event Log Locate All Devices.

There is an Old Location Adjustment parameter on the Configure Settings > Page 2 > Tracking Parameters screen that lets you increase the threshold if it is too small and is always causing those retries. Try adding 1-minute and see what happens.

christopher-wong commented 10 months ago

Thanks for the reply, Gary.

I'm still seeing this unexpected behavior with Location Old messages and iCloud3 getting stuck not reporting up to date locations. In the latest instance of this example, I tried the Event Log -> Locate Old Devices and I just got back another Location Old message. After that, I restarted iCloud3 and it immediately refreshed the devices location.

I don't think this is related to poor cell coverage on the device - restarting iCloud3 seems to reliably get things moving again.

christopher-wong commented 10 months ago
Screenshot 2023-11-11 at 4 56 46 PM Screenshot 2023-11-11 at 5 02 27 PM
gcobb321 commented 10 months ago

I’ve made a change to the next Release Candidate that will only use a15-sec interval 4 times when old location data is returned from iCloud and you are approaching Home. Then it will revert to the normal 2-3 minute threshold to try to catch the ‘old but good enough’ locations. I’ll try it for the next few days and see what happens.

christopher-wong commented 10 months ago

Thanks for looking into this!

gcobb321 commented 10 months ago

I've wrapped up rc9. Here is a preliminary copy with the code that addresses the problem you had, along with a bunch of other things. I have not uploaded this to GitHub yet but probably will this coming Wednesday. Let me know how things go (ok or there is a problem).

Unzip icloud3-rc9.zip into the icloud3 directory and restart HA. icloud3_v3-rc9.zip

rc9 Change Log:

  1. Stationary Zone

    • Fixed a bug restarting iCloud3 when reinitializing the zones and a Stationary Zone already existed. Some of the zones were not reloaded and the Stage 2 Zone setup process would end.
    • All Stationary Zone information persists over iCloud3 restarts and devices that were in the Stationary Zones will be moved back into it.
    • Unused Stationary Zones will be checked and deleted every hour
    • A nearby device results will not be used if the device's stationary zone timer has expired
  2. The iOSApp Location Time was not being saved correctly when it processed an update handling the Initial Location triggers when starting iCloud3.

  3. Bug fix - Devices that were paired with a Watch that was not being tracked were displaying a message in the Event Log that they were paired with themselves.

  4. Battery - Fixed a problem so the battery sensor would only be updated when the battery level or status changed. It was updating when the information hadn't changed which was causing excessive and unnecessary HA battery sensor state changes.

  5. Near zone (home) old location update retries - When approaching Home, the location request time was small (15-secs) and old location info was being returned from iCloud, the old location threshold was set to 15-secs to try to get a good location. This sometimes resulted in the location always being old even when it was good enough to be used. Now, the small interval will only be used for 4 Location requests. The old location threshold of 2-3 minutes will then be used.

  6. Waze History Database - Removed some maintenance activities being done when iCloud3 starts that was delaying the startup process by almost 2-minutes for a database with 10,000+ entries. This is now done at midnight. 7: Event Log - The Event Log items are displayed a lot faster after selecting a different device or refreshing the screen.

  7. HA Area - iCloud3 was assigning or reassigning the tracked and monitored devices to the 'Personal Device' area when starting. This will now only be done when the devices is added or changed from Inactive to Tracked. You can now change or delete the device's HA Area and it will not be reassigned.

  8. NEW FEATURE - Away Time Zone - "The time displayed in the Event Log and Sensors show the time an event took place using the Home 'time zone' from your Home Assistant computer. When you are away from Home and in another time zone, your tracking events are still based on the time at your Home 'time zone', not time in your current location. This feature lets you display time events on the Event Log, Sensors, Sensor Attributes and the Device_Tracker Attribures using your Away location's time zone.

This is useful if you are away for a holiday or business trip to a location in another time zone. For example, you may create a temporary zone for a house you rented, set that zone up as a 'track from' zone on the device's update screen and then all time based tracking events (arrival time, location time, etc) will show your local time instead of your Home time zone time.

The Away Time Zone screen has been added to the Configure Settings, Menu Page 1. On this screen, you can configure the devices that should display the time based entities in the Away Time Zone and the Away Time Zone's time. Two configuration fields are provided if you have several devices that are away and they are in different time zones.

  1. NEW FEATURE - Log Activity for Zones - When a device exits a zone, the zone information (Enter Time, Exit Time, Time in the Zone (minutes & hours), zone name and device_name) can be written to a spreadsheet .csv file. This file can be imported into a spreadsheet (Excel, etc) and used for travel expense reporting, monitoring when a device entered and exited a zone, who entered a zone, etc. The zones and file name format is specified for each device you want to monitor. You can monitor multiple zones for one or more devices.

The file name format is:

christopher-wong commented 10 months ago

Wow, a ton of work here - really awesome to see. I just installed rc9 and I'll report back.

christopher-wong commented 10 months ago

I'm seeing some intermittent errors in the logs refreshing location. Using the manual action to locate all devices temporarily resolves it.

Screenshot 2023-11-28 at 4 14 49 PM
gcobb321 commented 9 months ago

Below is the latest rc9 update. Unzip icloud3_v3-rc9.zip into the icloud3 directory and restart HA.

There are a lot of updates, bug fixes and new features. Review ChangeLog.txt for a complete list. They are at the top under the rc9 heading.

icloud3_v3-rc9.zip