Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

It can be frustrating…(took me a few hours to nail it). If HTTPS is there, so is the bind key…assuming the MiHope pairing went well.
I suggest you try again. Get a few minutes worth of HAR file and export them ALL…there are more than plenty there. Wish I could find a ‘select all’ option.

Ok thanks for your extremely fast answer !
Ok that’s what I did.

Thanks also for you quick answer.

Ok I will try again. (I tried 4-5 times already…)

Yes the pairing went well on the Mi home.

Any suggestion for the HAR viewer to use ? Is there a better alternative than Charles ?

@Magalex Further update…
All working well. I have read on numerous forums that the RPI3 has a lousy BT adapter - well, I beg to differ.
I live in a split level house of conrete construction.
LY2 is ca 8 meters away; same level but behind 2 brick walls.
LY1 is ca 10m away on the lower level (1 conrete slab) plus 2 brick walls.
I have yet to see a missed signal or ‘Unvailable’ on HA (that only happens after HA restart until the first polling interval).
The passive component is a very clever idea and in hindsight, the frustration of the design change on account of the LY, in my opinion, has actually led to a better and more ‘green’ solution.
God bless you, droog! :smiley:

PS: Ordered 4 more LYs.

1 Like

I think that the problems with bluetooth on raspberry pi in most cases are connected with poor power supply (in terms of the power ability and its “purity”) and not very good design in terms of electromagnetic compatibility (adding devices like SSDs greatly spoils the picture). So much depends on the individual characteristics of each installation. Your result pleases, yes.

First and important, you MUST install HACS to be able to read LYWSD03MMC sensor because this intergration is different than the original intergration.

At first, I have a problem finding bind_key, too. Therefore, I wrote another instruction in iOS. This instruction is for LYWSD03MMC sensor. I don’t know the other sensors are different or not.

  1. Open Stream -> HTTPS Sniffing -> CA Install. Then you will be directed to browser to download VPN profile.

  2. Go to General -> Profile -> Stream Generated CA… -> Install the VPN profile

  3. After installing VPN profile.
    Open Stream -> HTTPS Sniffing -> hit trust CA in settings

  4. General -> About -> Certificate Trust Settings -> tick green on Stream Generated CA…

  5. Logged in to MiHome and open Stream.
    Then hit “Sniff now”.
    Immediately go to MiHome and add LYWSD03MMC sensor.
    Waiting for the app to read Temperature and Humidity.
    Then close MiHome app. Go back to Stream and click “Stop Sniffing “

  6. Now go to sniff history and search for keyword “bltbind”. Will see file

“POST https://api.io.mi.com/app/device/bltbind”

If you don’t see that file, go back to step 3 to check whether the CA was trusted or not.
You can click Edit -> Export HAR

Then use Charles Proxy on laptop to see HAR file.
Below is other way to find bind_key inside Stream app (if you don’t want to install more software to laptop).

  1. Click on that file -> Request -> “Preview Form” at bottom -> Format -> Decode -> find “bind_key”

  2. After finding bind_key, then add it to Configuration.yaml

  3. Stop HA in Server management. Then, unplug and plug back power source. HA will be start working in about 10 minutes

  4. Wait about 10 more minutes, you will see the sensor entities in Entities or States tab in HA.
    Batteries level sensor will be showed up after an hour

3 Likes

I am running home assistant on a Synology without Bluetooth. I got an Raspberry Pi and some ESP32 modules. Is it somehow possible to use this component also with the Bluetooth of my PI or ESP32? How to realize the connection between home assistant and the Bluetooth receiver?

Hi, I am using LYWSD03MMC sensors with encryptors as described above.
After adding 5th sensor my RPI3 HASSIO started to crash (no web gui/but can access files remotely).
Removing any of the 5 devices solves the problem.

Has anyone faced similar situation? Any suggestions?

@fitim our FAQ has a mention of methods appropriate to your situation. But the simplest thing in your case would be to use an external USB-BT dongle.

ESP32 has its own implementation of passive data reception from BT sensors, but there the list of supported sensors is somewhat smaller.

@dimaf Do you have the opportunity to see the HA log during the occurrence of a problem?

Hi. I’ve used your mitemp_plugin since september, and it worked great for me. it stopped working the other day, i think after some hcitool update.

With logging enabled, HASS spits out

2020-04-02 10:45:54 DEBUG (SyncWorker_7) [custom_components.mitemp_bt.sensor] Finished. Parsed: 0 hci events, 0 xiaomi devices.

ive moved my temp sensor (LYWSDCGQ) next to my board. lescan does find it. any idea what i can do to fix it?

tanks in advance

@Magalex
Thanks for the reply - are you referring to “home-assistant. log” - it doesn’t indicate anything special. just stops adding new info.

Same problem, I was going crazy knowing that it could be … I have HA core, raspberry pi 4 4gb and raspbian / docker / portainer, integrated bluetooth and 4 thermometers LYWSD03MMC … after 24h it saturates HA and it doesn’t work for me ( if I look at the CPU is at 100%) restarting HA solves the problem for 24H … and it happens again.

Recently, the bluez package was updated. The only thing I did in connection with this was to reboot the host. I did not notice any negative effects because of this update.

If you have not read it, then read our FAQ - it summarizes everything that we had to deal with. Make sure the status of the hci interface is UP (hciconfig cmd). Make sure that other bluetooth components do not enabled. Look carefully at the system logs. In general, more information is needed…

what else could i look at? hcitool lescan works, the python root access thingy works… i only have one bluetooth adapter, hci0, and its only being used by hass…

@roberdlv @dimaf
So far, I have not received feedback on this behavior of the system. You are the first. At the moment, I have no idea about the reasons for this. The only thing that affects the number of sensors is the load on the computing resources (component need to sort through more hci-events). Failure with increased load (in the case of raspberry) may be due to overheating or poor powering. I monitor the resource consumption of my component, and I do not see any signs of a memory leak in the current version (my data comes from three bt-interfaces and five sensors, but only two of them are LYWSD03). In the near future I will try to find some more LYWSD03 somewhere and load with them my raspberry pi 3b with Hassio).

As I said above, carefully review the system log (syslog). Pay attention to the time period corresponding to the stop of data reception.
A number of events equal to zero indicates problems in the operation of the bluetooth subsystem. I consider the conflict with another component such as bluetooth_tracker or other system utilities unlikely, because even then these events should be more than zero if my memory serves me right.
You should also not discard the power problem, because the failure can be at the hardware level (too many users in the case of raspberry pi solved their problems by replacing the power supply and cable).

@roberdlv @dimaf in continuation of my previous post

My test system:

Raspberry Pi 3b+, Hassio 32bit image: HassOS 3.12, Home Assistant 0.107.7

Duracell 3A power supply, high quality microusb cable (I don’t remember exactly the brand/model).

LYWSD03MMC: 4 sensors
LYWSDCGQ: 3 sensors
MiFlora: 1 sensor

Configuration:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor:
  - platform: mitemp_bt
    rounding: False
    period: 60
    log_spikes: True
    batt_entities: True
    hci_interface:
      - 0
    encryptors:
      "A4:C1:38:2F:87:6B": "217C568CF5D22808D120181502D84C1B"
      "A4:C1:38:D1:6A:8D": "C99D2313182473B38A01086FEBF781BD"
      "A4:C1:38:E6:5C:E7": "DAE14A7A1F620A18A8D842D642A14E92"
      "A4:C1:38:BD:42:D0": "78430FD59BAABA433F4A7FBDB4179048"
      
    report_unknown: True

  - platform: rpi_power
    text_state: true

  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /home
      - type: memory_use_percent
      - type: load_1m
      - type: load_5m
      - type: load_15m
      - type: processor_use

  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'


Some overheating (throttling) is reported (during system startups), but most of the time everything is fine. CPU load and memory consumption on graphs. I’ll wait a week, and update this post.

UPD. Added fifth LYWSD03MMC, screenshot updated.

Update since 10 days: everything works well, changing the period from 1 minute to 10 did not have a noticeable effect on the system load.

image

I continue with the problem, if I remove the sensors the system works perfect 4% of use all the time.

If I activate sensors, it works correctly at first and gradually increases and increases the percentage of use of the cpu until HA breaks and cannot be entered, if you restart HA it works correctly again or else if you disable bluetooth, HA it works again.

I also use a docker of this for my xiaomi scale and it is also bluetooth, this worked perfectly before putting the sensors, but I do not know if it creates any conflict with them. https://github.com/lolouk44/xiaomi_mi_scale