Force updates for app sensors

Hi there.

I’ve been reading and testing through the Notification Commands for some time, but haven’t found an elegant way to force update my app sensors, while my phone is asleep.
The only way I got it working reliably is with command_webview, which does wake up the app, but then the app is opened on the screen, which is rather annoying.

Is there a more elegant way? Or can a command, similar to request_location_update be implemented to update other sensors as well or just wake up the app in the background?

Xiaomi is very restrictive with background apps, so sensor updates often take several minutes. Based on an automation I need to check my WiFi BSSID. Since I have several access points in the house the app doesn’t catch if I’m just for a short period near one of them.

Are you sure the phone actually connects to the other access point?
I don’t generally recommend relying on router data, but in this case, perhaps the router has the information?
Keeping the phone awake just to get this information seems like a way to drain the battery.

Yes it does and as soon as I open the HA app it updates.
Router integration doesn’t have the information so I have to rely on the app.
The update should be triggered by an automation that will run 5x/week on average, so I think battery shouldn’t be an issue.

This means the app does not have proper permission to run the background. Double check device settings and make sure it does and that all power saving settings are disabled for the app.

I have done everything I possibly can according to this guide:

The periodic updates work, but I don’t get instant sensor updates.

Does your device not respond to the intent? If you plug in your phone does it auto update?

If you mean by intent the command_webview notification - it responds within less than a second with a sensor update.

The moment I plug or unplug it I get an immediate sensor update. But letting it stay plugged doesn’t change anything.

What about when you turn off wifi?

No immeadiate response.

BTW the same issue with the bluetooth sensor detecting the connection with the car infotainment. It’s not a WiFi issue.

bluetooth and wifi use intents just like the phone being plugged in. This is an intent issue. What device is this on? Is it a custom ROM? Can you look at the device logs when you perform the above actions to see if the app is even getting the intent?

if you still have a need to force updates please submit a feature request on github and we can make it a notification command.

Xiaomi Mi 9T with stock MIUI 12 (Android 11).

Here the logs with the update from the sensor worker. It took 20 minutes to update.

It doesn’t seem to get the intent.

What sensors do you have enabled?

1 Like

Battery, loading, Bluetooth connections, WiFi BSSID, position, background position, zone
(freely translated)

Try to enable all the wifi sensors then turn wifi on and off let’s see if that works. On my pixel it works well and even detects bssid changes.

1 Like

No luck.
I suppose Pixels don’t have major issues with limiting background processes…

Try these steps let’s make sure it’s not bad data or anything.

no need for feature request, here is the PR: Add notification command to update sensors by dshokouhi · Pull Request #2194 · home-assistant/android · GitHub

1 Like

Did a fresh start - didn’t help. Also tried tons of other things, it won’t work.
Thanks a lot for trying to help me, I really appreciate it.
Looking forward to get the PR on my phone, I bet there are also use cases for a lot of other people.
SInce I’m having other issues as well, I’ll probably flash it with a custom ROM.

Can you do me a favor and check that the following Developer Option on your phone is enabled? It may help here. Its called “Mobile data always active” see if that helps when you enable it (assuming its disabled)