This project probes and decodes a Linptech K2 temperature/humidity/button sensor from an ESP32 running MicroPython.
Target from Mi Home:
- Model:
linp.sensor_ht.ks2bb - MAC: stored locally in
secrets.py - Bindkey: stored locally in
secrets.py
Install mpremote, connect the board, then copy and run:
mpremote connect /dev/cu.usbserial-14440 fs cp secrets.py :secrets.py
mpremote connect /dev/cu.usbserial-14440 fs cp linp_k2_scan.py :linp_k2_scan.py
mpremote connect /dev/cu.usbserial-14440 run linp_k2_scan.pyThe scanner prints:
- target address matches in normal and reversed byte order
- raw advertisement payloads
- Xiaomi
0xFE95service data, if present - MiBeacon frame hints, including whether the payload appears encrypted
- GATT service discovery output if the device accepts a connection
The reusable codec is in lib/ks2_decoder.py.
Known KS2 payloads:
- Temperature: object id
18433/ hex0x4801, little-endian float - Humidity: object id
18440/ hex0x4808, little-endian float - Battery: object id
20483/ hex0x5003, uint8 - Action: observed short event payloads use
0c5600,0d5600,0e5600
Current action mapping:
0c5600->single0d5600->double0e5600->hold
The 0c and 0e codes were observed from real encrypted KS2 advertisements. 0d is inferred as the middle code for double click and should be confirmed with a double-click capture.
Run local tests:
uv run python -m unittest tests/test_ks2_decoder.pyDecode a captured advertisement:
uv run python tools/decode_mibeacon.py 020106181695fe58590b524d48a2b838c1a4097f009a0000581ba2c5If the target is seen but GATT connect fails or immediately disconnects, that likely means integration should be based on BLE advertisements, not an active connection.
If 0xFE95 appears with encrypted=True, the scanner can now decrypt it on ESP32 with the 16-byte bindkey. Home Assistant integration can be built later on top of the decoded dictionaries.
This repository is licensed under CC-BY-NC-SA-4.0.
Commercial use is not permitted. Modified or derived versions must be distributed under the same license. See LICENSE for details.