Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

@myle Hi StePhan - What device did you use for the way it is explained in the video? ESP32 or something else? Also what did you use to flash?
I have spent some hours with ESPHome as per video, downloaded binary. Flashed to ESP32 Dev Board V1 with NodeMCH PY Flasher as the ESPEasy Flasher would not flash the Bin File for some reason?
Any additional help as to what you did to get it to work would be appreciated?
cheers
Bruce

I used espflasher.exe the tick i found was
start the Flashing it and then I press the boot buttom or was it the other one can’t remeber
and them PRAYED
hope this helps

got 2 of these

and these

with
https://www.ebay.com/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=Xiaomi+Mi+Bluetooth+Smart+Plant+Monitor+Flora+Soil+Water+Light+Sensor+Tester&_sacat=0

esphome:

here is my script

esphome:
  name: bluetooth199
  platform: ESP32
  board: mhetesp32devkit

wifi:
  ssid: "MYLE"
  password: "BLA.BLA.BLA"
  
  manual_ip:
    static_ip: bla.bla.bla
    gateway: bla.bla.bla
    subnet: 255.255.255.0
# Enable logging
logger:

# Enable Home Assistant API
api:
  password: 'bla.bla.bla'

web_server:
  port: 80

ota:
  password: 'bla.bla.bla'


#Enable Bluetooth scanning for this ESP32
esp32_ble_tracker:
  scan_interval: 300s
  
binary_sensor: 
  - platform: ble_presence
    mac_address: C5:52:0E:82:C3:8C
    name: "Car Keys"
  
  
sensor:
  - platform: xiaomi_mijia
    mac_address: 4C:65:A8:DE:D3:1D
    temperature:
      name: "Lounge Temperature"
      unit_of_measurement : "°C"
    humidity:
      name: "Lounge Humidity"
      unit_of_measurement : "%"
    battery_level:
      name: "Lounge Battery Level"
  - platform: wifi_signal
    name: 'Bluetooth Bridge Wifi Signal 199'
    update_interval: 10s
  - platform: uptime
    name: 'Bluetooth Bridge Uptime 199'
    
  - platform: xiaomi_miflora
    mac_address: C4:7C:8D:6A:6F:30    
    temperature:
      name: "MiFlora Temperature"
    moisture:
      name: "MiFlora Moisture"
    illuminance:
      name: "MiFlora Illuminance"
    conductivity:
      name: "MiFlora Soil Conductivity"
    battery_level:
      name: "MiFlora Battery Level"
time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: 0
        hours: 4
        days_of_week: MON-SUN
        then:
           - switch.toggle: restartit
      - seconds: 0
        minutes: 0
        hours: 16
        days_of_week: MON-SUN
        then:
           - switch.toggle: restartit
switch:
  - platform: restart
    name: "Bluetooth Restart"
    id: restartit

as the bluetooth on the esp32 plays up just hungs
the script script reboot at 4am and 4pm each day
has not mis a beat yet.

first time i had to use esphomeflasher.exe


think there a new one out .
This one has not let me down yet

thinking of adding these
https://www.ebay.com/itm/Xiaomi-Mijia-Bluetooth-Waterproof-Sonic-Electric-Toothbrush-APP-Control-HOT-SALE/253835807475?_trkparms=ispr%3D1&hash=item3b19cb0af3:g:T8gAAOSwZela8rL7&enc=AQAEAAAB4BPxNw%2BVj6nta7CKEs3N0qU74sKlk6%2FrZE0gDFIWEYyn8cVax8ACqJL8TWkZWuyle%2B9VhyyC%2FwSEQRIR412%2FXhGK2BErk9nlpbbxhprJR1ehn%2Bln6Bu192wx2CC%2Fa7Ra2mPUYq4nq28OL%2BNW3Sa%2FvtwHaH6vvySoYOvBUtjmkwF%2F82U6q4YfTXAvRpbAjGaKi68H0Jjnk2dFrEMMiaZaaLvdI7%2FjsG%2BFxU65c46g5bzxUI%2F5gBL54q%2BHT5%2BtWjr3vKn9BJHlwYTYfpUhLNJ0C1mpA97Xdjs4X8%2BEkt%2B5v4Ba556YSvB4j4syLFKNAkqO%2BvfH0csODPTW3R15ClGBhcLV4tYnRw3f8H%2FNSH4UygMVrupoqsXQ8MnLL4HNVHWBviv20FedKUC9XfmApkRCoNXWZQGiMUBLDJ9JZ7ejJ%2BPEytBGsUL3e0hY6%2BPNQUGFy0Rik6iT6JtRz%2BpMeFa2JjPOdIoqiYIlwjedNZoAnlQt0AvEz2GXzbgzouSrrfpuXZZzvhQ52Xn3dybhXdvA365SbyCnpsnbHUwhtOkNDtimw5oZWUjJ0GpYPqwDR9zn9pArWgGrHO4ZUwJOKflj6bEhU%2FKq2BZslB5P4TpwN9kd6fDBv12q8YFnGwHZzrNvgQ%3D%3D&checksum=253835807475674ba32844b842b49a67443323562e61

