custom-components/ble_monitor

soocas.toothbrush.m1s support

8times4 opened this issue · 13 comments

Hey!

I really like what you guys did with the ble implementation to HA. Thank you!

I'm checking if it'd be possible to add some support to Xiaomi Toothbrush T500.

I've got some logs via HA:

2021-04-06 01:14:15 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -73, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3132890430115b174371e609b7
2021-04-06 01:14:40 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -56, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890431115b174371e609c8
2021-04-06 01:14:44 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -54, MAC: E67143175B11, ADV: 043e2302010001115b174371e617020106131695fe7130890432115b174371e6090a10013aca
2021-04-06 01:14:47 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -62, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890433115b174371e609c2
2021-04-06 01:15:02 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -35, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890434115b174371e609dd
2021-04-06 01:17:36 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -38, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890435115b174371e609da
2021-04-06 01:17:49 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -41, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890436115b174371e609d7
2021-04-06 01:23:13 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -36, MAC: E67143175B11, ADV: 043e2402010001115b174371e618020106141695fe7130890437115b174371e6091000020003dc
2021-04-06 01:23:16 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -35, MAC: E67143175B11, ADV: 043e1f02010001115b174371e6130201060f1695fe3130890438115b174371e609dd
2021-04-06 01:23:33 INFO (Thread-3) [custom_components.ble_monitor] BLE ADV from UNKNOWN: RSSI: -51, MAC: E67143175B11, ADV: 043e2402010001115b174371e618020106141695fe7130890439115b174371e6091000020004cd

I've also dumped some info here a few weeks ago: Hypfer/Cybele#16

Would you also require a hcidump?

Thank you,
Mark

Hi Mark,

Yes, It's possible to add this device. It's NOT encrypted, so no need to get a key.

I first looked at the 10 lines presented in your post.

  • Short lines contain no data, only RSSI
  • 3rd line: result: 'battery': 58%
  • 8 line: result: 'Toothbrush incident': 0003
  • 10th line: result: 'Toothbrush incident': 0004

'Toothbrush incident' is the google translation of the sensor type 0x0010 on this page with explanation of Xiaomi BLE message format. It's in Chinese, so I had to use google translate. Could you tell me what this sensor can possibly be? I guess it's a setting of the toothbrush, like speed? If not, I can create a (temporary) sensor that just reports the number, which will allow you to figure out which number corresponds to which setting/speed/??. I'll prepare some code for you a.s.a.p.

I've created a first draft in the Xiaomi-toothbrush-T500 branch

To try, first install version 1.5.2 (not 1.6.0), if not already done. After that, overwrite the content of sensor.py, __init__.py, and const.py, with the content of the above mentioned branch.

You will get a battery sensor (if enabled) and a tootbrush mode sensor with a value. Please try to figure out which number corresponds to what. Also leave report_unkown and logging at info level enabled (see below), to see if you get more/different data from the toothbrush. If so, you will get an debug message in the logs that starts with UNKNOWN dataobject from DEVICE:

logger:
  default: warn
  logs:
    custom_components.ble_monitor: info

1.9.0-beta has been released, which adds support for this Toothbrush.

It will create a battery sensor and a toothbrush mode sensor. @markthehipster Could you please test it and report back which state (number) corresponds to what? In the Xiaomi documentation, I can only find
0: Start of brushing
1: End of brushing

But in your messages, there is 3 and 4 as well.

Toothbrush event
first byte - type - 0: start to brush, 1 end of brushing
second byte is optional - score of brushing - 0 to 100 and only appeared when type == 1

so I am wondering it might be meaningless in the log since the first byte is 0

Thanks, I noticed in the messages from @markthehipster that he has first byte = 03 and 04, so I wonder what that means.?

I'm try to decode as following

09 10 00 02 00 03 dc
Capability = 0x09
Obj Id = 0x0010
length = 0x02
event first byte = 00
event secont byte = 03

Or do I misunderstand the spec ^^"?

ah, ok, than I mean the second byte (they often read the bytes reversed in MiBeacon).

So far, I assumed that only the last byte meant something, as I only found 00 03 and 00 04 in the the advertisements of @markthehipster

So, If I understand your right (looking at the last two bytes).

00 xx means start to brush
01 xx means end of brushing

01 16 means end of brushing, score of brushing: 22 (16 in hex is 22 in decimals)

In the adv of @markthehipster we have 00 04
00 would means start of brushing, but what would the 04 means in his message, also score of brushing?

@ckmarkhsu Do you have this toothbrush? Are you able to make a HCIdump and check the byte order, I'm not sure if they should be read reversed or not. If you can't make a HCIdump, you can also use this app Bluetooth LE Scanner

hummm I guess you are right. I do have the toothbrush let me dump the test data and get back to you soon

Thanks!

Quick update

I still don't have very complete log.
Because most BLE scanner on mobile will only record the first ADV and stop recording. However, based on several test data, I found that there will be data like 00 05, 00 06, 00 07, 00 1C, LOL. I have no idea.

My guess it that it an increasing counter, e.g the score of brushing. I can add the first byte to the tooth brush sensor, this will make it easier for you to check both bytes. Will prepare it tonight.

sorry, it takes a little longer. Will try to prepare the version this weekend.

@ckmarkhsu

Went faster than expected.

Please install version 2.7.3, which is the latest final version (not beta). Next copy the content of the following two files into
/custom_components/ble_monitor/sensor.py

https://github.com/custom-components/ble_monitor/blob/toothbrush_test/custom_components/ble_monitor/sensor.py

and /custom_components/ble_monitor/ble_parser/xiaomi.py

https://github.com/custom-components/ble_monitor/blob/toothbrush_test/custom_components/ble_monitor/ble_parser/xiaomi.py

Next do a restart of HA. After the restart it will add two attributes to the sensor, byte 1 and byte 2. Next, try to see how it changes during brushing your teeth.

Fixed this in BLE Monitor 5.1.4. Note that the sensor is removed and replaced with a binary sensor (with some info in the attributes).

After a start, the toothbrush reports a counter (time from start)
After finishing, it reports a score.

Based on info from the Xiaomi Gateway 3 custom integration.