Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

So I made it work. LYWSD03MMC with custom and original firmware works at the same time (if you have 2 different sensors). I had to make some changes in sensor.py:

image

Just comment away the adv_index and add the rest of the code. I dont know how to submit the code to the developer to include it to github if they want to.

Hi everybody,

I managed to remove the need for encryption keys and , data in HA are updated every 10 sec instead of every 10 min.
Here is how I did:

  • connect to LYWSD03MMC through the Telink Flasher, https://atc1441.github.io/TelinkFlasher.html
    (Works only from Android mobile or Chrome from a newer PC with BLE support, not from iPhone)
  • modified the Telink custom firmware (changed device type to LYWSDCGQ that sends data without encryption, set the default advertising mode to ā€œMI Likeā€ and default advertising interval to 10 sec )
  • Flashed the customized custom firmware to LYWSD03MMC
  • modified sensor.py commenting these two checks:
    #if adv_index == -1:
        # return None
    # check for BTLE msg size
    msg_length = data[2] + 3
    if msg_length != len(data):
        return None
    # check for MAC presence in message and in service data
    xiaomi_mac_reversed = data[xiaomi_index + 8:xiaomi_index + 14]
    source_mac_reversed = data[adv_index - 7:adv_index - 1]
    #if xiaomi_mac_reversed != source_mac_reversed:
    #   return None
  • removed the encryption section in configuration.yaml
  • added the mac address to the whilelist

It works perfectly and I am very pleased with the result.

Please let men know if anybody is interested in this aproach and need any help.

Hi, tried to make the same edits but the code looks abit different. can you take a look?

# check for no BR/EDR + LE General discoverable mode flags
adv_index1 = data.find(b"\x02\x01\x06", 14, 17)
adv_index2 = data.find(b"\x15\x16\x95", 14, 17)
if adv_index1 == -1 and adv_index2 == -1:
    return None
elif adv_index1 != -1:
     adv_index = adv_index1
elif adv_index2 != -1:
    adv_index = adv_index2
# check for BTLE msg size
msg_length = data[2] + 3
if msg_length != len(data):
    return None
# check for MAC presence in message and in service data
xiaomi_mac_reversed = data[xiaomi_index + 8:xiaomi_index + 14]
source_mac_reversed = data[adv_index - 7:adv_index - 1]
if xiaomi_mac_reversed != source_mac_reversed:
    return None

Line #4 looks different then yours. what should I change exactly?
thanks,

Hi,

I can see you have version 6.13. I have been using version 6,12, thatā€™s why it looks different.

Iā€™ll try 6.13 that actually should support Telink custom firmware by default.

Iā€™ll look into the new version and get back to you

1 Like

Hi Omer,

I upgraded to the latest version like you, and it seems to work without any further changes needed to sensor.py as it is designed to support the Telink custom firmware.

Thatā€™s great :slight_smile:

Oh thatā€™s great news, so just change the yaml as such?:

  - platform: mitemp_bt
    whitelist:
      - 'A4:C1:38:7B:BB:B3'

Still not seeing the device, Flashed it but canā€™t get the info even when using https://atc1441.github.io/TelinkFlasher.html. probably other problem that doesnā€™t have to do with HA directly (getting ā€œDetected custom Firmwareā€ but no info passed). Iā€™ve opened an issue about this on the developers project page.

thanks again.

So,
With the latest version of mitemp_bt (6.13) that supports the Telink custom firmware, you only need to

  • change default advertising mode and advertising interval in the Telink custom firmware, if you want more often updates.
  • and move the mac address in configuration.yaml from the encryptors section to the whitelist section.

This is getting much better and quite easy to setup

Thanks @Magalex for this improvement

1 Like

6.13 was released yesterday, which adds support for the custom firmware, as you guys already noticed. No need to change the sensor.py code yourself. As I understood, you can remove the encryptor key, when using the custom firmware.

Credits should be given to @karto (at least I assume he is the same as benkarro on github), based on the code in his post here in the forum. Iā€™ve used his code in the 6.13 release. Instructions are also updated with links to the custom firmware.

1 Like

Thanks for the shoutout @Ernst :slight_smile:

Hi Aleksey,

I am facing same problem, my log is filled with this error

