iCloud Binding Communication Error

I’m not sure why they are at two different locations. Maybe there is symlink involved. Personally I would delete them.

/srv is used to export data via samba.

I deleted all files in
/var/lib/openhab/jsondb/
/var/lib/openhab/jsondb/backup/
Afterwards the files were gone in the other directories too.

But unfortunately this wasn’t the solution. My problem still remains.

As a side effect my cpu threads went down from 640 to 570.

Did you

  1. Stop openhab
  2. Delete the files
  3. Start openhab

?

Yes - this procedure

Could you post a DEBUG log here? How many digits has the code you receive from Apple?

What I did is:
Disable thing
Enable it
Allow Apple-ID registration
Enter the 6 digit 2FA code
Save changes

This is the debug


2023-01-10 19:46:22.931 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:a39aeaeff1' changed from UNINITIALIZED (DISABLED) to INITIALIZING
==> /var/log/openhab/openhab.log <==
2023-01-10 19:46:22.937 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - iCloud bridge handler initializing ...
2023-01-10 19:46:22.939 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - iCloud bridge handler initialized.
==> /var/log/openhab/events.log <==
2023-01-10 19:46:22.940 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:a39aeaeff1' changed from INITIALIZING to UNKNOWN
==> /var/log/openhab/openhab.log <==
2023-01-10 19:46:22.941 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - Starting iCloud authentication (AuthState=INITIAL, Thing=icloud:account:a39aeaeff1)...
2023-01-10 19:46:22.944 [DEBUG] [inding.icloud.internal.ICloudService] - Checking session token validity
2023-01-10 19:46:22.948 [DEBUG] [inding.icloud.internal.ICloudSession] - iCloud request POST https://setup.icloud.com/setup/ws/1/validate.
2023-01-10 19:46:23.222 [DEBUG] [inding.icloud.internal.ICloudService] - Token is not valid. Attemping new login.
org.openhab.binding.icloud.internal.ICloudApiResponseException: Request https://setup.icloud.com/setup/ws/1/validate failed with 421.
	at org.openhab.binding.icloud.internal.ICloudSession.request(ICloudSession.java:148) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudSession.post(ICloudSession.java:98) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudService.validateToken(ICloudService.java:190) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudService.authenticate(ICloudService.java:94) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.checkLogin(ICloudAccountBridgeHandler.java:341) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.callApiWithRetryAndExceptionHandling(ICloudAccountBridgeHandler.java:167) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.lambda$2(ICloudAccountBridgeHandler.java:130) ~[?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	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) [?:?]
2023-01-10 19:46:23.225 [DEBUG] [inding.icloud.internal.ICloudService] - Authenticating as XXXXXXXXXXXXXX...
2023-01-10 19:46:23.227 [DEBUG] [inding.icloud.internal.ICloudSession] - iCloud request POST https://idmsa.apple.com/appleauth/auth/signin?isRememberMeEnabled=true.
2023-01-10 19:46:24.484 [DEBUG] [inding.icloud.internal.ICloudSession] - iCloud request POST https://setup.icloud.com/setup/ws/1/accountLogin.
2023-01-10 19:46:25.564 [WARN ] [l.handler.ICloudAccountBridgeHandler] - iCloud authentication requires 2-FA code. Please provide code configuration for thing 'icloud:account:a39aeaeff1'.
==> /var/log/openhab/events.log <==
2023-01-10 19:46:25.566 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:a39aeaeff1' changed from UNKNOWN to OFFLINE (CONFIGURATION_ERROR): Please provide 2-FA code in thing configuration.
19:46:25.564 [WARN ] [l.handler.ICloudAccountBridgeHandler] - iCloud authentication requires 2-FA code. Please provide code configuration for thing 'icloud:account:a39aeaeff1'.
==> /var/log/openhab/openhab.log <==
2023-01-10 19:46:42.778 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - iCloud bridge handler initializing ...
2023-01-10 19:46:42.781 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - Starting iCloud 2-FA authentication  AuthState=WAIT_FOR_CODE, Thing=icloud:account:a39aeaeff1)...
2023-01-10 19:46:42.781 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - iCloud bridge handler initialized.
==> /var/log/openhab/events.log <==
2023-01-10 19:46:42.782 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:a39aeaeff1' changed from OFFLINE (CONFIGURATION_ERROR): Please provide 2-FA code in thing configuration. to UNKNOWN
==> /var/log/openhab/openhab.log <==
2023-01-10 19:46:42.784 [DEBUG] [l.handler.ICloudAccountBridgeHandler] - Code is given in thing configuration 'icloud:account:a39aeaeff1'. Trying to validate code...
2023-01-10 19:46:42.787 [DEBUG] [inding.icloud.internal.ICloudSession] - iCloud request POST https://idmsa.apple.com/appleauth/auth/verify/trusteddevice/securitycode.
2023-01-10 19:46:43.253 [DEBUG] [inding.icloud.internal.ICloudService] - Code verification failed.
org.openhab.binding.icloud.internal.ICloudApiResponseException: Request https://idmsa.apple.com/appleauth/auth/verify/trusteddevice/securitycode failed with 412.
	at org.openhab.binding.icloud.internal.ICloudSession.request(ICloudSession.java:148) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudSession.post(ICloudSession.java:98) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudService.validate2faCode(ICloudService.java:246) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.handle2FAAuthentication(ICloudAccountBridgeHandler.java:244) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.callApiWithRetryAndExceptionHandling(ICloudAccountBridgeHandler.java:170) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.lambda$2(ICloudAccountBridgeHandler.java:130) ~[?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	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) [?:?]
