Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

Is this custom component fixing the non-updating data issue ?

Yes so far everything is runs smooth. No issues.

Yes, it is fixing because there is no need for polling, the sensor originaly sends the data in every seconds.

I must be a total noob, but I can’t run your command. I tried both with a SSH session on port 22 and 22222, but each time, it returns

'bash: sudo: command not found"

I am on a Raspberry Pi 3B+, with an hassio image. Is this command supposed to work on Raspbian only ?

I did it this way

works great

even got
one of these

https://www.ebay.com/itm/Xiaomi-Mi-Bluetooth-Smart-Plant-Monitor-Flora-Soil-Water-Light-Sensor-Tester/153551869395?var=453547131351&_trkparms=ispr%3D1&hash=item23c06795d3:m:m2Zuz1p2WD8-l4i0f98ZZhg&enc=AQAEAAACIBPxNw%2BVj6nta7CKEs3N0qVyy%2B%2FGlKC87xTxz8QnnNfgY%2FcP3Aogpvo3%2BstOWpIvEi8QPC7RJujUbx28Un05hvzaOlb%2B8wjR29w%2FReHtkhhVMjiaigd%2B3loBFchhLGFaDuzeZFFDQY9ekkFIGEYU7jpNGH00LaAd6xuMZ8QYP1XcWvJd2ej1Q4r0BmqLKplCdyTBdovy%2FOO%2FvzvtWMQhkf9TZoOtzRjHelhLLcT7nXvr5sjtz2RU4MfFmw7cAwfkbW5gX5ortihQwCpN3J5VwLjwrFK%2FaVzkzA3l4jt21%2Fi6JwndwMiBatHAFiOn4Xjw85PRZUYSZYOu%2BndDhyUmeM2dgJGSFEEGfj1X5h%2BqldQxNAzIt7wLPQ19rBurSFHiYVAA4GFYoJsFB1yiHxi9Fl2CMDQkj%2Fdnyd2AQZ%2FQuaEMc%2FxmxPn92rhYY8Iletv8uQNSVRv4AxH4d%2F7uDLxfON%2BrMSgOaHcujRefxU4%2FOCVqowowywT9Bq2pc%2BXb5BjpZmuPsOBE0tbJAD5klPdOJr6hs7qjT25Q7XOSGeGOqiEPVvKlpToSGSYSVSgnSuiMLr7ncfPv62vbnzyqPV7n7%2Bx2wvSK42eABcYBatJmpjKBiNkRXIcSGvJrFcjyopqCWFvAWfwuKx1yQXwNwhEDAt%2Fp%2FqN%2Bit%2FAyWUivrd52mph29mvAIszGFl7NsOXuG7rQqboDgc9QQfTBTowMO%2FaQbA%3D&checksum=15355186939506ffa6d3ab8c4c9690a0e764d5a949f9

looking to add this to it

https://www.ebay.com/itm/Xiaomi-Smart-Body-Fat-Scale-2-Bluetooth-Balance-Test-BMI-Health-Weight-Measure/153554200000?_trkparms=ispr%3D1&hash=item23c08b25c0:m:mC4aOnCOSKceJalsMyU1EPw&enc=AQAEAAAB4BPxNw%2BVj6nta7CKEs3N0qWaEWy29gF3aMsotSpZTNyqMhEdTMj%2F47c56ZfXVETWJhNxR4%2BeskTjruOU%2Fhwa%2BJtaAXsOMRYZAv%2FmShlfimiLQaaAESvjb2R85R27qCgi4tzWDdS4gI7mG%2BCwXtCCeT%2Bc8FFBQ4kmiMV0uu3jXK903mPZjV%2FuogMszOsmsqCcvgNtb1Mg2x5rliTXGDFWBnwc9QkyDTpClk6j15k9oJI6LZEDwPbH90kc57SjFSfExybtfpIH4Y8XfpIO3l588DxpyGAEV2%2By1vCeePVpnvorwGux%2BUcC4mqTqV16fq%2FvtEouwBzz9rO%2BpPqF6OXT%2FFnOcgK0%2BTBVUzu68OyE3%2FoiUdxZOx%2FjW12ZbSbQ8rcoJ%2Bws8CIlg5N6bx7yWzzeoZWGYO4cDXG9n7A9krlmgOXCD8eyYpwySWwISu4fA2SP4tYV%2BO8%2BECEFXbqAZgeCj3FyJCP%2F%2F%2B2tlUqD3XS5Jk0GAuCq6UxGfA4Gi2MieJNaA%2B7S4hwGf7J0RjMN1IUnIDGpNBjGq2hK7Sbe%2B4ivH94ajf9vsYLb%2BDK2W6tcaD9H17xjNg0jQy3coXdGfQw8jQAEK0egUC0ODkZE2mQzexYEDWd1PdUITgqW%2BRJei813Vw%3D%3D&checksum=153554200000a9abd30853464a45a6cd79a6dc5955e6

If you are running Hassio you don’t have to run any sudo commands ( at least for me I didn’t ),

Just put the mitemp_bt folder into your custom_components folder in config, and add

sensor:
  - platform: mitemp_bt

to your configuration.yaml and you’re all set.

Restart HA and you will see sensors like mi t_582D3432CFTR

Hope this helps! Huge thanks to @tsymbaliuk :heart:

4 Likes

Thanks, worked like a charm. But I can’t see battery level, is it normal?

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):

- platform: template
  sensors:
    batt_582D3432CFTR:
      friendly_name: "Mitemp battery level"
      entity_id: sensor.mi_t_582D3432CFTR
      unit_of_measurement: '%'
      device_class: battery
      value_template: "{{ state_attr('sensor.mi_t_582D3432CFTR', 'battery_level') }}"

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: 2019-08-18_185854

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… :crossed_fingers:

Thank you, it was that simple !

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?

Yes, nothing else is needed.

1 Like

working great! i have only one issue, log file updates constantly with the following errors:

2019-08-19 18:16:47 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:16:58 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:17:09 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:17:20 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:17:30 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:17:41 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:17:52 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:03 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:14 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:25 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:36 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:47 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:18:58 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:19:09 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:19:20 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:19:31 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:19:42 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:19:53 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:20:04 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:20:14 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:20:25 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:20:36 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '
2019-08-19 18:20:47 ERROR (MainThread) [googledevices] ClientError contacting http://192.168.0.196:8008/setup/bluetooth/scan_results - 0, message='Attempt to decode JSON with unexpected mimetype: '

Thank you for your help

Seems like these errors are not related to the work of the discussed integration… I suspect this is something from the google home integration… Presence detection, maybe?

How can I set the interval scan time? In my graph it seems to be a point every minute (sometimes 2-3 points in 1 minute). Is there a way to have a point plotted every 5 minutes (for example)?

Unfortunately, I am completely newbie to the Home assistant, and do not have (yet) sufficient knowledge to make proper integration with the options. I look forward to when @tsymbaliuk has time for us)
I don’t have time yet to study the issue, so for now we can only change in my sensor.py in line 221 the text seconds = 60 to the text seconds = 300 (“minutes = 5” should also work, as it seems to me). And restart HA.