custom-components / ble_monitor

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

Add support for Xiaomi Mi Flood Detector - SJWS01LM #181

Closed pasolobo2 closed 3 years ago

pasolobo2 commented 3 years ago

Hi.

I need support for the new Xiaomi Flood Detector - SJWS01LM

log.txt photo_2020-12-02_18-27-28 photo_2020-12-02_18-27-43

Detect water leaks.

Thanks!!!

Magalex2x14 commented 3 years ago

Thanks, I'll take a look tomorrow.

Magalex2x14 commented 3 years ago

@pasolobo2 unfortunately, the dump you posted does not contain a single package with useful data. Please make sure that the sensor is added to the official application (MiHome), and that this application is closed while receiving the log (there is no active connection to the sensor), and try again to capture data.

pasolobo2 commented 3 years ago

Hello again.

I did what you said. Here is the news log. I wait its correct. log.txt

Thanks

Magalex2x14 commented 3 years ago

@pasolobo2 thank you. We are dealing with another encryptor. In order to continue working on its support, you need to get the encryption key anyway. This can be done using one of the methods described in our FAQ. The simplest is the MiHome mod by vevs. Consider the fact that after re-adding the sensor to the application, you will need to get the HA log again. There are two options here:

  1. You give me a key and a new log
  2. You tell me which version of the component you are using, I make a new code based on it, you add the key to the component's configuration, and write a new log in which the messages will already be decrypted.

The first option is safer and faster. You can then change the key (by deleting and adding the sensor to MiHome again), if this is important to you.

pasolobo2 commented 3 years ago

Hello again.

I send you the key and the new logs.

log.txt

Thanks

pasolobo2 commented 3 years ago

Sorry... the key. key.txt

Magalex2x14 commented 3 years ago

Received. I'll take a look a little later.

Ernst79 commented 3 years ago

@Magalex2x14 Can you explain how you decrypt the advertisement. I can add this device, but I don’t understand how to decrypt the messages.

Ernst79 commented 3 years ago

@pasolobo2 There is no bind key in your key.txt file. The token mentioned in key.txt is not the key we need. Please follow the instructions here to find the bind key. It should have 32 characters.

Magalex2x14 commented 3 years ago

@Ernst79 I had an idea to change the parser code so that, in the case of an unknown device, logging would occur after decryption (if the packet is encrypted), but my hands have not yet reached... Also, I think, we can add a warning about the need to configure the key in case the data is encrypted and the key is not in the configuration.

In general, I just took the actual parser code and constants and added them to a small program that parses the text file with dump. Unfortunately, I am now out of place, and I do not have it at hand. I will return to this in early January.

pasolobo2 commented 3 years ago

Hello and happy new year !!!....

I hope it is correct now.

pairings.txt log.txt

Ernst79 commented 3 years ago

Yes, that's the correct bind_key. I'll look into it.

Ernst79 commented 3 years ago

I have created the SJWS01LM branch, which adds support for your sensor.

I used the Moisture type Binary Sensor, so it should show wet/dry as state.

Please copy the code from __init__.py, const.py and binary_sensor.py to your config/custom_components/ble_monitor folder to test. You will need to set the encryption_key in your configuration as well.

I haven't found a battery reading but I assumed it does send battery info, given your screenshot above.

@Magalex2x14 I managed to do the decryption, so no need to send your script. However, I have two questions.

Ernst79 commented 3 years ago

@pasolobo2 Did you had a change to try it?

pasolobo2 commented 3 years ago

Hi. I made the change in ble monitor, added the encryption_key in the config.yaml I restarted my HA but I don't see the changes. What should i see?

ble_monitor:
  hci_interface: 0
  discovery: True
  active_scan: False
  report_unknown: False
  batt_entities: False
  rounding: True
  decimals: 1
  period: 60
  log_spikes: False
  use_median: False
  restore_state: False
  devices:
    - mac: '54:EF:44:E0:27:BC'
      name: 'Agua'
      encryption_key: '255e6cabb39b2eddd0de992b9fee2bf2'

I dont see anything on the logs

logger:
  default: info
  logs:
    custom_componets.ble_monitor: debug
Ernst79 commented 3 years ago

Aren't there any lines in the logs about ble_monitor? Please show all log output (not only errors, but all lines), by clicking on this button at the bottom of the log.

image

Isn't there a device visible under integrations --> ble_monitor --> devices? If it works, a device should be shown which is named with your MAC address. The sensor should show up as binary_sensor.ble_moisture_54EF44E027BC

pasolobo2 commented 3 years ago

Hi.

I made the change.

b'\x63\x08': ("SJWS01LM", True),

b'c\x08': ("SJWS01LM", True),

I send b c x08.txt b x63 x08.txt

you the logs with the two options.

Ernst79 commented 3 years ago

It looks like something is wrong on this line.

Line 512: File "/config/custom_components/ble_monitor/binary_sensor.py", line 113, in async_run

Do you have the previous and/or next line in the log. I think something is missing around these lines, which indicates what is wrong.

pasolobo2 commented 3 years ago

Here is ...

Traceback (most recent call last): File "/config/custom_components/ble_monitor/binary_sensor.py", line 113, in async_run sw_i, op_i, l_i, b_i = MMTS_DICT[sensortype][1] ValueError: too many values to unpack (expected 4)

I send you a zip of my component... ble_monitor.zip

Ernst79 commented 3 years ago

You also had to copy __init__.py and binary_sensor.py, You now still have the old files (at least binary_sensors.py seems to be the old version in your zip file (and explains the error). Could you try again?

pasolobo2 commented 3 years ago

Hi.

It´s work. I send you the logs.

log.txt

Ernst79 commented 3 years ago

Great, thanks. I will prepare a beta release a.s.a.p.

Ernst79 commented 3 years ago

Released as 0.9.5-beta.

Can you check one thing. Does it report battery state? (and at what interval).

pasolobo2 commented 3 years ago

Sorry, yesterday my HA installation stopped working. I must reinstall it. Also, my PC started doing weird things. I have to check. I will take a few days.

alessocci commented 1 year ago

Follow

benkwyan commented 1 year ago

Hello and happy new year !!!....

I hope it is correct now.

pairings.txt log.txt

How do you find the bindkey for xiaomi Flood Detector?

Ernst79 commented 1 year ago

Check the faq

https://custom-components.github.io/ble_monitor/faq#how-to-get-the-mibeacon-v4v5-encryption-key