Unable to send service call fromwidget with https

I created a widget to turn on a scene. Ever since I’ve added SSL support it started to behave weird:
It will fail with Unable to send service call every time I click it, until I open the app. Then it will work for a short period until again it will fail until I open the app (see gif below).

I’ve tried to remove the widget and recreate it and it didn’t work.
Any idea how to fix it?

ezgif-3-e11fdb3b78

What’s the actual error message in the on device logs in companion app?

I’m getting CertPathValidatorException error due to SSL. Is there a specific way to add the certificate on Android devices?

04-05 19:04:25.504  7016  7016 E ButtonWidget: Could not send service call.
04-05 19:04:25.504  7016  7016 E ButtonWidget: io.homeassistant.companion.android.common.data.integration.IntegrationException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at io.homeassistant.companion.android.common.data.integration.impl.IntegrationRepositoryImpl.callService(IntegrationRepositoryImpl.kt:239)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at io.homeassistant.companion.android.common.data.integration.impl.IntegrationRepositoryImpl$callService$1.invokeSuspend(Unknown Source:15)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.os.Handler.handleCallback(Handler.java:938)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.os.Looper.loopOnce(Looper.java:201)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.os.Looper.loop(Looper.java:288)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.app.ActivityThread.main(ActivityThread.java:7870)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at java.lang.reflect.Method.invoke(Native Method)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-05 19:04:25.504  7016  7016 E ButtonWidget: Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.SSLUtils.toSSLHandshakeException(SSLUtils.java:363)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.convertException(ConscryptEngine.java:1134)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.readPlaintextData(ConscryptEngine.java:1089)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:876)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:747)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.unwrap(ConscryptEngine.java:712)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:858)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.access$100(ConscryptEngineSocket.java:731)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngineSocket.doHandshake(ConscryptEngineSocket.java:241)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngineSocket.startHandshake(ConscryptEngineSocket.java:220)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:379)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:337)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:209)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at java.lang.Thread.run(Thread.java:920)
04-05 19:04:25.504  7016  7016 E ButtonWidget: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:656)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:505)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:425)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:353)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:90)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngineSocket$2.checkServerTrusted(ConscryptEngineSocket.java:163)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:255)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.verifyCertificateChain(ConscryptEngine.java:1638)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.NativeCrypto.ENGINE_SSL_read_direct(Native Method)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.NativeSsl.readDirectByteBuffer(NativeSsl.java:569)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.readPlaintextDataDirect(ConscryptEngine.java:1095)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	at com.android.org.conscrypt.ConscryptEngine.readPlaintextData(ConscryptEngine.java:1079)
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	... 27 more
04-05 19:04:25.504  7016  7016 E ButtonWidget: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
04-05 19:04:25.504  7016  7016 E ButtonWidget: 	... 40 more

You mean like a self signed certificate? You should be able to import that

If this is supposed to be a valid certificate then you may want to try a different provider as Android can be picky about it. The trust anchor error suggests that may be the case here.

Ever figure this out?