Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

0.9.8 has been released, which supports the custom ATC firmware for LYWSD03MMC out of the box (no need to use mi-like advertisements anymore). It’s advised to use the custom advertisement format, and not all, as the last might result in not showing up of the voltage sensor. custom also has a higher accuracy and reports more frequently than mi-like. Note that you need to enable battery sensors (batt_entities: True) if you want to see the voltage sensor (voltage of the battery).

How would I adjust the measured values - i.e. add 1 degree to temperature or substract 0.5% from humidity when I use this integration, installed via HACS and configured the integration in the configuration.yaml file.
If the integration would be similar to other sensors I could use a value_template:

        value_template: "{{ states('sensor.ble_humidity_a4c1389077a5') | float + 0.5 }}"

But I have no idea how to do similar with the ble-sensors without creating a new second sensor.

Hi
I am using 5x LYWSD03MMC devices with this addon.
I confirm this addon is working with latest HA core (as of 31.01.2021) with Pir3+ and correctly communicates with all devices. I would add that one of the devices is 9 metres away through two interior walls.
However, what I am experiencing is that after around two days I find that the controller goes down and HA reports an unexpected end of the bluetooth loop, and hciconfig -a reports the local controller to be DOWN and often timeouts communicating with the onboard controller, when issuing hciconfig commands. I then need to do the following

sudo systemctl restart hciuart, bluetooth
hciconfig hci0 reset

A reboot of the Pi always resolves the issue but this is an overkill every two days!

Eventually (sometimes I need to do this several times) the hci0 interface is back up and doing its PSCAN stuff, and the ble_temperature*sensors are again updated.

This is a linux/device issue to be fair.
I have scoured various forums with suggestions such as downgrading bluez and upgrading the EEPROM firmware, but this issue continues to persist. I am posting here because I only use the controller with this addon and with my sensors - no other BT devices used in my network - so to discover whether anyone has had similar timeout issues with the controller going down with timeouts, and if you have, how specifically did you fix it please.

Actually I have no idea what is going on with the Pi in terms of BT. There seems to be several BT packages installed which are not potentially needed and/or conflict with one another:

  • bluez-firmware
  • pi-bluetooth
  • bluez
  • hci
  • and various firmware “dist” files that can be downloaded and manually installed as a .deb

I also tried to downgrade bluez from 5**.5.0-1.2~deb10u1+rpt2** to 5.5.0-1.2~deb10u1 as per recommended on the RaspberryPI UK forum - but on reboot nothing could find the controller and all attempts to create/use/update the device from user-space failed with “No controller” or similar issues.

Also is this addon capable of somehow resolving comms issues with the controller?

Hello everybody,
i have the LYWSD03MMC. I want to use them in Home Assistant but i can´t connect to it.
I have an Rpi4 with the hassos image instaled. I followed the instructions but i can´t run the hcitool.
I can only run bluetoothctl. Is it possible to use this one instad hcitool? Or can any one help me to install the hcitool? Thanks for your help.
best regards

It should work out of the box, no need to install anything when using HassOs (except ble_monitor of course). Did you set your encryption key in your configuration?

Thank you Ernst. now it looks like it work. i think i have made some mistake. i tried to config it with the gui and there was only the hci interface showing. thats why i tought i need the hcitool.

0.9.11 has been released with the following changes.

Changes in 0.9.11

  • Remove jagged humidity measurements for sensors with ATC firmware
  • Added support for Bluetooth 5 advertisements (extended format) for sensors with ATC firmware
  • Improved support for motion sensor of MJYD02YL Xiaomi Motion Activated Night Light sensor (thanks for the support of @andrewjswan and @skynetua).

It’s time to move to 1.0.0! :tada: We were running out of numbers, so it was about time to move on and start with the magic number 1.0.0.

Changes in 1.0.0

To celebrate, we have added more settings that can be set/overruled for individual devices. decimals , use_median and restore_state can now be set at device level. We have removed the rounding option, as it wasn’t adding much. The same can be achieved by using a large number of decimals.

We also fixed a bug for sensors with ATC firmware, which were not working in combination with discovery: False

1 Like

Just wanted to say thanks for all your work! I just added six LYWSD03MMC sensors and it was super easy. Dug up a cheap Android phone and used the TelinkFlasher website as per your instructions and flashed the ATC firmware. It took 15 minutes to set up all 6. They were all detected by HA on a Pi (2 floors above me) within seconds of flashing, didn’t need to do a thing. :+1: Very pleased since they are to replace Xiaomi zigbee sensors that I know dont work at that same range. Plus they were a third of the price and have a screen :partying_face:

2 Likes

I am trying to edit the friendly name for these sensors, but it always puts the ble_temperature/ble_humidity in front.

Can the friendly name be fully configurable, please?

This was the solution Map new sensor to old sensor name

Updated the Raspbian this system works on and I noted a bug whereby if there is an external dongle, the internal BT sensor does not work. - Pi-bluetooth bug external and internal devices. I did revert the fix (as I have a local dongle and a remote one).

However, I am seeing these errors that eventually results in the HCI interface going down. I saw the errors before I applied the fix, after I applied the fix and again once I reverted back to the up to date version.

