home-assistant / home-assistant/android

Battery sensors do not update on Xiaomi 14 Ultra (MIUI) - stale data after POWER_CONNECTED intent

Open
#5,857 2 comments 0 reactions 0 assignees View on GitHub
bug question sensor-tracking
Dominant language
Kotlin
Stars
3.9k
Forks
1.1k
Avg merge
1d 12h
Merged PRs (30d)
81

Description

Home Assistant Android app version(s):
2025.8.7-full

Android version(s):
MIUI: 2.0.206.0.VNAEUXM
Android: 15 / AQ3A.240627.003

Device model(s):
Xiaomi 14 Ultra

Home Assistant version:
Core: 2025.9.4
Supervisor: 2025.09.3
OS: 16.2

Last working Home Assistant release (if known):
N/A

Description of problem, include YAML if issue is related to notifications:
On the Xiaomi 14 Ultra, all battery-related sensors (is_charging, charger_type, battery_level, battery_state) fail to update when the charging cable is connected or disconnected.

The debug logs clearly show that the app correctly receives the ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED system intents. However, immediately after receiving the intent, the app's update process concludes with "Nothing to update for server".

This suggests a race condition within the phone's operating system (MIUI). The OS sends the power connection broadcast before it updates the internal battery status that is readable by apps. When the Home Assistant app queries the battery state, it reads stale data (e.g., still "discharging"), sees no change from the previous state, and therefore sends no update to the Home Assistant server.

All standard troubleshooting steps have been performed without success, including:

- Disabling all battery optimizations ("No restrictions").
- Locking the app in the recent apps view.
- Clearing cache/data and reinstalling the app.

The issue appears to be an OS-level bug specific to this device model and MIUI version, which prevents the app from functioning as intended.

Companion App Logs:

```
# Log excerpt showing the issue. Full log was too long for GitHub.

# Event: Power is DISCONNECTED. App receives the intent...
10-01 18:33:37.641 21545 21545 D SensorReceiverBase: Received intent: android.intent.action.ACTION_POWER_DISCONNECTED
# ... but concludes there is nothing to update.
10-01 18:33:37.904 21545 21605 D SensorReceiverBase: Nothing to update for server 1 (Casa)
10-01 18:33:37.905 21545 21605 I SensorReceiverBase: Sensor updates and sync completed

...

# Event: Power is CONNECTED. App receives the intent...
10-01 18:33:40.597 21545 21545 D SensorReceiverBase: Received intent: android.intent.action.ACTION_POWER_CONNECTED
# ... but again concludes there is nothing to update, because the OS hasn't updated the battery state yet.
10-01 18:33:40.921 21545 21593 D SensorReceiverBase: Nothing to update for server 1 (Casa)
10-01 18:33:40.922 21545 21593 I SensorReceiverBase: Sensor updates and sync completed

...

# Consequence: During a regular time-based check, the app still thinks the phone is not charging and skips the update.
10-01 18:34:00.003 21545 21545 D SensorReceiverBase: Received intent: android.intent.action.TIME_TICK
10-01 18:34:00.006 21545 21605 I SensorReceiverBase$onReceive: Skipping faster update because not charging/different preference
```

Screenshot or video of problem:
N/A - The issue relates to sensor states not updating in Home Assistant, which is not easily shown in a screenshot.

Additional information:
The issue is very consistent and reproducible. The logs confirm the app is receiving the trigger but the OS is providing stale data at the moment of the query. Other users with recent Xiaomi devices have reported similar issues where the OS aggressively kills or limits background data access, and this appears to be a variation of that problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.