I am not sure… If you give the sensor the correct BLE bind key from Xiaomi Cloud, it should just work.
I got it working by selecting “Chinese Mainland” in the Mi Home app like you suggested. It showed up almost instantly once it was using the right server. Thanks for the links in the original post to set up the bind key as well - it took a while, but I managed to get past that, and have it set up in Home Assistant now.
Thanks again for the help!
Couple of questions since ive been struggling to find a batterg mmwave sensor that works. I have now ordered the Tuya Battery Sensor ZG-204ZM maybe from 3/4 different sellers, all not working.
-
The aliexpress link you shared is sold out, can you let me know the model number of the Xiaomi one?
-
I relatively not that experienced in settinf things up so require just a little more hand holding here. I have SMLIGHT SLZB-06 with ZigbeeMQTT installed on Raspberry Pi 4. Do i need any other hardware to get this working?
Thank you! What about any other hardware apart from the oned i mentionef above?
The xiaomi sensor is a BLE device, not a Zigbee device, so your zigbee-mqtt setup does not help.
To make a BLE device discoverable by HA, you need either 1) enable Bluetooth on your HA hardware (and related setting) directly OR 2) add Bluetooth Proxy device in the local network (e.g. I used the M5Stack one). I recommend the second approach, especially when your BLE device is not closed to your HA hardware.
Please read the setup doc below to get the detailed steps.
Here is the for dummies step-by-step guide, now that we have @ldfandian update in 2024.10.0
Basic Requirements
You need to have Bluetooth adapter and integration in you HA.
You need to add Xiaomi BLE integration to you HA
Now some manual work
Power on the sensor by holding the button for 7 seconds, it will blink blue 5 times.
HA will now discover it and Xiaomi BLE integration will add it without the BLE key.
It will show only signal strength, but don’t worry we are about to configure it.
Open your Mi Home app - Apple or Android
Go to your profile and click Additional Settings at the bottom
On the next screen click on Region
Type in “Chine” and select Chinese mainland
Once you log in (or create an account) press the + in the top right corner to add new device
Hold the button for 7 seconds again and the app will find it
It will complain that you need a gateway, but you can still configure it.
Just keep your phone close.
Scroll to the bottom to get to the settings and adjust to your liking.
I only turned off that blue switch light.
All done in China.
You can log out from your Asian profile
Final step
Now we need that BLE token Xiaomi uses.
Back to HA, if you are running HAOS open up the terminal and paste this command
bash <(curl -L https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/raw/master/run_docker.sh)
(For other methods see Token Extractor Git)
This will fetch the token from Xiaomi Cloud
Fill in your account credentials and type cn for the server
You will see something like this in the terminal
Devices found for server "cn" @ home "9540037XXXXXX":
---------
NAME: Xiaomi Human Presence Sensor
ID: blt.3.1j9mo411XXXXX
BLE KEY: 4804797ab8289bdecfa3d4bxXXXxxxXX
MAC: F8:XX:XX:XX:XX:XX
TOKEN: XXXXXXXXXXXX
MODEL: xiaomi.sensor_occupy.03
---------
Copy the BLE KEY value.
Back in HA your Xiaomi BLE integration will report configuration change and ask for this key.
Put it in and you are good to go.
Walk by the sensor or turn on the light so it populates all of the available sensors.
Since this is BLE broadcast device it will take some time for HA to catch all the sensors.
Simple right?
How long does it take for all entities to be recognized? At first, only three entities were displayed: Duration detected, Illuminance & Signal Strength. After a few minutes, Battery was added.
Really appreciate the thorough guide!
It depends on the sensor status changes, I think.
- when the status changes from “cleared” to “occupied”, “duration detected” and “occupancy” shows up.
- when the status changes from “occupied” to “cleared”, “duration cleared” and “occupancy” shows up.
- when “illuminance” changes significantly, “illuminance” shows up.
I picked up a couple of these to test out and seeing some anomalies.
My “Duration detected” has been at 5min for over an hour now.
Also my occupancy entity has been listed as detected ever since joining. I tried throwing it in a drawer in another room and Signal Strength, Illuminance and Duration cleared updated, but it still showed detected and duration detected was still 5 minutes.
Does it take some time for these to shake out and start updating properly?
I DM some installation tips to you, please take a look and tune the setup config.
Can you please “DM” those tips to this thread also? I’m struggling with similar issues. Occupied never goes away. Even when nobody is home, it’s occupied. In a room with no window and nothing moving.
Sent message to you. Hope it helps.
Thanks. This will be interesting.
Is there a solution if my Home Assistant (HA) setup is far away from the occupancy sensor?
I am using Tasmota on a Sonoff Dual R3 to read temperature and humidity data from a Xiaomi sensor. Has anyone successfully integrated an occupancy sensor with Tasmota? If so, I’d appreciate any guidance or examples!
Thanks!
- To improve BLE coverage, I recommend using a Bluetooth proxy like the “M5Stack Atom Lite.” You can find more details here ( Bluetooth Proxy — ESPHome )