I was able to implement component for parsing of Bluetooth Low Energy packets payload that contains temperature/humidity/battery data and that are emitted each second by the sensor. That allows to auto-detect new sensors (both first and second versions) and passively receive data each second without battery impact at all.
There are 3 reasons why I didn’t commit my changes into home assistant repository yet (but I’m working on it):
It requires 1 more command to run on Raspberry Pi itself that allows hcidump command to run without root access:
Configuration support is not yet ready, whole configuration looks like this now:
sensor:
- platform: mitemp_bt
I did everything inside one file that goes against coding standards of Home Assistant. I’m working on it and expect to create merge request in the next months.
In case you’d like to test it on your system, here is the link to my custom_component mitemp_bt. The folder to unpack is /home/homeassistant/.homeassistant/custom_components/ Also you need to run the command I wrote above to allow rootless access to bluetooth device for hcidump tool. I will be glad for constructive feedback.
Thank you for your work, Ivan! I was pleasantly surprised by the news that this sensor sends readings every second, and does not require polling. Such operation of the sensor provides a large window for filtering its readings, but unlike the original mitemp_bt with a five-minute poll, the delay here will be acceptable even with a median of 30 or more (beautiful fast smooth graphics without affecting power consumption). We look forward to the release of your code!
On my RPI 3B+ with Raspbian Buster and HA 0.97.0 (virtualenv) your code works fine. The log has cleared of mitemp_bt timeouts.
The only thing, in addition to your instructions, I had to do:
Here is my attempt to implement filtering (and reduce HA DB growth rate
The sensor status is updated with the average of all readings, received between updates (hardcoded 60 secs). In sensor state details you can see actual number of averaged readings ("median: ").
This is my first experience with Python and HA dev, please do not laugh much )
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).