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

[New Sensor]: qushui.pillow.mj02 #1061

Closed yangqian closed 1 year ago

yangqian commented 1 year ago

Sensor Description

qushui.pillow.mj02 Xiaomi Smart Pillow

Additional information

https://home.miot-spec.com/spec/qushui.pillow.mj02

Most probable meaning for first ADV: In bed Most probable meaning for second ADV: out of bed Most probable meaning for third ADV: Double click Ble key: 13f072b8c8469f54ac2c333ee746d771

BLE advertisements

2022-12-08 21:00:13.444 INFO (Thread-137) [custom_components.ble_monitor.ble_parser.xiaomi] BLE ADV from UNKNOWN Xiaomi device: RSSI: -74, MAC: CC:B5:D1:D6:37:7B, ADV: 191695fe5859db20157b37d6d1b5cc63b97eec020000a615ec10

2022-12-08 21:05:05.456 INFO (Thread-137) [custom_components.ble_monitor.ble_parser.xiaomi] BLE ADV from UNKNOWN Xiaomi device: RSSI: -68, MAC: CC:B5:D1:D6:37:7B, ADV: 191695fe5859db20177b37d6d1b5cc86f2d4ce0200002b6ba459

2022-12-08 21:11:00.444 INFO (Thread-137) [custom_components.ble_monitor.ble_parser.xiaomi] BLE ADV from UNKNOWN Xiaomi device: RSSI: -71, MAC: CC:B5:D1:D6:37:7B, ADV: 0e1695fe1059db20227b37d6d1b5cc
Ernst79 commented 1 year ago

Thanks, looks possible to add this.

However, when looking at the link you gave, the meaning should be

image

I decoded the messages, e.g. the second gives 165a0102

165a = measument type (sleeping mode I assume) 01 = length of data = 1 02 = the state

Assuming that it is the sleeping mode 1st message data: 165a 01 01: state: 01 --> Sleep 2nd message obj_id 165a 01 02: state: 02 --> Double Click ????

BTW. 3rd message = empty message

I think there should also be battery data and "snorring" boolean data.

Can you get some more advertisements, e.g. when snorring?

yangqian commented 1 year ago

Thanks. OK. I'll try to get more data. ADV: 191695fe5859db20177b37d6d1b5cc86f2d4ce0200002b6ba459

2nd message obj_id 165a 01 02: state: 02 --> Double Click ????

This should probably be OutofBed.

We may need to look at this:

ble

I also noticed the following two lines.

2022-12-08 20:36:34.948 INFO (Thread-137) [custom_components.ble_monitor.ble_parser.xiaomi] BLE ADV from UNKNOWN Xiaomi device: RSSI: -79, MAC: CC:B5:D1:D6:37:7B, ADV: 191695fe5859db200a7b37d6d1b5cce79fcf95020000a0e4f773
2022-12-08 20:46:35.210 INFO (Thread-137) [custom_components.ble_monitor.ble_parser.xiaomi] BLE ADV from UNKNOWN Xiaomi device: RSSI: -64, MAC: CC:B5:D1:D6:37:7B, ADV: 191695fe5859db200d7b37d6d1b5cc581773a002000001cb9cc7

Could this two be battery? The battery was 75 and dropped to 74. It may be a little bit hard to trigger the snoring state.

I'll hopefully provide more updates.

Ernst79 commented 1 year ago

in out of bed 191695fe5859db20177b37d6d1b5cc86f2d4ce0200002b6ba459 is indeed returning state 2 (out of bed). 165a0102

battery Yes, can very well be. The first message is giving 0354014c

0354 = measurement type battery 01 = length of data = 1 4c = the state = 76

The 2nd message is returning 4b instead of 4c, so, 75%.

So, yes, I agree that this is the battery (although 1% difference with your values).

I will add this a.s.a.p., such that you can test it. If you catch some "snorring" messages, let me know.

yangqian commented 1 year ago

Thanks for the prompt reply.

I got a new ADV which is most likely double click: 191695fe5859db20b57b37d6d1b5cceeac2cf2030000af66e6b0

rezmus commented 1 year ago

qushui.pillow.mj02 (8411) - Xiaomi Smart Pillow

eid 20496, time 600, delta 1 eid 20497, time 86400, delta 1 eid 22017, time 0, delta 0 eid 21507, time 600, delta 1 eid 23062, time 0, delta 0

prop.4.1017 (Snore State) bool = eid 20497 (0x5011) prop.4.1016 (Sleep State) uint8 = eid 20496 (0x5010) prop.5.1003 (Battery Level) uint8 = eid 21507 (0x5403) event.5.1001 (Low Battery) = eid 22017 (0x5601) event.6.1022 (Customized Event-1) = eid 23062 (0x5a16)

