@Magalex Dear Aleksey,
In one statement - ALL IS WELL, my dear friend!
Very glad to report that your instructions, clear and complete as they were, did result in both sensors getting registered in HA and working fine (after the usual struggle - total 3 hours; some tears, lots of smiles).
For the benefit of others (and to serve as a reminder to my own-self when I acquire more sensors after this COVID nonsense is over), here are the steps as I followed them…
Hardware:
HA updated and current. Running on Rpi3 (I know, I know - will soon move to a SSD).
2 x LYWSD03MMC sensors.
Steps Taken:
Acquire the mac address of the LYs. Easily done via ssh to HA.
$ ha help
➜ ~ bluetoothctl
Agent registered
[CHG] Controller B8:27:EB:7E:50:F2 Pairable: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:7E:50:F2 Discovering: yes
[NEW] Device A4:XX:XX:XX:XX:67 LYWSD03MMC
[NEW] Device A4:XX:XX:XX:XX:4E LYWSD03MMC
[bluetooth]# scan off
Discovery stopped
Copied and pasted this (to copy/paste and for added functionality, used MS Visual Studio terminal) into a blank text file and named the sensors LY1 and LY2 to avoid confusion later.
Logged off ssh.
This info may be gathered by many ways; and various other BT apps.
Opend the Stream app on my iPhone.
Important step - In the app’s settings, choose HTTPS sniffing otherwise the whole procedure will go a waste (I learnt it the hard way). To complete this, the usual VPN trust procedure in Settings>General>About>Profiles needs installation. Make sure this profile is verified and ticked green.
Now, ensure that MiHome app is logged-in (ensure it is logged-out of other devices and region chosen is mainland China - I faced some grief on account of multiple log-in on other devices) and that the LYs are not added. Remove (delete) if needed. This can be done multiple times without any issues. Force close the app and restart it.
On Stream, hit ‘Sniff now’ and immediately move to the MiHome app and commence the pairing procedure - don’t worry if auto discovery selects the LY. Complete the pairing and get the T and RH data from the LY. I paired only one to start with - the LY1.
‘Stop sniffing’ on Stream. This took about 65 seconds in my case. Now, goto the sniff history, Edit, Select all and ‘Export HAR’. I did this export to my NAS.
Charles Proxy app (30 day trial) was used on a mac to open the said HAR file. Use the find feature and find bind_key
It will be 32 characters long.
From here on, things get easier! I had the LY1 and LY2 data ready in VS but not yet pasted in the Configuration.yaml
Time for an important Start/Stop procedure (I did struggle here a bit).
a) Stopped HA from here.
b) For additional measure, powered off and restarted the pi.
c) Logged-into HA and appended the config.yaml file as shown above.
d) Restarted HA.
Waited patiently for about 15 minutes.
Voila!! 4 new entities magically appeared into the Entities tab! Renamed them - will give a more meaningful name once I have tried them for a few days.
My best wishes and salute to Aleksey and all others who have contributed to this project and indirectly, to my…happiness - life is nothing but a pursuit of it, is it not
@Magalex, thanks for providing us with such a useful plugin. Had to recompile Python 3.8.2 with Bluetooth Sockets though, but after that it worked.
However, as I have LYWSDCGQ devices scattered all over the house, and remote_ha probably isn’t the best option (I’ve got Raspberry Pi Zero Ws around the house), I was wondering what it would take to turn https://github.com/algirdasc/xiaomi-ble-mqtt into the same passive-mode approach ? I’m using it today but it’s doing the active-mode-approach.
I think it will be easier to write own daemon (since periodic launch through cron is not suitable for passive mode - the code should be executed all the time in the background). To do this, I need to figure out how to correctly implement it in python, and figure out how to correctly publish data to MQTT.
You are not the first who asks for this, and there is a corresponding issue in our GitHub repository. The implementation of the component as a standalone is in the plans, but I still can’t allocate time for this…
I followed the steps but I cannot find the bind_key in the HAR file. I also add (until it reads temperature) and remove many times. Can you talk more details about this step?
Unfortunately I don’t find any bind_key when I look into the .har file.
I use stream on my Ipad with https sniffing.
Should I import the certificate from the Ipad to my win10 PC (running Charles app).
It can be frustrating…(took me a few hours to nail it). If HTTPS is there, so is the bind key…assuming the MiHope pairing went well.
I suggest you try again. Get a few minutes worth of HAR file and export them ALL…there are more than plenty there. Wish I could find a ‘select all’ option.
@Magalex Further update…
All working well. I have read on numerous forums that the RPI3 has a lousy BT adapter - well, I beg to differ.
I live in a split level house of conrete construction.
LY2 is ca 8 meters away; same level but behind 2 brick walls.
LY1 is ca 10m away on the lower level (1 conrete slab) plus 2 brick walls.
I have yet to see a missed signal or ‘Unvailable’ on HA (that only happens after HA restart until the first polling interval).
The passive component is a very clever idea and in hindsight, the frustration of the design change on account of the LY, in my opinion, has actually led to a better and more ‘green’ solution.
God bless you, droog!
I think that the problems with bluetooth on raspberry pi in most cases are connected with poor power supply (in terms of the power ability and its “purity”) and not very good design in terms of electromagnetic compatibility (adding devices like SSDs greatly spoils the picture). So much depends on the individual characteristics of each installation. Your result pleases, yes.
First and important, you MUST install HACS to be able to read LYWSD03MMC sensor because this intergration is different than the original intergration.
At first, I have a problem finding bind_key, too. Therefore, I wrote another instruction in iOS. This instruction is for LYWSD03MMC sensor. I don’t know the other sensors are different or not.
Open Stream -> HTTPS Sniffing -> CA Install. Then you will be directed to browser to download VPN profile.
Go to General -> Profile -> Stream Generated CA… -> Install the VPN profile
After installing VPN profile.
Open Stream -> HTTPS Sniffing -> hit trust CA in settings
General -> About -> Certificate Trust Settings -> tick green on Stream Generated CA…
Logged in to MiHome and open Stream.
Then hit “Sniff now”.
Immediately go to MiHome and add LYWSD03MMC sensor.
Waiting for the app to read Temperature and Humidity.
Then close MiHome app. Go back to Stream and click “Stop Sniffing “
Now go to sniff history and search for keyword “bltbind”. Will see file
“POST https://api.io.mi.com/app/device/bltbind”
If you don’t see that file, go back to step 3 to check whether the CA was trusted or not.
You can click Edit -> Export HAR
Then use Charles Proxy on laptop to see HAR file.
Below is other way to find bind_key inside Stream app (if you don’t want to install more software to laptop).
Click on that file -> Request -> “Preview Form” at bottom -> Format -> Decode -> find “bind_key”
After finding bind_key, then add it to Configuration.yaml
Stop HA in Server management. Then, unplug and plug back power source. HA will be start working in about 10 minutes
Wait about 10 more minutes, you will see the sensor entities in Entities or States tab in HA.
Batteries level sensor will be showed up after an hour
I am running home assistant on a Synology without Bluetooth. I got an Raspberry Pi and some ESP32 modules. Is it somehow possible to use this component also with the Bluetooth of my PI or ESP32? How to realize the connection between home assistant and the Bluetooth receiver?
Hi, I am using LYWSD03MMC sensors with encryptors as described above.
After adding 5th sensor my RPI3 HASSIO started to crash (no web gui/but can access files remotely).
Removing any of the 5 devices solves the problem.
Has anyone faced similar situation? Any suggestions?