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

LYWSD03MMC not recognized, faulty device? #185

Closed ivanpavlina closed 3 years ago

ivanpavlina commented 3 years ago

Hi,

I bought two LYWSD03MMC sensors, flashed custom firmware through Telink Flasher and one is working great, i get temp/humidity/battery readings as expected but i have a problem with other one.

This is my config:

ble_monitor:
  batt_entities: True
  restore_state: True
  report_unknown: True
  devices:
  - mac: 'A4:C1:38:00:AE:2A'
    name: 'Hallway'
    temperature_unit: C
  - mac: 'A4:C1:38:E1:8C:8D'
    name: 'Livingroom'
    temperature_unit: C

Device with MAC A4:C1:38:00:AE:2A is working good, but A4:C1:38:E1:8C:8D is not getting any values in Hass. I turned on report_unknown, but still there aren't any messages about the 'unknown' device.

I downloaded app BLE Scanner on my phone and i see messages from both devices - This is raw data for mac A4:C1:38:00:AE:2A which is working fine: 151695FE50305B05242AAE0038C1A40A10012A0000000B094154435F303041453241

and this is raw data for faulty mac A4:C1:38:E1:8C:8D: 10161A18A4C138E18C8D00FB21640C310B0B094154435F453138433844

Message from faulty device is shorter, i looked through the code a bit and i see there should be bytes \x16\x95\xFE present in message but i dont see those in message from a faulty device.

I tried reflashing the custom firmware on the faulty device, shorting reset pins above the battery but nothing seems to help. Also i made sure that Advertising Type 'Mi Like' is set, that button was pressed about thousand times now while the device is connected to my phone :)

So, do I have a faulty device on my hand or is there some kind of remedy for this? Thank you in advance

Magalex2x14 commented 3 years ago

I have never heard of faulty devices before. I think you should ask a question in the custom firmware repository.

The only thing I can say is that the sensors send a lot of packets, but not all of them contain useful data. They may contain a Payload, but there is no data on temperature, humidity, battery. If a sensor in HA has an UNKNOWN state (instead of UNAVAILABLE), then the component receives packets from the sensor, but among them there has not yet been a single one with data on the status of the sensor. That is, if the status of an entity is unknown, then everything is fine, the reception works. At the same time, in both "empty" and "full" packets, in any case, there must be 0x1695FE bytes (this is a sure sign that the packet is from the Xiaomi Mijia ecosystem device, actually 0x16=Service Data, 0x95FE=Xiaomi UUID)

ivanpavlina commented 3 years ago

Thanks for the response, yeah, it would probably be better to ask this question in ATC's repo, sorry. Sensor is always in UNAVAILABLE state.. Also when i remove it from 'devices' list and turn on discovery that device is never discovered, while other one that works fine is..

I will try other repo, i also just ordered 10 of those sensors so i hope they will work fine :) Keep up the good work.

Magalex2x14 commented 3 years ago

Here are the differences between payload for short and full packets in a nutshell (this is how the LYWSD03MMC service data looks with the original firmware, that is, the payload is encrypted). For the rest of the sensors, everything looks about the same, just the PAYLOAD data is open:

---------------------------------------------------------------------------------------------------
len  AD  Xiaomi Frame Device  Frame     MAC (LE)        ----------------PAYLOAD--------------  RSSI
    type  UUID   ctrl  type    cnt                          cypher      ext.cnt     MAC tag
---------------------------------------------------------------------------------------------------
0F   16  95 FE  30 58  5B 05   BF   6B 87 2F 38 C1 A4   08                                      E3
1A   16  95 FE  58 58  5B 05   C0   6B 87 2F 38 C1 A4   63 02 92 E6 37  21 00 00  E5 E9 32 F7   E2
Magalex2x14 commented 3 years ago

If there is no data from the sensor, but it is close enough to the host, then in the case of original firmware I would say that it is not activated (if the sensor is not added to the official MiHome application, then it does not send packets with service data at all).

ivanpavlina commented 3 years ago

Thanks for the info, this could be usefull in the future, but both sensors are flashed with custom firmware, i just tried adding 'faulty' sensor to mihome app but it fails, which is expected.

I will look a bit more into the packets that sensor is sending, i agree that its weird that Xiaomi UUID is not present in messages.

Magalex2x14 commented 3 years ago

Refer to this issue in other repo, I can keep the conversation going if need be.

ivanpavlina commented 3 years ago

Nice, thanks, let me just 'catch' some more messages from this sensor to make sure that there isn't any 'normal' messages

ivanpavlina commented 3 years ago

Oooooh ... The following settings can be send to the RxTx Characteristics 0x1F10/0x1f1f These settings will not get saved on power loss, maybe that will change in future but normaly the battery will be in there for a while ... I am removing battery to make it send messages (in retrospect, probably a stupid idea :D ), it could be that it forgets 'Mi Like' Advertising Type and defaults to 'Custom'. Let me try it without removing the battery.

Magalex2x14 commented 3 years ago

Ha! I remembered what I saw somewhere a custom firmware, in which the MiLike option is enabled by default...

Magalex2x14 commented 3 years ago

Look at this: https://github.com/atc1441/ATC_MiThermometer/issues/37

ivanpavlina commented 3 years ago

:( 404 on all links. I'm gonna build my own compile env.... with blackjack and hookers :)

ivanpavlina commented 3 years ago

Problem solved, i flashed both sensors with new firmware which has MiLike Advertising type and they both work. Yay \o/ I'm attaching this firmware here so that it helps any poor soul like me.

Thank you for the help dude, you rock, now i finally have some proper and cheap option to measure temperatures in all corners of my house :D ATC_Thermometer-05122020-mi_like-adv.zip

Magalex2x14 commented 3 years ago

OK, thank you.