iCloud3 v2.1 Device Tracker - iCloud3 v2.2 has been released (10/10/2020)

Thanks Gary, everything seems to be in order with the non-2fa account when I log into icloud.com; I can see the location of the people that I want to track, they are in the contacts app and I can see them in the ‘Find iPhone’ app.

I have emailed you some screen shots and the json response that the apple server sends back to pyicloud_ic3.py during startup. It would be really useful if you could confirm that the json response is as you would expect. If not, I will try and find out why the response is incorrect.

@gcobb321im trying to make sure I understand the “update” service call correctly.

Let’s say I followed your naming convention. Bob and Mary each have an iPhone and they are named:

  • Bob iPhone
  • Mary iPhone

They each have the iOS app installed. After iCloud3 is installed I have the following service device_tracker.icloud3_update. If I call that service with a parameter of

command: location

That will send a message to each phone (because device name was left blank) asking them to do what precisely?

  • Send their GPS location? If so, how does this get sent?
  • What else is sent from the phone?

When using device_tracker.icloud3_restart, that will reset any intervals you may have changed with device_tracker.icloud3_set_interval?

@FutureTense

  1. The iOS App will send the device’s location to HA when it receives a notification request from HA. When you use the service device_tracker.icloud3_update with the command: location, the following is sent to the device:
service: notify.ios_<your_device_id_here>
    data:
      message: "request_location_update"

The iOS App updates the device_tracker.<devicename>_XX with the devices’s location data (lat/long) and sensor.last_update_trigger_XX as a ‘Push Notification’ trigger. This info is picked up by iC3 since the trigger change and the location information is processed.

  1. device_tracker.icloud3_restart restarts iC3 and reinitialized everything like it does when HA loads. device_tracker.icloud3_update with the command: restart does the same thing.

  2. Use device_tracker.icloud3_update with the command: resume to reset the interval that is set with device_tracker.icloud3_set_interval service call. Internally, the next poll time is set to 0 (00:00:00) causing the device to be relocated on the next 5-second cycle.

Is it possible to display the city via waze? I would love to have a sensor that would display the current city the devices is in.

@coalsi No, that information is not returned from Waze. There are some sensors in the HA iOS App that display the current location of the device (street, city, etc.) that you might check out. Go to Sidebar>Developer Tools>State and scroll through the list to see if the address is displayed.

Copy, i wanted to use this via the FMF method, as i love this setup as it is easy for roommates and friends to join etc.

I guess i could setup zones for cites they/we visit often. Question maybe you know this, if i set a zone at 100 meters at a house, but a zone at say 3000-4000 meters, will the smaller zone be priority for zoning? Or will the system even recognize the zone? I guess i can try!

@coalsi Both HA and iCloud3 support a zone within a zone and overlapping zones. The current zone is determined by using the zone size and distance from the device to the zone center. The smaller zone wins if they have the same center and the closest center us used if they are overlapping.

Thanks! I have been testing out, and it is working as expected. Now just to create a lot of zones!

Thanks so much for all your hard work on this, the add-on is simply amazingly put together and documented.

On another note, radius wise. if i set up the radius is that from coordinates outwards, or overall diameter of radius?

@coalsi The radius is from the zone center to the edge of the zone.

1 Like

Sorry to jump in at this point but I was following the exchanges between Pickerin and WifiNetGuy because I wasn’t able to make icloud3 to work in my setup yet…
Brand new to hassio here, tried a few tutorial without any success…

-I installed icloud3 from hacs

-I created the following folders and subfolders under config : www/community/icloud3:

-I edited the config with the raw editor : (this is it completely) - told you it’s all new :slight_smile:

resources:
 - type: module
    url: /community_plugin/icloud3/icloud3-event-log-card.js
title: Maison
views:
  - badges:
      - entity: binary_sensor.updater
      - entity: person.admin
      - entity: sensor.hacs
      - entity: sun.sun
    cards:
      - entities: null
        entity: weather.maison
        path: default_view
        type: weather-forecast

-I tried to add a manual card :

entities:
  - entity: sensor.icloud3_event_log
title: iCloud Event Log
type: 'custom:icloud3-event-log-card'

-Saved
-Configuration/Server controls/restart

So now the full config is :

resources:
  - type: module
    url: /community_plugin/icloud3/icloud3-event-log-card.js
title: Maison
views:
  - badges:
      - entity: binary_sensor.updater
      - entity: person.admin
      - entity: sensor.hacs
      - entity: sun.sun
    cards:
      - entities: null
        entity: weather.maison
        path: default_view
        type: weather-forecast
      - entities:
          - entity: sensor.icloud3_event_log
        title: iCloud Event Log
        type: 'custom:icloud3-event-log-card'

nothing show up :frowning:


Any idea what I’m doing wrong ?
I’m running 0.104.3 on docker

Any help appreciated !

Isn’t this what the device_tracker.icloud3_update service sends to the device (now that notify.ios_… is depreciated)?

service: notify.mobile_app_<your_device_id_here>
    data:
      message: "request_location_update"

@marshn Yes, you are correct.

iOS App v1 is service: notify.ios_<your_device_id_here> (and no longer used)
iOS App v2 is service: notify.mobile_app_<your_device_id_here>

