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
509 stars 52 forks source link

icloud3 device tracker falsely registered in home zone when it is actually not available? #279

Open aschmere opened 10 months ago

aschmere commented 10 months ago

One of my family members from time to time turns off its mobile data when being away from home. In these cases of "unavailability" the device is falsely displayed as "home" by the icloud3 sensor "zone_name". Question: Is this a bug or can the behavior of an icloud3 device tracker be modified in this way, that it displays the last well known zone/position? I think an "unknown" position should not automatically translate to "home".

townsmcp commented 10 months ago

I have the same issue. Just before my kids get to school they turn off their phones and a little while latter IC3 marks them as Home even though Family Sharing shows the place the kids turned off their phones. I haven’t checked IC3 log between them leaving home and switching off their phones to see if Last Update was before they left home or after they left home and correlated that to Next Update time to see if they were away between IC3 updates. Potentially the fix, for me at least, is to change IC3 polling when home to less than the amount of time it takes the kids to leave home and turn off their phones (approx half hour polling rather than 2 hours)

gcobb321 commented 10 months ago

Are you using the v3 prerelease or v2.4.7?

townsmcp commented 10 months ago

Are you using the v3 prerelease or v2.4.7?

For me, I’m on v3.0-pr1.3

aschmere commented 10 months ago

I am on v3.0pr1.

gcobb321 commented 10 months ago

I’ll check it out.

  1. Do the devices have the iosapp installed?
  2. Does it show Home or Away when they turn the device off?
  3. Have you tried setting up a zone at the school and having the phone go into that zone before they turn them off?
townsmcp commented 10 months ago

Hi Gary.

  1. Yes, the iOS app is installed on their phones, and actively signed in and working
  2. I would say 50/50 - sometimes the IC3 state for the device shows Home when their phones are turned off, other times it will show Away or Stationary. When the value is Home, if I look in the event log, I can see the location hasnt updated when the phone left home so as far as IC3 is concerned, the phone is still home however family sharing knows the phone is near the school (where it was turned off) when I look in FindMy. If I restart IC3, the status for the phone then shows Away. The school is 10 miles away.
  3. I do have a zone setup on HA for the school however I probably need to make that zone larger to account for when they turn the phones off - at the moment it is just set for the school itself rather than knowing where they turn off
gcobb321 commented 10 months ago

If the phone shows Home after they have left, the iosapp might not be using an Exit Zone trigger. Check the Event Log to see if you see one. Also see when the iosapp last issued a location. The iosapp might be asleep in the phone and not doing any updates. The Event Log will have entries like ‘Located FamShr-hh:mm:ss (iOSapp-hh:mm:ss).

You might have to set up an automation to do an iosapp Request Location service call at a certain time in the morning to try to wake it up.

aschmere commented 10 months ago

iCloud3_timeline Hi @gcobb321 , not sure, whether I understand your explanation. But let me elaborate a bit more my issue with an attached timeline (see jpg file) of my daughter's icloud3 ZoneName and HomeDistance entities in Home Assistant. I have marked 3 special events: Event 1: I drove her to the airport on Saturday morning. Expected result: ZoneName switched from "Home" to "Away", then to StatZone1. HomeDistance goes from 0km to > 100 km (location of FRA airport), so all good here. Event 2: My daughter arrives in Norway, ZoneName goes to "Away", then to another "StatZone", HomeDistance goes to > 1000 km, so all good here. Event 3 (Attention please, this is I guess unexpected now): ZoneName suddenly switched from "StatZon1" to "Home" and HomeDistance switched from > 1000km to 0km temporarily. Between Event 3 and Event 4 things are quite normal again, before there is with Event 4 another temporary switch to "Home"/0km.

So my daughter has already correctly been registered as "not at home" starting from the time, when she left for the airport, but has been "uncorrectly", although only temporarily, assessed as "at home" wtih the events 3 and 4, which is unexpected, as she constantly was staying in Norway far away from home during the whole displayed period. Any additional thoughts, why this happened?

gcobb321 commented 10 months ago

The zone would have switched to Home when the distance went to 0km. When she put the device into airplane mode, it looses communication and can not be located. iCloud3 goes into an location error mode where the interval gets increasing larger (15-secs, 1-min, 5-min, etc). I think it stops increasing when it is 1-hour. When it goes out of airplane mode, it should get the current location and continue.

Without looking at the Log files of the location events at the time it went to Home and then back to the correct value, it is impossible to speculate why this occurred.

I have been in Paris for the last few days and am flying to Newark, then Orlando FL and then driving home today. I’ll look at the Home distance sensors and see if this occurs. I have been changing how the StatZone is handled while away and maybe that was the reason. I let you know if I see anything. I’ll post the pr1.4 version to the iCloud3 Dev site and let you know when it’s available.

spry-salt commented 9 months ago

I'm also on v3.0-pr1.3 and wonder if this observation might be helpful. One of my family members is at school right now and iCloud3 did detect that when they arrived over an hour ago.

However, when I restarted iCloud3 just now it's showing that family member as being at home, so I've been digging a bit further...

The iCloud3 log for this person currently shows:

The iCloud3 Tracking Monitors show that person's device was last updated when they arrived at school over an hour ago. But all other family member devices are showing as updated in the last few minutes. No amount of requesting new updates or restarting iCloud3 fixes this.

Looking now at Apple's Find My app:

I'm not sure what to do about the discrepancy but sure would appreciate any pointers, thanks.

modelstudent101 commented 8 months ago

Just to add to this: This started happening shortly after 2 changes were made around the same time:

  1. Upgraded iCloud3 to v3.0.rc8
  2. Upgraded HA Core to 11.0 (and now 11.1)

I did a delayed update on rc8, and upgraded to 11.0 at roughly the same time, so afraid I'm not able to provide much more than that. The issue primarily appears when there is not an update through FamShare -- it seems like it may be an issue with the iOS Companion app tracking returning the device home. I'm going to disable it temporarily to see if that's the cause, only updating through FamShare. It seems to be occurring when the phone is out of connectivity, either due to tunnels, low battery, or while using reduced updates due to being in a Zone.

Just a side note: In the Device page, "iCloud3 Integration" model name is currently misspelled as "Intergration".

modelstudent101 commented 8 months ago

Disabling the iOS Companion App tracking in iCloud3 immediately returned the device to the correct location, which had a previous location update 16 minutes earlier from FamShare.

EDIT: I'm going to check to see if the family member accidentally disabled the Location updates for the iOS companion app later today.

gcobb321 commented 8 months ago

@modelstudent101 Error recovery after losing communication with the internet is always a challenge. iCloud3 goes into a retry process where the polling interval increases and eventually pauses. The iOS app usually wakes it up but it must be done manually in some cases.

modelstudent101 commented 8 months ago

Yes -- I checked the offending device, and (in my case) the issue is with the Home Assistant device_tracker returning to zone.home rather than maintaining a persistent or null state. Not an issue with iCloud3 at all, but with HA's handling of it.

Appreciate all the work you've done. I was sad to see the FmF framework go offline but the changes you've made with v3 have made up for it in other ways.

EDIT: I forgot to mention -- the offending device had accidentally changed the Companion app's Location permission from Always to While Using, causing the tracker to jump back and forth between FamShare updates.

I suspect that's what occurred with the user who posted earlier: the HA Companion device_tracker showed a persistent zone.home, while the iCloud3 device_tracker was jumping back and forth.