Feb 05 11:23:38 hassio kernel: Bluetooth: hci0: Received unexpected HCI Event 00000000
Feb 05 11:23:38 hassio kernel: Bluetooth: hci0: Received unexpected HCI Event 00000000
Feb 05 11:23:39 hassio kernel: Bluetooth: hci0: command 0x040c tx timeout
Feb 05 11:23:40 hassio kernel: Bluetooth: hci0: hardware error 0x00
Feb 05 11:23:40 hassio kernel: debugfs: File 'force_bredr_smp' in directory 'hci0' already present!
Feb 05 11:25:09 hassio kernel: Bluetooth: hci1: hardware error 0x03
Feb 05 11:25:09 hassio kernel: debugfs: File 'force_bredr_smp' in directory 'hci1' already present!
Feb 05 11:25:26 hassio kernel: Bluetooth: hci0: advertising data len corrected 28 -> 4
Feb 05 11:25:26 hassio kernel: Bluetooth: hci0: Received unexpected HCI Event 00000000
Feb 05 11:25:36 hassio kernel: Bluetooth: hci1: hardware error 0x0e
Feb 05 11:25:36 hassio kernel: debugfs: File 'force_bredr_smp' in directory 'hci1' already present!

These errors are repeated over and over in the syslog.

While migrating between the old BLE integration and the new one (so no BLE activity) no errors were seen.

[edit]
I’ll add that the data received is significantly worse than the old mitemp_bt passive system I had running. Where I used to get 10 or so readings in a 60s period, I now see a max of 5.

Not sure what I am doing wrong. I have three LYWSD03MMC sensors that have been automatically recognized by BLE Monitor. But only one is showing readings. This has been a long process so let me explain.
The two that are not showing readings were first programmed with the ATC custom firmware and I tried to install them manually using the HACS BLE app. They installed but did not read. While doing that and checking in BLE Options, I noticed that my third unit that had never been reprogrammed and was using the stock firmware was already recognized by BLE.
A noted difference was that the device (#3-stock firmware) had the MAC address (seen in BLE, options, devices {down arrow}) had no colons just the numbers and letters of the MAC address alone with no spaces. But the two other units (#1 & #2 w/ATC firmware) that were manually installed were listed with their respective MAC addresses with colons. Not sure why the difference.
So I uninstalled these two units (#1 & #2) then reprogrammed them both back to the stock firmware. These two were quickly auto recognized by BLE but no reading have ever shown in Development Tools, Current Devices. Again, all three are listed for Temp, Humid, and Battery but only the unit #3 that was never reprogrammed with ATC firmware is showing any readings.
So, could use some help if anyone can see what I have screwed up. Thanks
P.S.
(I also have one more unit that I have not removed from the box).
I have updated BLE to Version 1.0 recently after all the above with no change.
Running on Intel I7 Processor system with linux.

UPDATE:
I was able to get all three working correctly. I reprogrammed #2 & #3 with Pvvx Ver.20 custom firmware. Then BLE Monitor started to show the data. #1 was already working and kept working correctly after I reprogrammed it with the same custom firmware.

Hi,

I also have an openmqttgateway to collect broadcasted BLE info. How did you decrypt the messages from the LYWSD03MMC ?
I do have the bindkey but I don’t know how to get the data out of the servicedata or servicedatauuid since I expect this contains the encrypted info.

I flashed the alternative firmware.

so with the alternative firmware I don’t need to decode ?
I did flash the alternative firmware but is still don’t see the mqttgataway publishing the temp, hum, bat, …

I gave up on rpi and linux python to bluetooth after a lot of frustrating trying. It is just not robust enough in the area of processing advertising packets. I wrote a simple c program that collects the advertising packets and publishes them to MQTT. No need for HA to try and do any bluetooth stuff, I think this is a good thing. It has been running 2 months no problems on rpi 3 with internal bluetooth adapter, works fine with external as well or both at same time. Currently collecting from 20 BLE sensors of several types.

If you have an extra rpi or linux machine with bluetooth, you can just install it in parallel with whatever you are currently doing. Don’t change any of your HA stuff at first, the program will just publish to MQTT server and you can get a gauge if it is better. Program will publish hourly stats on number of packets received from each temperature sensor you configure, helps to position both sensors and collector machine for optional reception.

I use an ESP 32 with the openmqttgateway on it. It works fine for me at this moment.

So do I. Works very good.

Hi guys
this is a nice integration, thank you for it

I have the temperature/humidity sensor (not encrypted) and it worked fine for about half a year.

Then last month the entities (temp, hum, battery) were suddenly unavailable. I managed to get them back after a lot of fiddling, resetting the device, re-pairing with the phone, reinstalling everything in HA etc

yesterday it happened again, but this time I could not get it to work no matter what I did.

I suspect that these problems have something to do with updates to the repository or to the HA, as I have not changed anything else.

I appreciate any help, thank you.

this is my yaml entry that worked but no longer works;

ble_monitor:
  hci_interface: 0
  discovery: True
  active_scan: False
  report_unknown: False
  batt_entities: True
  decimals: 1
  period: 60
  log_spikes: False
  use_median: False
  restore_state: False
  devices:
    - mac: '59:3D:44:21:16:A7'
      name: 'Xi'
      temperature_unit: C

ther also used to be “rounding” there but I took it out as I understand it is deprecated

My hci interfaces are both dying regularly since I ran the Raspbian update. It is a real PITA. Should have not fixed something that wasn’t broken :frowning:

@baz123 Thanks a lot, that means I’m not alone… :frowning:

I ordered a new bluetooth dongle to see if something changes, but if you have the same problems…

Do you have an idea where to start the search for a solution?