and

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%2By1vCeePVpnvorzuzQ25QuRMW9upfF5woAF%2BBPHAbtvFRVBvNZDyXpd5D%2BqVUX9ww3VPPkkpOzzD2z7h%2Fbcbx%2BFYE1GEWfoSpY%2BQXE1w8e9y7aKxyuoYEGF3cxbZAZdmFSu2gNxdetX4SYZmJaJO%2BE11JemWQfQbAIgvpLgS%2B1NYujwpcLq1nxsA7ZbT8dKzd%2BBFS%2BGfdvVNjQkfoaEq6tSYiYdtg%2BpfcIks6f5BQ9yiXVYiEfxXQZ%2FhGo%2FsQ3h51LgUpmkXYsW4PfzueWZ11%2B3gBHTpS%2BIzv8psvdll9%2FA51AyqDh0jHa%2BSE9wY%2BURpHoNwWEU9Ba2Ee2wR334%2FhVJ24nQlZZL29ogg%3D%3D&checksum=153554200000a6e48237153e4b01bd8f5f40586f0199

But think I have to write my module to read the bluetooth data
think they be cool tho

my screen shots

image

image

once im happy with the Miflora sensor only been in the gound for about 2 days

I be adding them to my Sprinkler system

See clear as mud

1 Like

@myle
Hey StePhan. Thanks heaps for the information. I will try this out a little later. I am really hoping to get the board working as I really like the Xiaomi Sensors and I do want to get some MiFlora sensors as well.
Hope it works. thanks again

Good luck

im just a message away if u need help

Thanks StePhan. So you used ESP32 dev boards flashed with esphomeflasher.exe for first flash?

What state was any LEDs on the Board when you plugged it into your PC?
I had RED LED on solid when I plugged usb into PC and it stayed solid RED during flashing process, no other LEDs came on during flashing.
After flash completed, i unplugged and plugged into 5v USB power supply and it still came on with Solid RED only LED and ESP32 did not connect to ESPHome, Continued to show as RED OFFLINE

Any thoughts

blue

ok Bro

step I do

write the Yaml file (do the wizard thing)
and It OFFLINE :slight_smile:
click the … on the side
and compile it and PRAY
click the “DOWNLOAD BINARY”
it will download the bin file and save it to your download folder
NOW open the esphomeflasher.exe click browse
drill down to your download folder and select that bin file


click the Flash ESP
image
then press the Boot button or is the other one can’t remember and do the Praying thing again

if still red then I the ESP32dev is not sending out a message Im over here.

the way I fix it GAVE it a static_ip

esphome:
  name: bluetooth200
  platform: ESP32
  board: mhetesp32devkit

wifi:
  ssid: "MYLE"
  password: "blabla"
  
  manual_ip:
    static_ip: ITS OWN IP ADDRESS (not given to a other device)
    gateway: IP OF ROUTER
    subnet: 255.255.255.0
# Enable logging
logger:

# Enable Home Assistant API
api:
  password: 'blabla'

do compile thing again and download and upload

Hey @myle

Thanks again mate. Yes I understand all what you have put and this is exactly what I have already done except I could not get it to flash with ESPEasy, instead I had to use NodeMCU Flasher.
I will download and try esphomeflasher and try with that. I had downloaed the Binary file and flashed however what I am interested in, is the STATE of the ESP32 Board???

What leds are lite up on the ESP32 Board?

  1. before flashing?
  2. During Flashing? and
  3. After flashing when you remove USB and then plug it back in?

I only get One RED LED Solid ON, during all these steps of before, during, and after flashing
And once it all works properly I am assuming ESPHome shows the device and green and connected?
I also already given the device a Static IP as i do for all my ESPHome devices
This is my first ESPHome device that I have had a problem and it is the first ESP32 board also

Thanks again Bud

sorry cant tell you the colour of the led

its behind a switch plate in the wall sorry

hey mate, Thanks again, was just wondering when you did flash what the state was. I will try, test and see how we get on later today.
I appreciate your help mate

all good bro

best of luck

Hey @myle StePhan

Good news mate. I now have two ESP32s and 2 Xiaomi Bluetooth temp and Humidy sensors working perfectly.
The code was right that I was using in ESPHome it turned out to simply be the Flashing program
I downloaded ESPHOME Flasher for MAC as recommended and perfect flashing process both times.
I am very happy with how these are working and update often so I get regular data to HA. I am now keep to try a couple of trackers light my iWatch and wifes Fitbit. not sure if these will work so will look around to see if I can find any info on these.

Thanks again for your help mate. Was perfect and now success!!!
Cheers

All good bro

It’s a nice buzz when all the dot join together a

Yip I am stoked and now looking at other devices that I can track and use. Next is the Flora sensors to gain some very important WAF points (Wife Approval Factor) lol
Thanks again Bud

@pixeldublu I also have these spikes in the temperature graph. About 5 a day. Are you using @Magalex code? We might have to add something in the code that ignores temperatures above 60 degrees. But unfortunately, I’m not a programmer. @Magalex, can you help us with removing the spikes from the readings?

Yes, it is seems like @pixeldublu using my code.
Let’s try to do something with this …
But first, try to verify in the official MiHome application that your sensors have the latest firmware version. And answer a couple of questions:

  • are these spikes always positive?
  • do these spikes occur only in temperature readings, or in humidity too?
  • is there anything suspicious in the HA logs at this time?

For now, I suggest you try this code, which logs the fact of exceeding 60 degrees and ignores this value further. Please forward these log entries here. I suspect that these spikes are very large, since they are distinct even after averaging, and then, I hope, it will be enough to filter readings that fall outside the range of the sensor’s measurements. Let’s make sure of that.

yea… your gist.
From what i see both temp and humidity have spikes and always positive.
The logs are little bit harder for me as i have lots of errors from other things :slight_smile:

Will give the suggestion a try.

Spikes are always positive, yes. Both in humidity as well as temperature. I don’t see anything suspicious in the logs.

I will give your new code a try. Will post the log when it occurs again. Thanks for your help! Very much appreciated.

@Magalex. I had three temperature spike errors in the log with your new code. Not visible in the graph, so perfect.

2019-09-01 18:01:05 ERROR (SyncWorker_1) [custom_components.mitemp_bt.sensor] Temperature spike: 1587.2
2019-09-01 18:35:42 ERROR (SyncWorker_9) [custom_components.mitemp_bt.sensor] Temperature spike: 1587.2
2019-09-01 20:13:24 ERROR (SyncWorker_10) [custom_components.mitemp_bt.sensor] Temperature spike: 1587.2

I noticed that all spikes errors give the same value, in your old code the spikes in the graph had different values.

Yes, in my previous code spikes a little lower, since averaging with normal data takes place, but in the log we see directly the number itself. OK. Give me some time and I’ll post the updated version.

OK, guys, I posted an updated version of my gist.
Changes:

  1. Looks like I found the source of the division by zero error. It seems that it occurs when during the period between measurements there was no data on temperature or humidity, but there was a battery level only. Fixed.
  2. Added handling of erroneous spikes. Temperature and humidity values ​​that fall outside the measuring range of the sensor are now simply discarded.
  3. Made some useful options at the beginning of the file for convenience. I think the default values ​​are suitable for most cases. Here they are:
CONF_MITEMPBT_ROUNDING = True    # enable/disable rounding of the average of all measurements taken within CONF_MITEMPBT_PERIOD seconds

(I decided to turn off rounding, as I store data in InfluxDB and use further processing. Turning off rounding allows you to maintain the original accuracy, however, some HA widgets do not have an option to limit the number of decimals.)

CONF_MITEMPBT_DECIMALS = 2       # to how many decimal places to round if rounding is enabled
CONF_MITEMPBT_PERIOD = 60        # the period of measurement in seconds during which the sensor readings are collected and transmitted to HA after averaging
CONF_MITEMPBT_TMIN = -9.9        # sensor measurement limits to exclude spikes from the results
CONF_MITEMPBT_TMAX = 60.0        #
CONF_MITEMPBT_HMIN = 0.0         #
CONF_MITEMPBT_HMAX = 99.9        #
CONF_MITEMPBT_LOG_SPIKES = False # put information about each erroneous spike in the HA log

(limits of measurements took from the my sensor specs)

Look like that’s it. Installation instructions here (for those who are not in the know). History of this method with its differences from the original and advantages under the @tsymbaliuk post. Sorry for bad English )

UPD. Apparently, limiting the minimum and maximum does not help from spikes in some sensors. To solve the problem, added the calculation of the median instead of the mean:

CONF_MITEMPBT_USE_MEDIAN = False # use median as sensor output instead of mean (helps with "spiky" sensors).
                                 # please note that both the median and the average in any case are present as the sensor state attributes.

(By default, I decided to leave this option disabled, since when it is turned on, some of the advantages that averaging of measurements gives are lost. However, the owners of “spiky” sensors have no other choice but to turn the median on…)

For those who are interested, I give a comparison of the median (green curves) and the mean on a three-hour graph of temperature and humidity (at about 20 sensor readings per minute):

2 Likes