Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soocas.toothbrush.m1s support #319

Closed
8times4 opened this issue Apr 5, 2021 · 13 comments
Closed

soocas.toothbrush.m1s support #319

8times4 opened this issue Apr 5, 2021 · 13 comments
Labels
new sensor Request for a new sensor

Comments

@8times4
Copy link

8times4 commented Apr 5, 2021

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

@Ernst79
Copy link
Collaborator

Ernst79 commented Apr 6, 2021

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.

@Ernst79
Copy link
Collaborator

Ernst79 commented Apr 8, 2021

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

@Ernst79
Copy link
Collaborator

Ernst79 commented Apr 29, 2021

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.

@ckmarkhsu
Copy link

ckmarkhsu commented May 31, 2021

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

@Ernst79
Copy link
Collaborator

Ernst79 commented May 31, 2021

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

@ckmarkhsu
Copy link

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 ^^"?

@Ernst79
Copy link
Collaborator

Ernst79 commented May 31, 2021

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

@ckmarkhsu
Copy link

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

Thanks!

@ckmarkhsu
Copy link

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.

@Ernst79
Copy link
Collaborator

Ernst79 commented Jun 1, 2021

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.

@Ernst79
Copy link
Collaborator

Ernst79 commented Jun 4, 2021

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

@Ernst79
Copy link
Collaborator

Ernst79 commented Jun 4, 2021

@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.

@Ernst79
Copy link
Collaborator

Ernst79 commented Sep 5, 2021

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.

@Ernst79 Ernst79 closed this as completed Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new sensor Request for a new sensor
Projects
None yet
Development

No branches or pull requests

3 participants