@tlex The url in the resources statement may be pointing to the wrong directory. Have you tried - url: /local/community/icloud3/icloud3-event-log-card.js

since yesterday I added another plugin that works using :

resources:
  - url: /community_plugin/custom-header/custom-header.js
    type: module

So I think the url ( - url: /community_plugin/) is good… any other idea ?

Also, I saw that under “developer tools” / “services” I had nothing related to Icloud3…

Really desperate here !

@tlex

  1. HACS might be controlling the community plugins may be (I don’t know, just a guess). On my computer, I have it set up exactly as described in the docs. Outside of what works on my computer, anything I offer is a guess.
  2. I have never been able to get the service’s parameters to show up under the development tools so I think there is a problem having custom_components displayed. I have taken the file for icloud, changed the icloud to icloud3, saved the file on my Pi under the custom_components/icloud3 directory and nothing. Spent a bunch of time on it and moved on to other issues.

Hi @gcobb321, have looked a little more at the problem I am having getting the icould3 FMF tracking working. The home-assistant.log file contains the following entry, which indicates the the iCloud account has no contacts associated with it:

2020-02-09 16:17:22 ERROR (SyncWorker_15) [custom_components.icloud3.device_tracker] iCloud3 Error: Setting up-iphone_neil > The email [email protected] is invalid or is not in the Username: [email protected] FMF contact list. Valid [email protected] contacts are .

However, everything seems to be set up fine on icloud.com, the iphones that I want to track all have associated contacts (with the correct emails addresses) and I can see them on www.icloud.com in the ‘Find Friends’ and ‘Find iPhone’ app.

The problem seems to be caused in the device_tracker.py function _setup_tracked_devices_for_fmf(). Even though I believe I have set up the devices/contacts on icloud.com in accordance with your guidance, the “contactDetails” array returned by the API is empty. The json contains:

 "contactDetails":[  ],

From the comments in the code, I would expect this element to contain an array of contact details, with fields for email addresses, first & last name, a photo URL and an ‘Id’. I have tried various ways to persuade the API to populate this element, but have been unsucessful.

To get things working on my system I have made a couple of changes to the code so that instead of the empty “contactDetails” array the “following” array, which is populated, is used instead. It contains the relevant email address, and the “Id” field, which allows the correct association to be made:

   "following":[
      {
         "invitationSentToEmail":"[email protected]",
         "optedNotToShare":true,
         "expires":0,
         "expiresByGroupId":{ "kFMFGroupIdOneToOne":0 },
         "invitationAcceptedByEmail":"[email protected]",
         "source":"APP_OFFER",
         "invitationId":"41fc982a-af42-4546-bd40-3f4d6e03fc7e",
         "tkPermission":false,
         "onlyInEvent":false,
         "updateTimestamp":1581246917431,
         "createTimestamp":1581246917431,
         "invitationFromHandles":[ "[email protected]" ],
         "invitationFromEmail":"[email protected]",
         "personIdHash":"c98c61b62e9579055555ee190d58f823d855558b042e4e7e76d98fa3c73f352d",
         "invitationAcceptedHandles":[ "[email protected]" ],
         "friendPrefs":null,
         "personId":"107233321",
         "id":"MTA3MfkdhjeIyMQ~~"
      },
     ....
   ],

To use the alternate data, line of pyicloud_ic3.py changes at around line 851:

From: 
   @property
    def contacts(self):
        return self.data.get('contactDetails')
To:
   @property
    def contacts(self):
        return self.data.get('following')

And device_tracker.py at around line 5645:

From:
            for contact in fmf.contacts:
                contact_emails = contact.get('emails')
                id_contact     = contact.get('id')
To:
            for contact in fmf.contacts:
                contact_emails = contact.get('invitationAcceptedHandles')
                id_contact     = contact.get('id')

Because the “firstName” is not available also needs a change to prevent the friendly name being set to a null value. Comment out line 5678:

From:
                            self.friendly_name[devicename] = contact.get('firstName')

To:
                            # self.friendly_name[devicename] = contact.get('firstName')

The root cause of my issue is probably a misconfiguration of the iCloud.com account, so I don’t know whether this observation/suggestion is of any use to others. But if anyone else finds that they have an empty “contactDetails” array it may help.

If you have any suggestions for what may be causing the lack of contact details they would be gratefully received!

Is it possible to use this in the person component?
Now I have a “router-based” device_tracker and the icloud3 device_tracker in the person component, but I see both the person and the icloud3 device_tracker on the map.

Do you have a suggestion?

@marshn I’d like to see your HA Log file to see what is being returned from iCloud during startup. But first, add ‘log_level: debug’ to your configuration if you haven’t done that already. That will add a lot of debug info that might help figure out why you aren’t getting any contact data. Email it to [email protected] and I’ll take a look at it.

@kernehed I haven’t looked at any of the person capabilities/usage yet so I can’t offer any suggestions. It’s on my list of things to do, and unfortunately, it’s a long list.

Right now, I’m back into digging through the iCloud component, which has been rewritten as a component and an integration, to determine how the iCloud 2fa handling is done. There is also a lot of activity in the pyicloud interface to support that and to be able to request location information by device that looks promising.

@gcobb321 email containing HA log file sent as requested.