It seems that iOS greatly limits at what intervals apps run in the background. Although apps can “request” iOS to run it in the background at a specific interval, iOS does not honor (or have to) it. Since posting about my presence problem with the Home Assistant app, I’ve run into this “feature”/“limitation” in iOS with two other programs.
There isn’t any really solid work-around. You should keep the app running in the background (as long as you don’t close, it’s in the background) but this just helps to increase the chances that iOS will run the app sooner. One app indicated in its documentation that iOS usually will run (at least once) an app in the background between every 1-4 hours. I take that as more a ballpark figure. There just seems to be many variables at play.
The workaround for my presence problem was to use the Home Assistant API with the PushCut app. I configured the PushCut app with a “background” trigger that calls the Home Assistant API to update my presence when I come and go. You might want to check out the app…Maybe it has other trigger events?
Now, you might ask…why does PushCut work in the background when I change my location but not Home Assistant? I don’t know for certain, but my guess is that PushCut uses Location Assistance to run background tasks while Home Assistant doesn’t. For example, I have a Contact Sync app that asks to enable this Location Assistance because background tasks will be executed more quickly if I’m moving around…Again, this is part of the whole puzzle that is iOS background tasks.