Snoring (prop.4.1017 true) In bed (event.6.1022 {"sub_props":{"attr":[{"key":"prop.qushui.pillow.mj02.6.1","value":1,"value_type":1}],"express":0}}) Off bed (event.6.1022 {"sub_props":{"attr":[{"key":"prop.qushui.pillow.mj02.6.1","value":2,"value_type":1}],"express":0}}) Falling asleep (prop.4.1016 1) Double press the controller (event.6.1022 {"sub_props":{"attr":[{"key":"prop.qushui.pillow.mj02.6.1","value":3,"value_type":1}],"express":0}})

one more model from same vendor.

qushui.pillow.p2 (6371) - 8h intelligent sleeping natural latex pillow x

eid 18448, time 30, delta 0 eid 18449, time 30, delta 0 eid 19990, time 0, delta 0 eid 19991, time 0, delta 0

prop.2.1017 (Snore State) bool = eid 18449 (0x4811) prop.2.1016 (Sleep State) uint8 = eid 18448 (0x4810) event.3.1022 (Customized Event-1) = eid 19990 (0x4e16) event.3.1023 (Customized Event-2) = eid 19991 (0x4e17)

Snore (prop.2.1017 true) Fall asleep (prop.2.1016 1) Out of bed (event.3.1023) Be in bed (event.3.1022) Button double click (prop.2.1016 2)

Ernst79 commented 1 year ago

Thanks, I now have all the info I need. Will add it in the coming week.

Ernst79 commented 1 year ago

Can anyone find the xiaomi product number/code?

qushui.pillow.mj02 = MJZNZ018H qushui.pillow.p2 = ????

yangqian commented 1 year ago

qushui.pillow.p2 = ????

according to http://www.8hsleep.com/product.html?id=213 it is ZX1

model
yangqian commented 1 year ago

I caught a fall into sleep ADV: 191695fe5859db203f7b37d6d1b5ccba188ae6060000e1a9cb97 which is 10500101 once decrypted. Seems to agree with

prop.4.1016 (Sleep State) uint8 = eid 20496 (0x5010)

Ernst79 commented 1 year ago

I have released a 10.9.0-beta version. Can you check if it all works with this beta? You will have to enable Beta releases for BLE monitor in HACS, before you see this update.

I have added 5 sensors for HA

Note. The typo in snorring --> snoring will be fixed in the next release.

yangqian commented 1 year ago

I received an error:

Traceback (most recent call last):
  File "/ble_monitor/sensor.py", line 211, in async_run
    sensors = await async_add_sensor(
  File "/ble_monitor/sensor.py", line 152, in async_add_sensor
    description = [item for item in SENSOR_TYPES if item.key is measurement][0]
IndexError: list index out of range

The

Ernst79 commented 1 year ago

Ok, thanks for testing, you can return to the latest stable version for now, I’ll look into the error

yangqian commented 1 year ago

I suspect the button switch is not defined yet. Should one use button or one btn switch?

Ernst79 commented 1 year ago

Yes, I think you are right. Try 10.9.1-beta, I changed it to a button sensor.

yangqian commented 1 year ago

Right now, the bed occupancy, double click, battery works well.

Ernst79 commented 1 year ago

Ok, thanks, I assume you haven't tested the snoring and sleeping sensor? Or are you saying that these don't work? Let's wait a night to see if they work

yangqian commented 1 year ago

Ok, thanks, I assume you haven't tested the snoring and sleeping sensor?

Yes. I should be able to test the sleeping sensor tonight. I am not sure how to trigger the snore sensor though...

Ernst79 commented 1 year ago

I'm pretty confident that it will work, as I just followed the format as provided by @rezmus

I'm only a bit confused for the 8h intelligent sleeping natural latex pillow x (not the one you have), this one has two eid's 19990 and 19991 for the same property (in/out of bed). not sure how they exactly report their state. I assumed if eid 19990 == 1 than in bed, if eid 19991 == 1 than out of bed. But that is just my interpretation.

I also found this in the description of miot-spec.

    {"iid":1,"type":"urn:miot-spec-v2:property:customized-argument-1:0000012D:qushui-p2:1","description":"Customized Argument-1","format":"uint8","access":[],"value-list":[
        {"value":1,"description":"InBed"},
        {"value":2,"description":"OutOfBed"},
        {"value":3,"description":"Dblclick"}]}],

Not sure to which eid this belongs.

yangqian commented 1 year ago

The sleeping sensor works well.

Ernst79 commented 1 year ago

Added in 10.9.1 as final