iCloud custom_component device tracker that will not drain your battery

@nicx You both will want to enable debugging and then look though your home-assistant.log for "custom_components.device_tracker.icloud2] Updating device "

The way the component is currently written if you have a matching device that is offline the calculated interval will stay at one minute, and you’ll drain the battery on all of your devices quickly.

Just so I am clear on this, tracking any device that’s off, causes all other devices to drain the battery as well? Does that mean individual devices are not tracked, but every device is tracked every time any device location is requested?

Yes, that is the way the component and the underlying library, pyicloud, is written. Anytime the component interval evaluates true, a find my iPhone call is made to all devices on that iCloud account. It’s not ideal but I didn’t see any way to improve from the icloud2 component level with just a cursory look through pyicloud.

You can also see with the current iCloud device tracker component that is in the HA release that if you have say four devices you will be polling each device four times a minute! Crazy battery drain!

How do I setup filters to track family members phones ?
If for example my phone’s name is A wife B kid C ?

filter_devices: ‘phone’ shows only my phone

Try this version, still pass it a filter, but it will be ignored.

I use sosumi to automate when HA retrieves our iphone’s locations. It doesn’t require icloud component.

thanks but I still don’t understand how to apply filters.

filter_devices: ‘phone’ , ‘A’, ‘B’ ?
or
filter_devices:
- phone
- A
- B

When you add the icloud email, password, name to show in HA / your iphone will say somewhere has try to login to use icloud. The step for icloud to authorized your accounts to HA is on post #8 Mr.VladTepz

device_tracker:
  - platform: icloud2
    username: !secret icloud_usernameA
    password: !secret icloud_passwordA
    account_name: !secret icloud_descriptive_nameA
    filter_devices: 'phone'
  - platform: icloud2
    username: !secret icloud_usernameB
    password: !secret icloud_passwordB
    account_name: !secret icloud_descriptive_nameB
    filter_devices: 'phone'
  - platform: icloud2
    username: !secret icloud_usernameC
    password: !secret icloud_passwordC
    account_name: !secret icloud_descriptive_nameC
    filter_devices: 'phone'
1 Like

thank you for help I will try it out.

I set up icloud2 but I do not see any new device in the list. I have nmap enabled so devices are being tracked by it. I do not see any new device connected to icloud2 anywhere. What am I doing wrong ?

for iphone you have to allow Settings > iCloud > Share My Location.
for nmap enable, this is for local connection same network.
If your network didn’t find any new devices (iphone). Check at known_devices.yaml in your home assistant config folder.

If there isn’t any new device in known_devices.yaml, then manually add them in

devicename: <=== this normally is the name you given according to your iphone Setting>General>about>name> then the name your iphone use
  name: Friendly Name  <== name display in HA
  mac: EA:AA:55:E7:C6:94  <== iphone mac address
  picture: /local/****.jpg <== ****.jpg file locatedin www folder in your homeassistant folder
  track: yes
  hide_if_away: no
1 Like

Thank you for your help .
My iCloud “Share My location” is always on. I do know that nmap scans my network and gets all devices on my LAN using MAC address: After activating icloud2 and going through apple verification, I still don’t see any new devices added to my know_devices.yaml file.
I have tried all HA presence detection components. I think Geofency work best for me so I will stick with that for now. Again thanks for help.

Shelving this for now, the underlying library does locate for all devices on each update:

If that gets resolved, I’ll rework iCloud2 into a pull request to update the official HA component.

I wanted to try and save batteries a bit and trigger the icloud tracking only by other events, never periodically. E.g. magnetic door sensor: when front door is opened, check if a family member’s location changed from not_home to home --> turn on lights and TV. Or vice versa, door opens, one minute delay, some family member from home to not_home AND all family members now not_home, turn off all lights. Or, door opens, all family members status stays at not_home --> alarm.

I just couldn’t find how to make this manual triggering of icloud tracking in automation. Is it possible?

If you mean your icloud2 custom_component. Works really fine.

I have read some other users from post above. If you could provide the possibility to track not only phone but also ipad, apple watch.

Thank you very much.

What sort of timeline are you thinking it will get added to the main component? I’m using the iCloud component currently and wondering if i try holding out using that or consider moving over to your battery friendly version

1 Like

Thanks for the useful component. However, even putting the configuration as explained, all my iCloud devices are listed and not only my iPhone. How can I fix this?

After upgrade to 0.69 icloud2 component not found.

I found changing line 16 in icloud2.py fixed the component not found error.

Change
from homeassistant.components.zone import active_zone

to
from homeassistant.components.zone.zone import active_zone

Mine is now loading again.

1 Like

Thank you very much. I have now use the original icloud which a little more drain the battery.