iCloud Binding Communication Error

As others, when I enabled my account thing just now, it came online.

Online here again without doing anything (openHAB 3.3).

Hi, I am currently online as well. But if somebody want I created python script which is using pyicloud library. You can integrate to your openhab via exec binding and json transformation.

icloud script

I updated script now. You can use status a localization in one request.

I’m interested, but need a little more information to implement it. Can you please share more details of how you did it in openHAB ?

Hi,
I prepared some installation guide. See to github and let me know please.

thanks

Not sure if this is the same approach, but here is my code (cleaned up):

from pyicloud import PyiCloudService
import requests

family = [\
['person1','deviceID1abcde'],\  #change
['person2','deviceID2abcdefg']\  #change
]

api = PyiCloudService('icloudusername@gmail.com', 'IcLoUdPaSsW')  #change

if api.requires_2fa:
	print("Two-factor authentication required.")
	code = input("Enter the code you received of one of your approved devices: ")
	result = api.validate_2fa_code(code)
	print("Code validation result: %s" % result)

	if not result:
		print("Failed to verify security code")
		sys.exit(1)

	if not api.is_trusted_session:
		print("Session is not trusted. Requesting trust...")
		result = api.trust_session()
		print("Session trust result %s" % result)

		if not result:
			print("Failed to request trust. You will likely be prompted for the code again in the coming weeks")

elif api.requires_2sa:
	import click
	print("Two-step authentication required. Your trusted devices are:")

	devices = api.trusted_devices
	for i, device in enumerate(devices):
		print(
			"  %s: %s" % (i, device.get('deviceName',
			"SMS to %s" % device.get('phoneNumber')))
		)

	device = click.prompt('Which device would you like to use?', default=0)
	device = devices[device]
	if not api.send_verification_code(device):
		print("Failed to send verification code")
		sys.exit(1)

	code = click.prompt('Please enter validation code')
	if not api.validate_verification_code(device, code):
		print("Failed to verify verification code")
		sys.exit(1)
	

for familymember in family:
	loc = api.devices[familymember[1]].location()
	loc = str(loc['latitude']) + "," + str(loc['longitude'])
	requests.put('http://youropenhabinstance.com/rest/items/' + familymember[0] + 'Loc/state', str(loc), headers={'Content-type': 'text/plain'})  #change (url)

You would set this script up to run using Python periodically (I think it has to be no more frequent than every 5 minutes or you’ll run into rate limits).

In OH, you just need to make sure you have items created for each family member, e.g., BobLoc, SallyLoc, etc., which match whatever you use for “person1” and “person2” at the top of the file.

The only downside I’ve found is that you have to reauthorize the script with two-factor authentication every time the system reboots.

1 Like

Good point, I added direct update location via REST.

I’m wondering if we can move the python implementation discussion to its own thread so we can keep communication in this thread limited to the iCloud binding.

Has anyone seen the WWW-Authenticate header error since the binding has come back online? I haven’t had a single instance of the error, nor had the binding go offline since it started working again a day or two ago. Interesting.

Nothing here. It has been dead stable for me since it came back online.

1 Like

No issues here since it started working again.

Regardless, recent troubles have reduced my confidence in using iCloud for presence detection. I have started experimenting with GPSTracker - Bindings | openHAB and the OwnTracks iOS App. Initial results are encouraging. Location updates are driven by when the phone thinks it needs to provide an update, which more frequent than the 5 minute minimum using the iCloud binding when you are moving; less frequent when you are stationary. Also, the GPSTracker binding handles distance and geofencing related to regions defined in the app with channels and profiles, greatly simplifying my presence-derived rules. But it is still early days for me with this approach.

1 Like

I created virtual switches for all family members and exposed them to Homekit. In Homekit I created rules (arriving home/leaving home) which change the switch state. This has been by far the most accurate presence detection for me…

1 Like

Hey, can You explain with more details please?

If you use the homekit integration ( HomeKit Add-on - System Integrations | openHAB ) you can expose openhab items to homekit. So I simply created a switch-item in OH, exposed it to homekit and it will be visible in the homekit-app on your phone. One of the standard automation rules is “Coming / Leaving home”. You just configure this rule to turn the exposed switch on or off.

Since today, the probem with the “www-authenticate header” is back again…
someone else ?

3 Likes

Yes, same here

Yes, same

…I’ve got the same

ICloud Binding not working aigain.

1 Like