# Xiaomi Electric Scooter (BLE) for Home Assistant [![HACS Custom](https://img.shields.io/badge/HACS-Custom-41BDF5.svg?style=for-the-badge)](https://hacs.xyz/docs/faq/custom_repositories) [![GitHub release](https://img.shields.io/github/release/wajo666/homeassistant-xiaomi-scooter-elite.svg?style=for-the-badge)](https://github.com/wajo666/homeassistant-xiaomi-scooter-elite/releases) [![Validate](https://img.shields.io/github/actions/workflow/status/wajo666/homeassistant-xiaomi-scooter-elite/validate.yml?style=for-the-badge&label=validate)](https://github.com/wajo666/homeassistant-xiaomi-scooter-elite/actions/workflows/validate.yml) Reads a Xiaomi electric scooter **locally over Bluetooth** and exposes battery, range, mileage, mode, temperatures, battery health data and the last rides as sensors. It connects through **Home Assistant's Bluetooth stack**, so it works with the host adapter and with **ESPHome Bluetooth proxies** placed around the house. The Xiaomi cloud is used only once, during setup, to download the scooter's BLE key. ## Supported scooters | Model | Cloud model id | Status | |---|---|---| | Xiaomi Electric Scooter **Elite** | `xiaomi.scooter.elite` | verified | | Xiaomi Electric Scooter **4 Pro (2nd Gen)** | `xiaomi.scooter.t2336` | experimental (same protocol, property map not verified) | Older scooters (M365, Pro 2, 1S, Essential, Ninebot) use a different protocol and are **not** supported. Reports for other models are welcome: open an issue with the model id and a debug log. ## Installation 1. HACS → ⋮ → **Custom repositories** → add `https://github.com/wajo666/homeassistant-xiaomi-scooter-elite`, category **Integration**. 2. Download **Xiaomi Electric Scooter (BLE)** and restart Home Assistant. Manual: copy `custom_components/xiaomi_scooter_elite` to `/custom_components/` and restart. ## Setup Settings → Devices & services → **Add integration** → *Xiaomi Electric Scooter (BLE)*. A scooter that is switched on near an adapter/proxy is also discovered automatically. 1. Choose your **Xiaomi account region** (the one used by Mi Home). 2. Open the **login link** on a device already signed in to Xiaomi and approve it. No password is typed into Home Assistant. 3. Pick the scooter (if the account has several). 4. Enter the scooter **PIN** (set when pairing in Mi Home). The integration downloads the per-device BLE key (stored encrypted with the PIN) and decrypts it at runtime. ### Manual setup If the login link does not work for your account, tick **Manual setup** and paste: - the scooter's Bluetooth **MAC**, - the **encrypted BLE key** (64 hex characters, the result of the Xiaomi cloud call `share/askbluetoothkey`); for example with [`tokens/get_ltmk.py`](https://github.com/mehesbalazs/xiaomi-scooter-4-pro-2/tree/main/tokens) from ScooterLink, - the **PIN** and the model. ## Sensors | Sensor | Notes | |---|---| | Battery, Range, Total mileage | | | Mode | Pedestrian / Drive / Sport (`Locked` assumed for 0) | | Charge state | Not charging / Charging | | Motor temperature, Battery temp | | | Battery voltage, current, power | | | Battery status, cycles, over-discharge events | | | Remaining capacity, capacity / energy throughput | battery health over time | | Battery serial, manufacture date, BMS firmware, Firmware version, Activation date | diagnostics | | Last ride distance / duration, Rides logged | from the scooter's ride log (last ~10 rides in the attributes) | Not available over BLE: the scooter's own serial number (Mi Home reads it from the cloud) and the energy recuperation level (write-only setting). ## How it works and limitations - Reads happen only while the scooter is **switched on** and in range. When it has been advertising for 30 s, Home Assistant connects, reads all values (20–50 s) and **disconnects right away**. When it is off or away, the last values are kept, also across restarts. - **Only one Bluetooth connection at a time:** while the Mi Home app is connected, Home Assistant cannot read, and vice versa. - *Minimum time between reads* (Options, default 300 s) limits reconnects while the scooter stays on. - Force a read with `homeassistant.update_entity` on any of its sensors. - If the scooter stops advertising after an interrupted connection, the BLE link is still held by the adapter. Restart the adapter or proxy, or run `bluetoothctl disconnect ` on the host. Protocol: ECDH P-256 session; session key = `HKDF-SHA256(salt="smartcfg-login-salt", info="smartcfg-login-info", ikm = ecdh_shared ‖ LTMK)`. The 32-byte LTMK is the cloud key decrypted with `AES-128-CBC(MD5(PIN))`. Telemetry is read as MIoT spec properties over an AES-CCM channel. ## Privacy and disclaimer The Xiaomi account session is used only during setup and is not stored. The stored config entry contains the scooter's MAC, the encrypted BLE key and the PIN. This project uses unofficial, reverse-engineered interfaces. It is not affiliated with or endorsed by Xiaomi. Use at your own risk. ## Development ```bash pip install -r requirements_test.txt # inside a Home Assistant environment python -m pytest ``` CI runs hassfest, the HACS validation and the tests. ## Credits - BLE protocol: [ScooterLink / xiaomi-scooter-4-pro-2](https://github.com/mehesbalazs/xiaomi-scooter-4-pro-2) by mehesbalazs (MIT). - Xiaomi cloud API calls: [Xiaomi-cloud-tokens-extractor](https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor) by Piotr Machowski (MIT). - Property map of the Elite: reverse engineered and verified on a real scooter. License: [MIT](LICENSE); third-party notices in [NOTICE](NOTICE).