Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

Hello,
I’ve been trying for a few hours to set it up without success.
System: rpi3b+, running DietPI, home assistant on docker (specific version for rpi3).
Sensor: LYWSD03MMC

I did all the steps twice and more but the sensor never seems to appear in HA

logger:
  default: warn
  logs:
    custom_components.mitemp_bt: debug

#XIAOMI BLUETOOTH SENSOR (PASSIVE)
sensor:
  - platform: mitemp_bt
    rounding: True
    decimals: 1
    period: 60
    log_spikes: False
    use_median: False
    active_scan: False
    hci_interface: 0
    batt_entities: False
    encryptors:
               'A4:C1:38:3B:94:XX': 'A370B747DCBF7E78F0F2247CCDBXXXXX'
    report_unknown: False
    whitelist: True

I stopped the container, restarted and so on a few times but really nothing happens.
The weird thing is that the only log that I can see even with debug log is that:

docker logs home-assistant 2>&1 | grep "mitemp"
2020-05-21 20:49:05 INFO (SyncWorker_0) [homeassistant.loader] Loaded mitemp_bt from custom_components.mitemp_bt
2020-05-21 20:52:37 INFO (SyncWorker_8) [homeassistant.loader] Loaded mitemp_bt from custom_components.mitemp_bt

Can anybody help?

Very strange… There are no ideas… Even at the component loading stage, there should be several messages about the number of loaded encryption keys and a white list, and then many messages about the process of starting the data collection thread. It seems that the component does not start (there are messages only from the homeassistant.loader, but there is no messages from the component itself).

You can try to enable the report_unknown option - when the component starts, a message at the INFO level should appear.

Hello, guys!

Today I set up this integration for LYWSD03MMC sensor. And it works great!
But I’ve started having troubles with device_tracker on bluetooth platform.
Tracked deviced started to disappear periodically, so HA considers them as not_home.

Can this integration affect to bluetooth tracking somehow?
Any suggestions?

Thank’s in advance for help!

P.S. I’m using RPi 4b with Hassio.

Hello! Unfortunately yes. The component conflicts with bluetooth trackers (the interface cannot work in two modes at the same time). This is stated in our FAQ.

Thanks for your answer, Alex!
Yes, I saw this statement, but I’d like to clarify it and ask if there are any solutions to deal with this conflict.
Ok, got it, so I’ll have to choose. I’ll try to come up with tracking in some other way.

One more question, just in case.
As I understand according to description your integration replaces the native mitemp_bt. If so, can I restore original one? If I remove custom integration from HACS, reboot mi RPi, will the native mitemp_bt be restored?

Yes, removing the custom component and rebooting is enough.

1 Like

@xvaprol One solution would be, to seperate the different BT scanners. I for one use this component for my themometers, installed and used on my HA-Pi4. To scan for devices I have setup a few different PIs (in this case a PiZeros) to run monitor.sh.

1 Like

Yes, but using one more RPi only for bluetooth device tracking is too much :smile:
It will be easier to use additional discrete bluetooth adapter with current RPi, I suppose.

Depends. :wink: In my case, I have my HA-Pi “in the middle” of my appartment. One PiZero is right next to the front door, the other one in the garage. I didn’t install the BT tracker because of this component, it is just a side effect, as I do some more things with these Pis and need them to be as close as possible to the door. :slight_smile:

I’m not sure, if two BT sticks or one BT stick and the built in BT are usable together. But maybe there is a BT expert around and can answer that. :slight_smile:

Yes, both the bluetooth tracker and the custom.mitemp_bt have the ability to specify an interface, so it’s quite simple to specify different ones.

Greetings.
Many thanks to Alex and the community for your hard work and solutioneering.

I’ve been struggling to get my sensors into HA.

I am running on a Pi3 running dietpi. In the the shell, bluetoothctl>scan on shows many devices including the 2 LYWSD03MMC that I am interested. One of the sensors is within 6 inches or the Pi3.

I have found the bindkeys and have them in the file. I have enabled logging and see nothing unusual other than the fact that the mitemp_bt reports 0 hci events. The are no errors in syslog.
Any pointers?

Thanks in advance.

Config:

#
logger:
        default: critical
        logs:
            custom_components.mitemp_bt: debug

