New type Bluetooth Temperature sensor Xiaomi Mijia

There are many reasons use MQTT along side HA. It is a pretty integral tool that HA uses. I like being able to keep my sensors and other things that communicate with HA outside of HA and use MQTT as the entry for the sensor data into HA, keeps HA cleaner and more stable I think. I find that I can customize the behavior of MQTT sensors much more extensively that other sensors where the functions and attributes are baked in.

As far as the bluetooth sensors, using one or more external collector boxes like a RPI in my case, or esp32’s in other models, lets you have better reception range. If you only use the bluetooth adapter in you HA server, this may limit your coverage range.

I have flashed the same firmware but now I’m lost on how to get it working with HA ? sorry still finding my way around it home you can help. like which platform did you use? what did you set the advertising format to? thanks

Hi mate, welcome to the forum.

I have to say that you first need to check that your Bluetooth (BT) controller is capable of communicating with the new firmware. My controller is BT v4.1 and it does not see the Xiaomi sensors with the new firmware .So I had to downgrade back to stock firmware. I could buy a new BT controller - but my position is that the new firmware should as a minimum be backward compatible - which it is not - so I do not use it anymore. There is nothing in the new firmware that cannot be achieved with BT4.1

So first you need to check your BT version If you do not have BT 5.0 or higher then I think the firmware will not work so go back to OEM.

In terms of HA,
It’s all described here:

This is my config as an example

  ble_monitor:
    hci_interface: 0
    discovery: False
    active_scan: False
    report_unknown: False
    batt_entities: True
    rounding: False
    decimals: 1
    period: 60
    log_spikes: False
    use_median: True
    restore_state: False
    devices:
      
      #-- replace {MAC-addr} with MAC address of sensor but leave the single quotes
      - mac: '{MAC-addr}'   
        #-- replace {key} with MAC address of sensor but leave the single quotes 
        encryption_key: '{key}' 
        temperature_unit: C

Interested to know what Bluetooth version 5 adapter you recommend for Linux and Home Assistant? I am pretty sure there are no Bluetooth version 5 adapters that currently have linux drivers. If someone made a product that required Bluetooth 5 today, they would probably sell about five units… The ACT_Mi custom firmware works fine with every Bluetooth v4.x adapter I have tried, maybe six different ones.

This is what I found at the end and it is working fine with the RaspberryPi 3 Bluetooth except for the battery it is still showing unknown after a day! same configuration as you except that I don’t have encryption_key.

I might try reflashing to see if the changes I did to the configuration has anything to do with it. I will also try without the custom fw since it is easy to get the key anyway. If I find differences in battery consumption I might switch since this is what many seems to complain about.

Thank you

Not sure what are you taking about. bluz5 is quite common and widely supported . One would have to go far back to kernel 4.0 for blz5 to be incompatible. Current linux recommendation is to move to kernel 5.5 to secure latest BT compatibility.

The Pi3 runs kernel 5.4 (assuming a headless raspberry OS in install). Hence the sensor custom firmware does not work on any of my Pi boxes.
I’m sure members would love to know how you got it working on “about 6 of them”. What adapters, name them, show us a dump - for each - of Bluetooth and kernel logging when scanning and pairing using the custom fw. I would show mine but it’s pointless because it doesn’t work and so the logs are not going to positively assert anything of tangible benefit. Only the OEM fw for these sensors, will work.

I could upgrade the kernel but I’m not, for these sensors offer no useful functionality to my need as what I have working is sufficiently acceptable. My post earlier on was misguidedly made as I had not attempted to use the sensor with latest fw on my HA install node, I was using a PC on which it did work (under Windows 10 not Linux) :pensive:

EDIT: I just remembered I wanted to test a new bluetooth keyboard that doest work with my HA Pi3 box … so I will upgrade the kernel and retest the sensor custom fw at the same time.

I have 4 of these paired, running the original hacked firmware, with an ESP32 that only goes as high as BT 4.2.

That works fine with ESPHome, although I did have to make sure that the devices are set to use the “Mi Like” advertising and not the custom advertising (which is enabled by default).

EDIT1:
Oh hell. I didn’t see that bit. I bet that is why it aint working. Arggg. I will reflash…I sense I may be coming back here with my tail between the legs …hang on…

EDIT:2
Nope, still doesn’t work. All sensors can be seen by all boxes in the house (all linux 5.4 kernels) with OEM fw but not with ATC or pvvx firmware.

Hi all,

Update:

Been working with these for 2 weeks or so and all is well in so far as tx/rx and HA sensors. Works well.
However
My bt controller keeps going to ‘DOWN’ every two days or so, sometimes a day, sometimes three days.

My box is an RPi3b with the integrated bt controller. Had this box for a few years now and bt keyboards and headsets worked flawlessly. Since using these sensors and the HA integration here, the bt controller is periodically going down and I do not know why. There is nothing specific in the HA logs other than the usual “HCI loop aborted” thing (because HA cannot access the controller) but I think one needs to set DEBUG as an option on bt somewhere in the linux config to get system logging. I don’t know so will look into this.

I can restore things through the command line by using

systemctl stop homeassistant

then

hciconfig reset hci0

hciconfig command sometimes times-out and gives an error. I just keep repeating it every 5 seconds and all is well , eventually.
If I leave it there, all is well , until I restart homeassistant. After a few hours, the bt goes down again. So there is a pattern.

I am going to try debug log level for bluetooth and this integration. Will come back with updates - but in the meantime is anyone else seeing the same issue at all?

EDIT: By the way, I’m using the pi-bluetooth stack and not bluez. I could not get much success at all with the bt controller even working with bluez (which masks hci packages and the hci interfaces by the way).

Just to let you all know, the custom component ble_monitor now supports the ATC custom advertisement formats directly. it’s recently added.

1 Like

Hi! trying to add my sensor to the configuration.yaml using the following sintax:

sensor:
  - platform: mitemp_bt
    mac: "a4:c1:38:22:f6:b2"
    name: Mijia HT
    force_update: true
    median: 1
    monitored_conditions:
      - temperature
      - humidity
      - battery
    encryptors:
      'a4:c1:38:22:f6:b2': '621feb2ad78cbca37c42d4968e567153'

I get the following error: “Invalid config for [sensor.mitemp_bt]: [encryptors] is an invalid option for [sensor.mitemp_bt]”.

How should I set the Encription key?

mitemp_bt does not support encrypted sensors. Use BLE monitor instead, this can be installed via HACS.

1 Like

Thanks for the reply, I have installed HACS. When trying to install BLE Monitor, I get a message “Loading information…” that don’t update.

I checked the HA Logs and found the following message:

Logger: custom_components.hacs
Source: custom_components/hacs/api/hacs_repository.py:108
Integration: HACS (documentation, issues)
First occurred: 9:41:30 PM (5 occurrences)
Last logged: 11:11:31 PM

  • GitHub Ratelimit error
  • Cannot connect to host api.github.com:443 ssl:default [Name does not resolve]

Any reason why HA cannot reach github?
I’m running HA on Oracle VirtualBox VM.

Update: I was able to install BLE Monitor, but it can’t find my devices.
I get the following message:

Logger: custom_components.ble_monitor
Source: custom_components/ble_monitor/init.py:539
Integration: Passive BLE monitor (documentation)
First occurred: 11:42:45 PM (3 occurrences)
Last logged: 11:44:47 PM

HCIdump thread: OS error (hci0): [Errno 19] error while attempting to bind on interface 0: No such device

I checked Bluetooth is enabled in the VM.

Did you try hci 1 in stead of 0?

Just tried now, had the same result.

What do you get if you run

hcitool dev

Guys

Back here to confirm that I have moved from this component and now using https://github.com/deepcoder/bluetooth-temperature-sensors

The benefits:-

  • mqtt HA interface
  • does not require buggy python bluetooth stack
  • reduced activity/noise
  • and best of all, zero downtime. I found that this integration kept loosing the BT controller, although it is important for me to make it clear that the BT controller going down is not an issue with this integration but rather a symptom of buggy python bluetooth stack.

Just thought I’d mention it

I think based on this I will try the XiaoMi Mijia LCD Bluetooth Thermometer Hygrometer 2 High Precision Sensor. I just want a bluetooth, RF, or zigbee device that has a read out on the screen.

Quick thanks to everyone, It works on my RPi 3, that was heplful.