Ā“Ā“Ā“

2020-10-14 14:20:57 ERROR (Thread-84) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:21:12 ERROR (Thread-85) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:21:27 ERROR (Thread-86) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:21:42 ERROR (Thread-87) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:21:57 ERROR (Thread-88) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:22:12 ERROR (Thread-89) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:22:27 ERROR (Thread-90) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:22:42 ERROR (Thread-91) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:22:57 ERROR (Thread-92) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:23:12 ERROR (Thread-93) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

2020-10-14 14:23:27 ERROR (Thread-94) [custom_components.custom_mitemp_bt.sensor] HCIdump thread: OS error: [Errno 19] error while attempting to bind on interface 0: No such device

Ā“Ā“Ā“

I am quite sure this is not a HW issue as i changed to another pi and i still get the same error

I donā€™t know exactly when this started but I discovered it today.

I am running the beta version of HASSIO on a Raspberry Pi. Here are the system details:

Ā“Ā“Ā“

arch armv7l
chassis embedded
dev false
docker true
docker_version 19.03.11
hassio true
host_os HassOS 4.14
installation_type Home Assistant OS
os_name Linux
os_version 4.19.127-v7
python_version 3.8.5
supervisor 247
timezone Europe/Copenhagen
version 0.116.2
virtualenv false

Ā“Ā“Ā“
and i am running the latest version of your mitemp_bt component that supports custom Telink firmware

Hope you can help

I think I am in the same situation as @ghassan.

Migrating from a Pi4 (supervised install) to HassOS on Proxmox. It seems hci is not installed, instead it is using bluetoothctl.

So a bluetoothctl scan results in some mac codes;

Can these be used? Does the tool need other changes to work?

[edit]
It seems to have just started. Not made any changes other than the scan mentioned above, deleting the integration and starting to configure the builtin integration, several reboots/restarts and I suddenly noticed hci events in the log. Reinstalled this integration and seems to be working.

Bit odd really. Seems it is impossible to determine which bluetooth receivers are connected to the system and their hci numbers.

Underneath the logger config I have

logger:
  default: info
  logs:
    custom_components.mitemp_bt.sensor: debug

that tells me what is going on.

HTH

I rolled back to version 4.13 by leaving the beta channel and the error disappeared. :slight_smile:

@Magalex you should look into compatibility with version 4.14 so that it doesnā€™t break it for every body when it is released officially

Thanks
/Ghassan

Would this sensor be able to work with your component?

Iā€™ve released a new version 0.7.2, which is based on 0.6.13 and has a new option to apply sensor names via configuration.yaml.

0.7.2 release notes

  • Added option to configure sensor names in configuration.yaml, see the sensor_names option. Note that when you use or change this option, it will create new entities. This means that you will have to update your lovelace cards, automations and/or scripts that use the entity_id . Note that you can still rename sensors afterwards from the UI. After the change, you can manually delete the old entities from the Developer Tools.
  • Added the mac address to the attributes of the sensors
  • New sensors will be named according to a new convention: mi_sensortype_mac (e.g. sensor.mi_temperature_A4C1382F86C) (default) or mi_sensortype_sensor_name (e.g. sensor.mi_temperature_livingroom) (with sensor_names option). Your current sensors with the short naming (e.g. mi_t_A4C1382F86C ) or manually modified names wonā€™t be renamed, unless you use the sensor_names option.

Probably not, it isnā€™t an xiaomi device, so changes are small that the component talks the same language as the component is expecting.

Hello, I canā€™t get this integration with HACS.

Hereā€™s my config file:

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:
              '24:FC:E5:5E:0F:AF': '217C568CF5D22808DA20181502D84C1B'
    report_unknown: False
    whitelist: False

Iā€™m using custom firmware (atc) and I canā€™t find the device in Mi Home app, do I have to link it ?

LYWSD03MMC device

ty for any help

If you have the custom firmware, there is no need to use an encryption key, I think

Same here:
Logger: custom_components.mitemp_bt.sensor
Source: custom_components/mitemp_bt/sensor.py:139
Integration: mitemp_bt (documentation)
First occurred: 20:45:33 (3 occurrences)
Last logged: 20:47:34

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

There is an issue opened here

You have to put random key otherwise config file is not valid for me