Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linptech K2 ESP32 MicroPython Probe

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

Run on ESP32

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.py

The scanner prints:

  • target address matches in normal and reversed byte order
  • raw advertisement payloads
  • Xiaomi 0xFE95 service data, if present
  • MiBeacon frame hints, including whether the payload appears encrypted
  • GATT service discovery output if the device accepts a connection

Payload Codec

The reusable codec is in lib/ks2_decoder.py.

Known KS2 payloads:

  • Temperature: object id 18433 / hex 0x4801, little-endian float
  • Humidity: object id 18440 / hex 0x4808, little-endian float
  • Battery: object id 20483 / hex 0x5003, uint8
  • Action: observed short event payloads use 0c5600, 0d5600, 0e5600

Current action mapping:

  • 0c5600 -> single
  • 0d5600 -> double
  • 0e5600 -> 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.py

Decode a captured advertisement:

uv run python tools/decode_mibeacon.py 020106181695fe58590b524d48a2b838c1a4097f009a0000581ba2c5

Expected Interpretation

If 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.

License

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.

About

MicroPython decoder and ESP32 BLE scanner for Linptech KS2/KS2BB Xiaomi MiBeacon temperature, humidity, and button events

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages