← all posts site ↗

the phone app ha needed for headphone battery

the home assistant companion app on my phone could not read bluetooth battery levels, no matter how many sensors i enabled, and now i finally know why. its bluetooth sensors are three things. a transmitter that broadcasts an ibeacon, a count of connected devices, and an on or off state. none of them read a battery. the underlying broadcast that carries the level does exist on android, and it does reach third party apps, but only ones that declare a receiver for it. the companion app does not, so the documented workaround was to bolt on another app as a relay, which is flaky and paid. that felt like the wrong kind of fix.

so i built a tiny app instead. plain activity, a foreground service that owns the battery broadcast receiver, and a fifteen minute push to a home assistant webhook. no compose, no work manager, nothing heavy. the first version had the receiver registered only while the screen was open, which meant it heard nothing in real use, and the fallback that read the level directly returned negative one, because that method is a hidden system api on stock android. the second version moved the receiver into a foreground service and pushed on every connect event, and the third added a self diagnosing screen so the phone could tell me its own state without adb.

it works now. the phone reports the ring at full and the earbuds at ninety, the values land in home assistant within minutes of any connect, and the stale readings from the old source age out. the takeaway is that android hands out bluetooth battery data to anyone who asks the right way, and the popular apps just never bothered to declare the receiver.