2023-01-10 19:46:43.256 [WARN ] [l.handler.ICloudAccountBridgeHandler] - ICloud token invalid.
==> /var/log/openhab/events.log <==
2023-01-10 19:46:43.258 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'icloud:account:a39aeaeff1' changed from UNKNOWN to OFFLINE (CONFIGURATION_ERROR): Invalid 2-FA-code.

For me it looks like there is something different with your iCloud account, with is not supported by the current implementation. I did a few tests with my account. When providing a wrong auth code, I receive HTTP 400. You receive HTTP 421.
The problem is, that I have currently now idea how to support here, since I cannot reproduce this with my iCloud account. Another problem is that there is no documentation available for the iCloud API. The implementation in openhab is based upon an python project for the iCloud API: GitHub - picklepete/pyicloud: A Python + iCloud wrapper to access iPhone and Calendar data.
If possible you could try to login to your account using the pycloud project examples. If this works I could help to analyze what is different there.

This test could help you with that:

import os
import click
import datetime
import time
import sys
from pyicloud import PyiCloudService


print("Setup Time Zone")
time.strftime("%X %x %Z")
os.environ["TZ"] = "America/New_York"


print("Py iCloud Services")
api = PyiCloudService("XXX", "*****")

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")

    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")
#
# Location
#
print("Location")
print(api.iphone.location())

sys.exit(1)

Many thanks for your support Simon!!
Maybe a dump question but where do I have to store the code part?

The code has nothing to with openhab. You have to download the linked python project from github and create a python file with the mentioned code. This is not a typical enduser task but development related.

Found same error in apple forum. Maybe the hints there help? https://discussions.apple.com/thread/251380063

Is there already a release available which is supported on OH 4.0.x ?

As it was included in 3.4 release, it is also available in 4.0 SNAPSHOTS.

Is the problem with more than one bridge solved yet?

I still use

235 x Active x 80 x 3.3.0.202211101645 x openHAB Add-ons :: Bundles :: iCloud Binding

because I really need two working bridges.

No, this is not solved afaik.
But using family share with three AppleIDs works like a charm.

For me the “Find my Phone” function works only for the main account, but not for family members. It´s working when triggered from my iPhone. The logs show:

2023-01-27 20:40:28.281 [ERROR] [hab.core.internal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.icloud.internal.handler.ICloudDeviceHandler@889478': Retry finally failed.
org.openhab.binding.icloud.internal.RetryException: Retry finally failed.
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.callApiWithRetryAndExceptionHandling(ICloudAccountBridgeHandler.java:216) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.findMyDevice(ICloudAccountBridgeHandler.java:290) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudDeviceHandler.handleCommand(ICloudDeviceHandler.java:145) ~[?:?]
	at jdk.internal.reflect.GeneratedMethodAccessor391.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
	at com.sun.proxy.$Proxy11169.handleCommand(Unknown Source) [?:?]
	at org.openhab.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:85) [bundleFile:?]
	at org.openhab.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]
	at jdk.internal.reflect.GeneratedMethodAccessor390.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
	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(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
	at java.lang.Thread.run(Unknown Source) [?:?]
Caused by: org.openhab.binding.icloud.internal.ICloudApiResponseException: Request https://p24-fmipweb.icloud.com:443/fmipservice/client/web/playSound failed with 500.
	at org.openhab.binding.icloud.internal.ICloudSession.request(ICloudSession.java:148) ~[?:?]
	at org.openhab.binding.icloud.internal.ICloudSession.post(ICloudSession.java:98) ~[?:?]
	at org.openhab.binding.icloud.internal.FindMyIPhoneServiceManager.playSound(FindMyIPhoneServiceManager.java:77) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.lambda$5(ICloudAccountBridgeHandler.java:294) ~[?:?]
	at org.openhab.binding.icloud.internal.handler.ICloudAccountBridgeHandler.callApiWithRetryAndExceptionHandling(ICloudAccountBridgeHandler.java:185) ~[?:?]
	... 19 more

Any hint for me what the problem might be? Seems to be a problem with iCloud calls. I’m using version 3.4.0 of the binding

Did not use „Find my Phone“ through openHAB, will give it a try over the weekend.

The result of the script is:

Setup Time Zone
Py iCloud Services
Two-factor authentication required.
Enter the code you received of one of your approved devices:525042
Code validation result: True
Location
None

So 2FA is working here.

The snap shot I use works fine with more than one bridge.

Family sharing works with both bridges too.

But let’s say: 2 families, I still need two bridges

:joy:

Maybe the snapshot helps solve this in actual binding?

Which SNAPSHOT ?