iCloud Binding Communication Error

I’ll try to debug that tomorrow

Thanks for your work on this and for sharing your progess.

I tried it today (deleted iCloud binding in the UI, downloaded the .jar file to addons folder). It works as expected. I immediately receive a 2FA prompt on my iPhone. I entered the code in the Code field under the iCloud Account Thing in the UI. I’m running openHAB 3.4.0M1 on a Pi4 using openhabian.

Apple iCloud account is US based.

I have the same error if I setup another account in openhab, but the first account is fine.
Patrick

2022-11-09 12:29:20.382 [WARN ] [l.handler.ICloudAccountBridgeHandler] - Unable to refresh device data

java.io.IOException: Cannot authenticate token

	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.lambda$0(ICloudAccountBridgeHandler.java:110) ~[?:?]

	at org.openhab.core.cache.ExpiringCache.refreshValue(ExpiringCache.java:101) [bundleFile:?]

	at org.openhab.core.cache.ExpiringCache.getValue(ExpiringCache.java:72) [bundleFile:?]

	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.refreshData(ICloudAccountBridgeHandler.java:188) [bundleFile:?]

	at org.openhab.binding.icloud.internal.handler.ICloudDeviceHandler.refreshData(ICloudDeviceHandler.java:126) [bundleFile:?]

	at org.openhab.binding.icloud.internal.handler.ICloudDeviceHandler.initialize(ICloudDeviceHandler.java:116) [bundleFile:?]

	at jdk.internal.reflect.GeneratedMethodAccessor98.invoke(Unknown Source) ~[?:?]

	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]

	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]

	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]

	at java.lang.Thread.run(Thread.java:829) [?:?]

I’m Also having problems authenticating the code

2022-11-09 22:37:57.598 [WARN ] [l.handler.ICloudAccountBridgeHandler] - Unable to refresh device data

java.io.IOException: Cannot authenticate token

at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.lambda$0(ICloudAccountBridgeHandler.java:110) ~[?:?]

at org.openhab.core.cache.ExpiringCache.refreshValue(ExpiringCache.java:101) ~[?:?]

at org.openhab.core.cache.ExpiringCache.getValue(ExpiringCache.java:72) ~[?:?]

at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.refreshData(ICloudAccountBridgeHandler.java:188) ~[?:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]

at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) [?:?]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]

at java.lang.Thread.run(Thread.java:829) [?:?]

2022-11-09 22:37:57.617 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:6d9c5a675b' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): Cannot authenticate token

Works for my first Apple ID, but not for the second.

Cannot authenticate token

I created a new release here, which improves many things (mainly code quality and hopefully avoidance of multiple code requests). Release RC-1 · maihacke/openhab-addons · GitHub
I’m not sure if it yet supports multiple iCloud accounts. If you have issues please post debug log.

8 Likes

Thanks for your effort, will try tomorrow and report back.

1 Like

Was able to try earlier.
Updated to latest version and second account was online straight away. Great work :+1:
Only issue I see so far is some localisation strings are incorrect. But thats another story…

Edit: 3rd account online as well…

Thanks for your work! Do i need a thing config textfile? At the UI i dont see a code field and adding it at the “code tab” at MainUI doesnt let me save it

The versions from today include code field in UI.
You will need to delete and readd account thing to see it.

1 Like

thank you - had the old version

@maihacke - thank you very much for your work! Binding is actually working fine!

This did the trick ! Thanks for all your help hard work and effort !

Worked super and identified lots of different types of devices. Strangely some that are not assigned to my account anymore and others like my iPhone not.

All 3 icloud account can go online successfully.
Thanks a lot !
Patrick

First: Thank you very much! Having 2 Bridges with about 10 devices and works fully fine without errors! So glad you did the job! owntrack was a workaround, but this is much better.

Just an idea / thought of mine:
Not sure, but believe after reboot of server a new 2FA could be needed (not tested yet).

An alternative (channel for the code?) would be great (on bridge level or special item under the bridge).

This could make it possible to send e.g. a telegram message after reboot and send the code independend from being in the network. If there is already a solution to set the code (with text configured thing too) yet, a short “rule-sniplet” would be welcome.

Just out of curiosity. The whole auhtentication mechanism from Apple still depends on user/password supplied in the binding config? No change to tokens or a more sophisticated account access level?
I would love to use the binding to give openHAB access to coordinates/charging level etc. But not to photos, documents etc. Apple still does not support some granular authorisations do they?

Team,

Not sure if it helps… but I am one more from the many of us trying to get icloud at my openhab, and the history loops always to the same problem with the broken plugin. I was a little bit desperate looking for alternatives, and thanks to this community I found some people experiencing with pyicloud python. I am a python person, and realized with some small coding I can build my own icloud extractor being openhab agnostic. This code can retrieve the info of every icloud device under my account, and by config I can propagate it thru mqtt or thru direct openhab apis to feed data. I also added an specific message to propagate also by mqtt or openhab items that when 2factor credentials are expired, to be noticed

If you are interested, feel free to take a look at GitHub - redcorjo/mqtt_pyicloud . Just published today and still very basic description how to use it. Mainly, ensure to run install pyicloud first at your desktop (I use mac and raspberry), and run under the same account planned to execute this script also the initializing of icloud --username user@domain.com value

Perfect - I have three accounts and all of them are up and running now! Thanks a lot for your work!

Not sure if this is a bug or not, just letting you know. After getting the iCloud Account authenticated, about three hours went by and I noticed I received a notification on my phone to reauthorize the 2-FA code. I clicked “Allow” when it popped up and it just clicked “OK” when it gave me the 6 digit code. I did notice that in the log I received a warning

 2022-11-10 20:29:52.133 [WARN ] [l.handler.ICloudAccountBridgeHandler] - ICloud token invalid.

It is still working, (I sent a Find My iPhone Request and it notified me, and is registering location and battery) Just letting you know!

Updated and tested. Works out fine. Great work :+1:. Thanks a lot.