New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would it be possible to trigger Apple Watch complication updates through automations. #1046
Comments
It is possible to update complications via a push notification, but one potential downside is going to be how often you can do it. The complications are limited to 50 total refreshes per day. That can be once per second for 50 seconds, total, or once every 30 minutes for 24 hours, or so. Right now the app prefers the latter. |
Even with the limit of 50 per day it could be more useful to have it change based on a sensor change. For example triggering a change only if your alarm system changes state. Mostly like wouldn’t happen often, but better to be able to see that it’s disarmed before you try open your door than to have it randomly update 20mins later when the state hasn’t changed. |
Looks like this will require setting up a notify service specifically for the watch for watchOS 6+. In my reading of the docs the 50/day limit for push notifications may be separate from the periodic background uploading we do. |
OK, so I've got this working locally, but it's going to be relatively complicated:
A good amount of infrastructure work is going to be necessary to get this working, unfortunately. |
for later, this registers with PushKit. the registration request also has credentials with the token in it as Data which is the device token to push to diff --git a/Sources/Extensions/Watch/ExtensionDelegate.swift b/Sources/Extensions/Watch/ExtensionDelegate.swift
index 3c909ade..d69dccb7 100644
--- a/Sources/Extensions/Watch/ExtensionDelegate.swift
+++ b/Sources/Extensions/Watch/ExtensionDelegate.swift
@@ -14,6 +14,7 @@ import UserNotifications
import XCGLogger
import Shared
import PromiseKit
+import PushKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
// MARK: Fileprivate
@@ -24,6 +25,8 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
}
}
+ var registry: AnyObject?
+
// MARK: - WKExtensionDelegate -
func applicationDidFinishLaunching() {
@@ -48,6 +51,13 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
setupWatchCommunicator()
+ if #available(watchOSApplicationExtension 6.0, *) {
+ registry = with(PKPushRegistry(queue: nil)) {
+ $0.desiredPushTypes = [.complication]
+ $0.delegate = self
+ }
+ }
+
// schedule the next background refresh
Current.backgroundRefreshScheduler.schedule().cauterize()
}
@@ -249,3 +269,17 @@ extension ExtensionDelegate: UNUserNotificationCenterDelegate {
completionHandler([.alert, .badge, .sound])
}
}
+
+@available(watchOSApplicationExtension 6.0, *)
+extension ExtensionDelegate: PKPushRegistryDelegate {
+ func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
+ Current.Log.info("push credentials \(pushCredentials) updated for type \(type)")
+ }
+
+ func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
+ Current.Log.info("received incoming push: \(payload) for \(type)")
+ updateComplications().done {
+ completion()
+ }
+ }
+} |
Depends on home-assistant/mobile-apps-fcm-push#52. Fixes #1046, though not in the best way. However, this at least leaves it open to doing it better later. ## Summary Adds support for triggering complication updates indirectly via background notifications to the iOS app, and adds a manual update button to the complication list. ## Screenshots ![Image](https://user-images.githubusercontent.com/74188/116802546-6c2cf980-aac8-11eb-913a-6b9df9153ede.png) ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant#511 ## Any other notes This indirect method appears to be a bit slower than the direct method, but seems to mostly work.
There's another app called Complications (https://mikelyons.org/complicated/) which allows you to use webhooks to send text to your apple watch complication. It's still somewhat limited to every 5-10mins, but you can choose when it happens instead of having it update randomly, potentially just missing a sensor change.
At the moment, I use it to update a watch complication only when certain sensors change by using a shell command service to send a url encoded text. Sometimes that's multiple times an hour, other times far less. Occasionally, it won't update if there's been too many sensor changes within a short time or if I haven't opened the app on my phone in ages. But it makes my complication far more reliable than is currently available through the HA iOS app complications as I'm choosing when the update occurs.
It would be great if something similar could be implemented with the HA app complications. Would be nice to be able to cut out the middle app, especially since obviously pressing on the Complicated complication can't open the HA actions.
The text was updated successfully, but these errors were encountered: