custom-components / ble_monitor

BLE monitor for passive BLE sensors
https://community.home-assistant.io/t/passive-ble-monitor-integration/
MIT License
1.89k stars 243 forks source link

Unable to connect LYWSD03MMC #83

Closed fjvd closed 3 years ago

fjvd commented 4 years ago

I have HA running on Raspberry Pi OS and want to connect to LYWSD03MMC devices. It seems somehow it can't connect:

2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] Starting 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s). 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] HCIdump thread: Init 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0 2020-06-11 12:44:48 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Run 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1 2020-06-11 12:44:48 INFO (SyncWorker_12) [custom_components.mitemp_bt.sensor] Attention! Option report_unknown is enabled, be ready for a huge output... 2020-06-11 12:44:48 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] 1 encryptors mac:key pairs loaded. 2020-06-11 12:44:48 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] 0 whitelist item(s) loaded. 2020-06-11 12:44:48 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected 2020-06-11 12:44:48 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop 2020-06-11 12:44:49 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] update_ble called 2020-06-11 12:44:50 DEBUG (SyncWorker_12) [custom_components.mitemp_bt.sensor] First run, skip parsing. 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] update_ble called 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Discovering Bluetooth LE devices 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Time to analyze... 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Getting data from HCIdump thread 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] HCIdump thread: joining 2020-06-11 12:45:51 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: main event_loop stopped, finishing 2020-06-11 12:45:51 DEBUG (Thread-2) [custom_components.mitemp_bt.sensor] HCIdump thread: Run finished 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] HCIdump thread: joined 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s). 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] HCIdump thread: Init 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Starting HCIdump thread for hci0 2020-06-11 12:45:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Run 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] HCIdump threads count = 1 2020-06-11 12:45:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection 2020-06-11 12:45:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected 2020-06-11 12:45:51 DEBUG (Thread-18) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop 2020-06-11 12:45:51 DEBUG (SyncWorker_10) [custom_components.mitemp_bt.sensor] Finished. Parsed: 1315 hci events, 0 xiaomi devices.

Configuration:

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:E1:xx:xx': '39D7A24A719D7F65556B30CC70EAxxxx'
    report_unknown: True`

In the hcitrace.txt file is see the sensor showing up many times:

HCI Event: LE Meta Event (0x3e) plen 33 #18 [hci0] 1.766815 LE Advertising Report (0x02) Num reports: 1 Event type: Connectable undirected - ADV_IND (0x00) Address type: Public (0x00) Address: A4:C1:38:E1:xx:xx(Telink Semiconductor (Taipei) Co. Ltd.) Data length: 21 Flags: 0x06 LE General Discoverable Mode BR/EDR Not Supported Service Data (UUID 0xfe95): 30585b050141dde138c1a4280100`

Python:

/usr/bin/python3.7 = cap_net_admin,cap_net_raw+eip`

System:

arch | armv7l dev | false docker | false hassio | false installation_type | Home Assistant Core in a Python Virtual Environment os_name | Linux os_version | 4.19.118-v7l+ python_version | 3.7.3 timezone | Europe/Brussels version | 0.110.6 virtualenv | true

Any ideas?

Magalex2x14 commented 4 years ago

Hello!

Are you sure the relevant entities did not appear in HA? This sensor sends messages quite rarely (about once every 10 minutes), so you need to look at the log for a longer period. Try to search in the entities list by the text mi_.

Patresss commented 4 years ago

Hi, I have the same problem

fjvd commented 4 years ago

Did some more testing today, added a second sensor, stopped HA, Shutdown PI and booted everything. Unfortunately no luck. I do see errors now:

2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] Decryption failed for A4C138E1xxxx, decrypted payload is None 2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] Decryption failed: MAC check failed 2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] token: 14000f71 2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] nonce: 41dde138c1a45b0511000000 2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] encrypted_payload: c66034728200000014000f71 2020-06-25 13:37:07 ERROR (SyncWorker_11) [custom_components.mitemp_bt.sensor] cipherpayload: c660347282

I've double checked the bindkey, this is correct.

cheese202 commented 4 years ago

The same isuue here. Please help someone. Tried everything even another bluetooth dongle. Bluetooth working fine.

2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Starting 2020-08-27 18:11:36 INFO (SyncWorker_1) [custom_components.mitemp_bt.sensor] Attention! Option report_unknown is enabled, be ready for a huge output... 2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] 2 encryptors mac:key pairs loaded. 2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] 0 whitelist item(s) loaded. 2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] Spawning HCIdump thread(s). 2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: Init 2020-08-27 18:11:36 DEBUG (SyncWorker_1) [custom_components.mitemp_bt.sensor] HCIdump thread: Init finished 2020-08-27 18:11:36 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Run 2020-08-27 18:11:36 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Connection to hci0 2020-08-27 18:11:36 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: Connected to hci0 2020-08-27 18:11:36 DEBUG (Thread-3) [custom_components.mitemp_bt.sensor] HCIdump thread: start main event_loop 2020-08-27 18:12:37 DEBUG (SyncWorker_6) [custom_components.mitemp_bt.sensor] 0 Xiaomi BLE ADV messages processed for 0 xiaomi device(s). 2020-08-27 18:13:37 DEBUG (SyncWorker_6) [custom_components.mitemp_bt.sensor] 0 Xiaomi BLE ADV messages processed for 0 xiaomi device(s).

And lst message i'm getting every minute.

I don't have any sensor in HA. Hardaware seems working fine.

Configuration `sensor:

paperro commented 3 years ago

I'm having the same problem

2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] Decryption failed: MAC check failed 2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] token: bb60xxxx 2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] nonce: 6b6a2a38c1a45b0501000000 2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] encrypted_payload: b8d23abb54000000bb60xxxx 2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] cipherpayload: b8d23axxxx 2020-09-28 11:22:04 ERROR (SyncWorker_25) [custom_components.mitemp_bt.sensor] Decryption failed for A4C1382Axxxx, decrypted payload is None

after that i can see some unknown adv 2020-09-28 12:07:59 INFO (SyncWorker_13) [custom_components.mitemp_bt.sensor] BLE ADV from UNKNOWN: RSSI: -41, MAC: A4C1382Axxxx, ADV: 043e1f020100006b6a2a38c1a4130201060f1695fe30585b16006b6a2a38c1a408d7 2020-09-28 12:08:59 INFO (SyncWorker_20) [custom_components.mitemp_bt.sensor] BLE ADV from UNKNOWN: RSSI: -44, MAC: A4C1382Axxxx, ADV: 043e1f020100006b6a2a38c1a4130201060f1695fe30585b16006b6a2a38c1a408d4 2020-09-28 12:10:00 INFO (SyncWorker_2) [custom_components.mitemp_bt.sensor] BLE ADV from UNKNOWN: RSSI: -41, MAC: A4C1382Axxxx, ADV: 043e1f020100006b6a2a38c1a4130201060f1695fe30585b16006b6a2a38c1a408d7 2020-09-28 12:15:01 INFO (SyncWorker_20) [custom_components.mitemp_bt.sensor] BLE ADV from UNKNOWN: RSSI: -44, MAC: A4C1382Axxx, ADV: 043e1f020100006b6a2a38c1a4130201060f1695fe30585b16006b6a2a38c1a408d4

Im using "homeassistant/raspberrypi3-homeassistant" docker on raspberry pi 3

Ernst79 commented 3 years ago

Sorry for the late response, but @Magalex2x14 is away at the moment. For now, I think the easiest way is to install the custom Telink firmware, which removes the need for the encryptor key. You can also increase the message time.

vdiogo commented 3 years ago

I got the same issue: firstly (about a week) one of my 4 devices, and this weekend the remaining 3 devices stopped reporting

Ernst79 commented 3 years ago

@vdiogo Please check your encryption key again. It sometimes can change (e.g. changing battery).

Magalex2x14 commented 3 years ago

Please let us know if you managed to solve your problems, or do you still need help?

Ernst79 commented 3 years ago

Closing this issue now. Feel free to open an new issue if you still having issues.

vdiogo commented 3 years ago

@vdiogo Please check your encryption key again. It sometimes can change (e.g. changing battery).

Sorry for late answer: encryption key is the same, device merely stopped answering (it happened in 4 devices)

Ernst79 commented 3 years ago

Perhaps connection issues. Try to see if they work when you move them closer.

fjvd commented 3 years ago

Just wanted to let you all know that flashing the mija devices and upgrading homeassistant & python did the trick for me. Thanks for the support, it's awesome!

vdiogo commented 3 years ago

Perhaps connection issues. Try to see if they work when you move them closer.

They worked well for 3-4 months and stopped working all of the sudden. Don't think moving them will make any difference

Ernst79 commented 3 years ago

Did you start using an SSD? They can interfere with the BT signal.

vdiogo commented 3 years ago

Did you start using an SSD? They can interfere with the BT signal.

Yes I did: don't recall exactly when but should have been around the same time. How can I avoid it?

Ernst79 commented 3 years ago

That most likely explains it, SSD turn out to be interfering with the Bluetooth signal (I had the same issue). The FAQ gives a few hints to solve this.

Especially SSD devices are known to affect the Bluetooth reception, try to place your SSD drive as far as possible from your Bluetooth tranceiver.

What you can try is using a long cable for your SSD or using an external Bluetooth adapter, preferable with an USB extension cable. Main goal is to get the SSD as far away as possible compared to the Bluetooth radio.