# Example configuration.yaml entry
#
sensor:
  - platform: mitemp_bt
    rounding: False
    period: 60
    log_spikes: True
    batt_entities: True
    hci_interface:
      - 0
    encryptors:
      'A4:C1:38:7C:46:89': 'a1399da6549b524a1394d474ec71e4fe'
      'A4:C1:38:67:77:7F': 'c8b18f47afb75fc8b130c2aa4b93c31c'
    whitelist: False
    report_unknown: True

I set the last 2 attributes to try to get as much info as possible. I’ve tried setting the in other combinations with the same results.

Log output:

2020-05-25 11:34:02 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] Starting
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s).
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] HCIdump thread: Init
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0
2020-05-25 11:34:13 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Run
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1
2020-05-25 11:34:13 INFO (SyncWorker_2) [custom_components.mitemp_bt.sensor] Attention! Option report_unknown is enabled, be ready for a huge output...
2020-05-25 11:34:13 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] 2 encryptors mac:key pairs loaded.
2020-05-25 11:34:13 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] 0 whitelist item(s) loaded.
2020-05-25 11:34:13 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected
2020-05-25 11:34:13 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop
2020-05-25 11:34:14 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] update_ble called
2020-05-25 11:34:14 DEBUG (SyncWorker_2) [custom_components.mitemp_bt.sensor] First run, skip parsing.
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] update_ble called
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Discovering Bluetooth LE devices
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Time to analyze...
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Getting data from HCIdump thread
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] HCIdump thread: joining
2020-05-25 11:35:15 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: main event_loop stopped, finishing
2020-05-25 11:35:15 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Run finished
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] HCIdump thread: joined
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s).
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] HCIdump thread: Init
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0
2020-05-25 11:35:15 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Run
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1
2020-05-25 11:35:15 DEBUG (SyncWorker_4) [custom_components.mitemp_bt.sensor] Finished. Parsed: 0 hci events, 0 xiaomi devices.
2020-05-25 11:35:15 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection
2020-05-25 11:35:15 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected
2020-05-25 11:35:15 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] update_ble called
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Discovering Bluetooth LE devices
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Time to analyze...
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Getting data from HCIdump thread
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: joining
2020-05-25 11:36:16 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: main event_loop stopped, finishing
2020-05-25 11:36:16 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Run finished
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: joined
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s).
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: Init
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0
2020-05-25 11:36:16 DEBUG (Thread-4) [custom_components.mitemp_bt.sensor] HCIdump thread: Run
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1
2020-05-25 11:36:16 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Finished. Parsed: 0 hci events, 0 xiaomi devices.

Hello! Tell me more about your installation. Is it HA core with python venv?
First, check if the python has access rights to the interface, as indicated in paragraph 1 of the installation manual. It is important to make sure that the rights are granted to the exact interpreter that launches HA (more details are in the FAQ).

Thank you for the prompt response!
I am running Home Assistant 0.110.2 via venv. The venv python3 interpreter does have the rights mentioned in the documentation. It is python 3.8.0.

homeassistant@pi:~$ source pyenv-activate.sh 
homeassistant@pi:~$ getcap `readlink -f \`which python3\``
/home/homeassistant/.pyenv/shims/python3 = cap_net_admin,cap_net_raw+eip

Hm. I propose to do the following:

  • stop HA;
  • run sudo btmon on the command line;
  • start HA;
  • wait for the HA to start fully and stop btmon with CTRL+C;
  • show the output of btmon.

And in order to make sure that we checked the rights of the necessary binary, I suggest running this command:
ps -auxww | grep hass

Thank you, Alex. You are a star!

The ps command showed that a different interpreter was being invoked so I gave it the right permissions and all is well.

Finished. Parsed: 2252 hci events, 1 xiaomi devices.

Apologies for the inconvenience.

1 Like

Finally got my LYWSD03MMC sensors (square ones with encryption key).
They can be swapped between Celsius/Fahrenheit on the display from the app!

Procedure I followed:
First, you MUST install HACS “Xiaomi passive BLE monitor sensor platform” to be able to read LYWSD03MMC sensor(s).
The default/built-in one will currently not work with this sensor. After installing, reboot your HA!

Second, prep the Stream-app on your iOS device:
Open Stream -> HTTPS Sniffing -> CA Install. Then you will be directed to browser to download a VPN profile.
Go to General -> Profile -> Stream Generated CA… -> Install the VPN profile.

After installing VPN profile:
Open Stream -> HTTPS Sniffing -> hit trust CA in settings.
General -> About -> Certificate Trust Settings -> tick green on Stream Generated CA…

Third, make sure you are logged in to MiHome (ensure it is logged-out of other devices and region chosen is mainland China) and open Stream.
Then go to Stream-app and hit “Sniff now”, and immediately go to MiHome, pull the plastic-tab to activate sensor, and add the LYWSD03MMC sensor.
Follow the wizard. Wait for the app to read Temperature and Humidity. (Optionally you can get the MAC-address here. Under the sensor -> settings (3 dots in upper right corner) -> “About”. This is also where you can swap between displaying Celsius/Fahrenheit.
Go back to Stream-app and click “Stop Sniffing“.

Now in stream-app go to sniff history and search for the keyword “bltbind”.
You will see a file “POST https://api.io.mi.com/app/device/bltbind”
(If you don’t see that file, go back to step 2 to check whether the CA was trusted or not.)
Click on that file -> Request -> “Preview Form” at bottom, then at the top hit -> Format -> Decode -> now you look for: find “bind_key”, “value”:
After finding the bind_key, then add it to your “- platform: mitemp_bt” Configuration.yaml together with the MAC-address.
The MAC-address can be found in MiHome under the sensor and settings (3 dots in upper right corner), and “About” if you did not get it earlier. You can change between Celsius and Fahrenheit for the display here also.
Repeat this step until all sensors are added.

Fourth, when done adding all sensors, power-off HA, then restart it.
Once you HA is fully back online, go to Configuration -> Entities -> search for “mitemp_bt” and you will see the 2 sensors for each thermostat (one for temp, one for humidity). Be patient, it can take time (less than 10 minutes) for HA to detect them.

LYWSD03MMC broadcasts temperature and humidity once about every 10 minutes and battery level once an hour.

If you get impatient, you can look for the from the terminal:
root@hassio:~# bluetoothctl
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:07:AA:AA Discovering: yes
[NEW] Device A4:C1:38:AF:BB:BB LYWSD03MMC
[NEW] Device A4:C1:38:42:CC:CC LYWSD03MMC
[NEW] Device A4:C1:38:42:DD:DD LYWSD03MMC
[NEW] Device A4:C1:38:F1:EE:EE LYWSD03MMC
[NEW] Device A4:C1:38:38:FF:FF LYWSD03MMC
[NEW] Device A4:C1:38:4D:11:11 LYWSD03MMC
[bluetooth]# scan off
Discovery stopped
[bluetooth]# exit
root@hassio:~#

Added class 1 Bluetooth dongle for better reception:
TRENDnet Low Energy Micro Bluetooth 4.0 Class 1 USB 2.0, TBW-106UB
Distance: up to 100Meters/330 Feet.
https://www.amazon.com/gp/product/B002AQSTXM/

Battery indicator will show at the bottom if you click on the sensor.

My config:

sensor:
  - platform: mitemp_bt
    rounding: True
    decimals: 1
    active_scan: False
    hci_interface:
                  - 0
                  - 1
    encryptors:
               'A4:C1:38:AF:BB:BB': '17CD89A41B9FB86CF760968F1C7C9B0D'
               'A4:C1:38:42:CC:CC': '7426CA29015D144F489705CBC625C1C4'
               'A4:C1:38:42:DD:DD': '7AB69F8D733EECAB92337D209ACD2B9E'
               'A4:C1:38:F1:EE:EE': '2DC3683236481DAA7DA2B2FEE4BFD893'
               'A4:C1:38:38:FF:FF': 'C9553E560EE6C36497A864D5E31F085C'
               'A4:C1:38:4D:AA:AA': 'B2219D1E99985CC5BE2C3EDDE8D377C0'
3 Likes

Can’t find bitbind

Yes it is, under integrations. It is called
Xiaomi passive BLE monitor sensor platform
in HACS.

OK got it installed struggling with getting key using stream app