-
Notifications
You must be signed in to change notification settings - Fork 28
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
Support LYWSD03MMC new mijia temp/humidity sensor #552
Comments
The LYWSD03MMC is incredible value for the price and could fit gloriously in any smart home. But, following the links you provided it seems it doesn't work like any other Xioami device and doesn't broadcast his data but instead requires a direct connection. This will probably cause issues when multiples devices are concerned and ultimately consume more battery power. |
@Trillon008 no, it sends ADV-packets as well, but they're encrypted :) |
(Just got mine a couple hours ago, and super interested in pulling the data in) There is a fundamental shift in how it operates (seems to require pairing where the previous versions broadcast to the open air), but the linked python script is able to read the data without issue. |
Likely standard BLE encryption, and since esphome is the master device, there would be no need to break the encryption |
But esp32_ble_tracker has no master/slave approach, it passively listening. |
@vevsvevs Yes, that’s what I meant: there would have to be a separate |
Apologies if this looks like advertising, I’m really just trying to help dev results. |
Anything new regarding the use in HA? |
Meanwhile, the ADV-payload decryption method for this sensor is already known. I hope some high-skilled contributor will be so kind to implement support of this sensor soon :) |
@vevsvevs Yes it was found, but only a few hours ago. Give people a chance to look into it |
Anything new? Meanwhile i've found this but I don't know how to use it |
This one is based on GATT connection and notifications while ESPHome way is to listen to advertised packets. |
I think HA custom component mitemp_bt has found some way to fetch data passively, see custom-components/ble_monitor#7 (comment) |
I bought 8 of the new LYWSD03MMC mijia temp/humidity sensors and 3 ESP32 dev boards to be used with ESPHome. I would really like to get the sensors directly supported in ESPHome. I have collected a full Android HCI dump while pairing the devices in the Xiaomi Home App and looked at it in Wireshark , but don't know how to proceed from here. I would really appreciate if somebody more skilled than me could step in.
It would be really nice if that would be possible and hopefully the encryption key does not change over time. |
Hopefully with the right people involved, ESPHome could be the one to do the initial pairing, making extracting the key much simpler. |
What are the next steps? I can read the temperature and humidity with this python script, but only when connecting to the device. I collected a clean dump of the conversation and can see the raw sensor values in the Notification, Handle 0x0036 as described in the README. But that is not what I need. I need to passively collect the data simultaneously from eight sensors with just two ESP32 (flashed with ESPHome connected via MQTT to HA and Grafana). As I understand, the device is constantly sending the data, but the data is encrypted. How do I extract the encryption key from the raw dump?
It sounds as it is actually possible! |
Obtaining the bind-key for ADV-payload decryption is quite simple following the guides described in the above mentioned project custom-components/sensor.mitemp_bt. I have extracted the bind-keys for all my eight LYWSD03MMC sensors and they are working fine in HA. However, I want to distribute them around the house and therefore need the ESP32s with ESPHome for the bluetooth connectivity. I had a quick look at the python code in sensor.py, which emulates hcitool, constantly scans for the broadcasted ADV packets and automatically decrypts the payload with the temperature and humidity values. This is basically what we need without the HA code, so an experienced programmer needs to translate the existing python code into Arduino C++ code to be included into ESPHome. Unfortunately I am just starting with bluetooth programming, so somebody more experienced is welcomed to step in. I hope the sensor will get eventually supported in ESPHome. |
I also thought I'd need ESP32 or some more bluetooth adapters to be able to cover the entire house. But it seems I don't, after all. One USB dongle works perfectly. |
Interesting, I didn't know that it is possible to extend the USB via Ethernet cables. It would indeed be a possibility for me as I have unused RJ45 outlets in every room. But I prefer to use the ESP32s as they are more versatile and also more fun (and I already have bought all hardware). I started to look into the ESPHome pyhton and C++ code and how to implement the new sensor component. It seems that the esp32_ble_tracker component needs to modified to include the payload decryption and also a new sensor configuration needs to be created. I am just starting to learn ESPHome and bluetooth programming. So it will take me a while to figure it out if I have to do it all by myself. But I'll give it a try. |
@ahpohl Feel free to ask any questions about the operation of the custom component mentioned above and the technical details about LYWSD03MMC - I will help you all I can. |
@Magalex2x14 Thanks for offering your help. In the meantime I have successfully created a standalone python script mitemp_standalone.py from your HA custom component sensor.py to get familiar with bluetooth low energy programming. The esp32_ble_tracker component is another story though. As far as I can tell, the function Which IDE do you recommend for coding? How do you test the new code? I find it difficult to develop for ESP32 when I cannot use the Arduino IDE directly. |
@ahpohl I use Visual Studio Code with addons like python linters, formatters, etc. For VSCode there are also C++ and Platformio addons, and I used them when I made a custom component for working with oled display on my ESP32 board. Unfortunately, this is where my knowledge of ESPHome architecture ends... At the moment, I'm a bad assistant in this... Just in case, here is a link to the esphome development environment setting up. |
https://community.home-assistant.io/t/xiaomi-passive-ble-monitor-sensor-platform/177352/144 this is great component, but I need working solution for ESP32... |
Development of a xiaomi_lywsd03mmc custom component for ESPHome has been initiated. The C++ decryptor works and the code can be used to extend xiaomi_ble. I already created the new sensor type xiaomi_lywsd03mmc, but unfortunately the new platform is not recognised during build. |
even in 1.5 dev not? |
@Monacoslo: Could you please explain what you mean with this comment? I created a new platform xiaomi_lywsd03mmc (in a new brach with the same name) but get this when compiling the firmware
EDIT: problem solved. I was not installing the new xiaomi_lywsd03mmc platform into my virtualenv after creating it. Now it recognizes the new platform! |
I compile the firmware using your branch but the response is empty: |
@ppanagiotis its not quite finished yet. The new platform is currently just a template. A lot more work needs to be done, e.g. creating a new config item |
how to install a new platform? "Failed config sensor.xiaomi_lywsd03mmc: [source config/ble_tracker.yaml:38] Platform not found: 'sensor.xiaomi_lywsd03mmc'. |
Hi, |
i have installed ESPhome as add-on home assistant. and it all worked.
thanks for the help anyway. :)
вс, 25 окт. 2020 г. в 21:49, rvanderven <[email protected]>:
… EDIT: problem solved. I was not installing the new xiaomi_lywsd03mmc
platform into my virtualenv after creating it. Now it recognizes the new
platform!
how to install a new platform?
"Failed config
sensor.xiaomi_lywsd03mmc: [source config/ble_tracker.yaml:38]
Platform not found: 'sensor.xiaomi_lywsd03mmc'.
platform: xiaomi_lywsd03mmc"
Hi,
I had the same issue.
I installed esphome via 'pip install esphome' some time ago. I have a
recent 2nd HA installation where I installed esphome as well. I found out
the both esphome versions were not the same.
I thought I used the proper update method for esphome, but apparently not.
Today I searched for it and I needed to use 'pip3 install -U esphome' to
update esphome and this did the trick.
I had to kill and start the esphome process which I normally start with:
'nohup esphome /home/pi/homeassistant/config/ dashboard >
/home/pi/homeassistant/esphome.log &'.
So now I am able to compile the new esphome entry with the new sensor
xiaomi.lywsd03mmc.
Hope this helps.
PS: Don't forget to connect to the sensors and set the Advertising Type to
"Mi Like", otherwise you will not see any data in esphome. For one sensor I
had to do this mulitple times before receiving data.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#552 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQBSAUGUIAHRTXGD7BNTYGLSMRXLDANCNFSM4KCY6RGA>
.
|
i am a noob |
Flash stock firmware https://github.com/atc1441/ATC_MiThermometer#stock-firmware |
thanks, i have one more noob question: why is it not showing in google home app when i linked both accounts? is there a way to do it? |
Hi Folks, already have 2 of these wonders working on home assistant through ESP, however having issues an getting data from 3 sensor. Any ideas? |
Have you tried restoring the stock firmware? Then just generate the encryption key with the TelinkFlasher and try without actually flashing the custom firmware. It should work if the sensor itself is ok. |
sorted, problem is that sometimes when you press "mi like" doesn't assume config and you don't see any error, press some dozen times and it's done :) |
I have a question for you, will I be able to connect 4 sensors under ESP32 and Xiaomi Home simultaneously by pulling out Bindkey https://atc1441.github.io/TelinkFlasher.html? |
@miastekpl It is no problem, you can add as many as you want. You don't need to change anything. You can leave the current binkkey as it is, as it only needs to have the correct format. |
So if I read Bindkey TelinkFlasher and put it in a file in ESP32, I will have sensors in Home Assistant and in the Xoaimi Home application? |
I think when you flash it with custom firmware, you cannot access it anymore in Xoaimi Home app. |
I have a plan, add sensors to the Xiaomi Home app, read Bindkey with TelinkFlasher and then put this bindkey into ESP32, can it work? Any of you did it? |
Ahh. Sorry, I did it with the old method (the custom Android app) with the official stock firmware. Moved to custom firmware a couple of days ago. Looks like custom firmware cannot be used with Mi Home app. |
That's right, after changing the firmware, you will not connect the Xiaomi Home app with the sensors. |
Ahh, only use the "Do Activation" button.. Maybe. I don't see a similar issue/question on the original repository. Please, create an issue with this question here so we can find out: Issues · atc1441/ATC_MiThermometer (github.com) |
Thank you very much for your answer. |
I'm not sure, have no experience with it. Please ask this through an issue here: Issues · atc1441/ATC_MiThermometer (github.com) |
I just wrote a report there, if I get an answer, I will share it with you. |
Great. I'll watch the ticket, for the rest, here is the ticket: Connecting sensors to ESP32 · Issue #126 · atc1441/ATC_MiThermometer (github.com) |
Hey. The BindKey does change the moment you click on do activation. This is also mentioned in the Telink flasher |
Got it, is there any way to read an already existing Bindkey without changing it? Because that would solve a lot of problems. |
Yes, there is. But only the "traditional way" by sniffing the bind key when the device is connected to the Xiaomi cloud. |
Reading bindkey by reprogramming to custom firmware and back to original. |
Describe the problem you have/What new integration you would like
Add support for the mijia Temperature/Humidity Sensor LYWSD03MMC
Please describe your use case for this integration and alternatives you've tried:
These are an updated version of the sensors from xiaomi mijia, and are small compact devices that can be used in discreet places
Additional context
Work has been done in a number of places to support them, that maybe of assistance
custom-components/ble_monitor#7
https://github.com/JsBergbau/MiTemperature2/
thankyou
The text was updated successfully, but these errors were encountered: