Show battery status for Xiaomi BLE plant sensors

First, thanks a lot for making the Xiaomi BLE integration! It is great to have continued support for my 40 plant sensors.
Unfortunately after adding all of them with the new integration I recognized that there is no battery information. The old way of using the plant sensors showed battery status which was very helpful to be prepared to change the batteries.
Would it be possible to add battery status in the new integration? Thanks :slight_smile:

The devs are already looking into it. The plant sensor requires polling the device to get battery info, so this needs a different BLE connection. But they are looking into it.

As I understand it, they need to be actively polled to get battery info. Does that mean the current integration is listening to the broadcasts passively?

There are actually three ways to communicate with BLE. lets call them passive scan, active scan and connecting.

Passive scan only listens to ble data, without asking.

Active scan shouts around “please send me data” (not to a paticular device, but just shouts around in the wild). Govee sensors need this, without this it wont send all the data. It also receives the passive data.

And the third method is connecting. In this method, you specifically ask one device (mac address) to send certain data (called characteristics) and this can only be read by the device that asked it. The battery of the Miflora needs this, for some odd reason. The other data of MiFlora can use passive scan.

BLE monitor uses method one by default, but can use method two, if you change the setting. Core HA BLE integrations use method 2 (xiaomi ble and govee for example), but can also be set to use method 1 (change in the Bluetooth integration). Some core integrations also use method 3 for specific brands/devices). The reason it uses method 2 is that bleak was not able to do the real passive scanning, but there have been some recent changes (not 100% sure), so that might change in the future (again not 100% sure it will). The adventure of method 2 is that it works for all passive sensors, including Govee, but the disadvantage is a slightly increased battery consumption.

Edit. Updated post as it can now use passive scanning as well

4 Likes

Thank you so much for taking the time to explain this. It makes sense now!

has anyone figured out how to report the MAC address of each device? battery is handy but I cant Identify which device in home assistant is actually associated with a physical device

It’s been requested. In the mean time, the best way is to click on the device and compare the unique identifier in the url with the device registry in the .storage folder.

So i boiled some water in a kettle then wrapped the contact end of each sensor in a paper towel and put them them in a small glass and poured enough water to slightly wet the towel, one by one. From there , I watched the temp go up and bingo, I knew which plant sensor went with the device in HA. the Analog way… :slight_smile:

Some excellent MacGyvering right there!

I identified my plant sensors by comparing moisture and conductivity values with what I see in the Flower Care app. That worked surprisingly well. :slight_smile:

Both the battery status and better names have already been merged and will be in 2022.9

1 Like

If the battery info can only come with active polling, it’d be nice if the polling interval could be configurable. For me it would be enough to check that value every 2 days or even just once a week. The batteries of those sensors really don’t hold that long. So the integration in HA should be as passive as can be. The old miflora support was actively polling (as far as I understood) and I had set the polling interval to 24 hours to save battery. I don’t need plant information to be current to the minute. It is nice to have it now with the new integration. But really I needed it only to quickly identify the sensors again. When it comes to knowing what plants need to be watered or fertilized, the information can be a day old without causing any issues to my mind.

3 Likes

See:

I have 4 Mi Flora sensors and all working with the new bluetooth from 2022.8. Since upgrading to 2022.9 two of them now show the battery percentage and the other two battery entities don’t show up. Any suggestions to add the battery entity? All are on latest firmware from the flowercare app.

battery polling is added in 2022.9. But it can take up to 24 h to get the battery state, please give it some time. It should only poll the battery status once per 24 hours.

2 Likes

It’s been around 5 days now and the battery status is still not showing up for two of my sensors. The other two are working fine. I’ve tried removing and readding the miflora and the battery still does not show up. Any suggestions?

The battery info requires a direct connection (while the other sensors are passively observed). This means that the standards for connection quality are higher to get battery info, odds are the connection is not good enough to the two that have been unable to get it.

Looks like there is an issue open to track this https://github.com/home-assistant/core/issues/81132

The Battery state is working for all of my HHCCJCY01 Xiaomi Plant sensors. It was tricky and I had to remove and re-add a couple of the plant sensors several times to onboard cleanly. I have had them all reporting via the plant integration to plant-status cards, and it’s been low effort with all the recent love BT is getting. I’m not saying it’s all fixed, just I that got it working with some effort.

Battery status works fine for me. And it simply showed up :slight_smile: Thanks so much!

Here a few of my plant cards (based on GitHub - RodBr/miflora-card: A Home Assistant Lovelace card to report MiFlora plant sensors based on the HA Plant Card.)

1 Like