As far as I understand, the essence of the problem is that hcidump generates such a large amount of data that it quickly overflows the allowed size of the PIPE buffer and further output is blocked (sometimes only 6 readings actually reach a minute).
I solved the problem by redirecting the output of hcidump to a python tempfile - now I really get all the readings in a minute (total about 45-50 and more, 20+ per minute for each of my two sensors).
Updated my gist with the described changes (+ some small fixes).
The battery level in the tsimbalyuk code is presented not as a sensor, but as a sensor attribute, which can be seen on the status page or in details by clicking on the sensor card.
If you need a separate sensor, then you can try something like this (replace senor’s name with yours):
I’ve tried your code (with the right sensor name), but I obtain “None” in the state value.
I’m not even able to see the battery value through the sensor status:
Interesting. Battery readings are really missing… I assume two options: either the sensor does not send this data at all (it may be a firmware issue, or the hw of the sensor), or the packets with the battery level data do not reach due to a weak signal (my sensors sends battery information less often than temperature and humidity).
I can offer to connect the sensor to the official program from Xiaomi (Mi Home), and check the relevance of the firmware in it. You can also try to place the sensor closer to the Home assistant host, and see if the situation changes (as an option, you can take the code from my post, then look at the sensor’s status, where the median number will be equal to the number of packets received between sensor updates - a small number (smaller than 5, may be) will indicate poor reception conditions). If it turns out to be a bad reception, then either improve the conditions or just wait in the hope that the battery data will come one day…
I wonder whether the battery status is not broadcast for a few hours after boot time of the sensor? This is the case (as I recently found out) for the Aqara human body sensor
I’ve came back home and found my Hassio totally down… rebooted (from the main power)… all messed up!!! Reboot again (via software)… all up and running!
And now I can see battery level in all 3 images linked above.
Let’s see what will happen tomorrow…
The custom component from @tsymbaliuk makes Hassio on Raspberry Pi significantly slower, especially if you plot the data on a graph card. CPU usage and temperature is higher than usual (I have frequent load peaks above 30%).
The update of @Magalex seems to fix this issue (CPU is now running as usual again), but I haven’t tested long enough to confirm that data does not randomly stop updating.
i replaced the sensor.py file with your script. i had to change the name of your script from mitemp_bt_sensor.py to sensor.py, than i manged to save the config.
that’s the only thing that i need to do in order to avoid the database issue?