Skip to main content

walkingpad-controller

Python library for controlling KingSmith WalkingPad treadmills over Bluetooth Low Energy (BLE).

Supports FTMS (Fitness Machine Service), the legacy WiLink protocol and the Sperax P3 Max (wi-linktech WLT6200) behind a unified API. The protocol is auto-detected from the BLE device name and, if that is inconclusive, from the advertised services.

Features

  • Unified API — single WalkingPadController class for all device types
  • Auto protocol detection — FTMS for newer KS-HD-* / KS-AP-* / KS-MC21-* / KS-SMC21C-* / ZP-ZEALR1-* devices, Sperax for SPERAX_P3MAX, WiLink for older models
  • Real-time status — speed, distance, duration, calories, steps via BLE notifications
  • Cold-start handling — waits for the belt to start moving before sending a speed command, avoiding BLE disconnects on KingSmith devices
  • Safe stop handling — stop()/pause() cancel a pending start or speed change; start and speed changes wait while the belt runs down after STOP (see Known Behavior)
  • KingSmith vendor extensions — step counter (FTMS bit 13), vendor pre-amble (any device exposing the d18d2c10-… characteristic, e.g. MC-21), supplement service detection
  • Firmware version — exposed via controller.firmware_version (FTMS only)

Installation

pip install walkingpad-controller

For legacy WiLink device support (older WalkingPad models):

pip install walkingpad-controller[wilink]

Quick Start

import asyncio
from bleak import BleakScanner
from walkingpad_controller import WalkingPadController

async def main():
    # Find your treadmill
    device = await BleakScanner.find_device_by_name("KS-HD-Z1D")

    # Create controller (protocol auto-detected from BLE name)
    controller = WalkingPadController(ble_device=device)

    # Connect
    await controller.connect()
    print(f"Protocol: {controller.protocol.value}")
    print(f"Speed range: {controller.min_speed}-{controller.max_speed} km/h")

    # Start the belt (runs at minimum speed)
    await controller.start()

    # Set desired speed
    await controller.set_speed(3.0)

    # Read status
    print(f"Speed: {controller.status.speed} km/h")
    print(f"Steps: {controller.status.steps}")

    # Stop and disconnect
    await controller.stop()
    await controller.disconnect()

asyncio.run(main())

Status Callbacks

Register callbacks to receive real-time status updates:

from walkingpad_controller import WalkingPadController, TreadmillStatus

def on_status(status: TreadmillStatus):
    print(f"Speed: {status.speed} km/h, Distance: {status.distance}m, "
          f"Duration: {status.duration}s, Calories: {status.calories}, "
          f"Steps: {status.steps}")

controller = WalkingPadController(ble_device=device)
controller.register_status_callback(on_status)
controller.register_disconnect_callback(lambda: print("Disconnected!"))
await controller.connect()

API Reference

WalkingPadController

The main entry point. Auto-detects protocol and delegates to the appropriate backend.

Property / Method Description
protocol Detected protocol (ProtocolType.FTMS, WILINK, SPERAX or UNKNOWN)
connected Whether the device is currently connected
status Current TreadmillStatus
min_speed / max_speed Speed range in km/h (read from device for FTMS)
speed_increment Speed step size in km/h
firmware_version Firmware version string (FTMS only; empty otherwise)
connect() Connect and auto-detect protocol
disconnect() Disconnect from the device
start() Start or resume the belt (runs at minimum speed after a cold start)
stop() End the session (counters reset)
pause() Pause, keeping the counters; the next start() resumes (WiLink: falls back to stop)
set_speed(speed_kmh) Set speed; starts the belt first if it isn't running. 0 pauses and never starts
set_sound(on) Buzzer on/off. KS-HD-* only (supports_sound). Afterwards the device sends no Treadmill Data while standing still, until the next connection
set_incline(step) / set_vibration(level) Sperax P3 Max only; False elsewhere
switch_mode(mode) Switch operating mode (auto/manual/standby; support varies by device)
register_status_callback(cb) Register a TreadmillStatus callback
register_disconnect_callback(cb) Register a disconnect callback
update_ble_device(device) Update BLE device reference for the next connect (e.g. after rediscovery)
set_name(name) Name used for protocol detection when the BLEDevice has none (e.g. learned later)
update_state() Poll / refresh current status from the device

TreadmillStatus

Dataclass with real-time treadmill data:

Field Type Description
belt_state int BeltState: 0=stopped, 1=active, 2=paused, 5=standby, 9=starting
speed float Current speed in km/h
mode int Operating mode (0=auto, 1=manual, 2=standby)
distance int Total distance in meters
duration int Elapsed time in seconds
steps int Step count (FTMS KingSmith extension)
calories int Total energy in kcal
calories_per_hour int Energy rate
heart_rate int Heart rate in bpm (if available)
training_status / last_fm_event int FTMS training status and last Fitness Machine Status opcode
incline / vibration_level int Sperax P3 Max only
timestamp float Unix timestamp of last update

Protocol-Specific Controllers

For advanced use, you can use the protocol controllers directly:

  • FTMSController — FTMS protocol (newer KS-HD-* devices)
  • WiLinkController — Legacy WiLink protocol (older WalkingPad models, requires [wilink] extra)
  • SperaxController — Sperax P3 Max (wi-linktech WLT6200, vendor service 0xFFF0)

Supported Devices

FTMS Protocol (tested)

  • KingSmith KS-Z1D (BLE name: KS-HD-Z1D) — confirmed working
  • KingSmith KS-Z1E (BLE name: KS-HD-Z1E) — tested by community, see #7
  • KingSmith R3 (BLE name: KS-AP-RQ3, model KS-R3Q) — tested: connect, start, set_speed, pause, stop. Rejects STOP while the belt moves, so stop() pauses first (see Known Behavior)
  • KingSmith MC-21 (BLE names: KS-MC21-*, KS-SMC21C-*, ZP-ZEALR1-*) — confirmed working as of v0.4.1, requires the vendor pre-amble described below
  • Other KingSmith devices with BLE names starting with KS-HD- are expected to work via the same FTMS / supplement-service code path

Other FTMS treadmills (e.g. the Sperax RM-01) are detected by service probing and use the standard FTMS path.

Sperax Protocol

  • Sperax P3 Max (BLE name: SPERAX_P3MAX…, wi-linktech WLT6200) — speed, incline (0-10), vibration (0-4), pause
  • WalkingPad A1, A1 Pro
  • WalkingPad C1, C2
  • Other models supported by ph4-walkingpad

Known Behavior

FTMS Cold Start

KingSmith FTMS devices require a START_OR_RESUME command before the belt will accept speed commands. The library handles this automatically: it sends START, waits for the belt to report speed > 0 via treadmill data notifications, and only then sends SET_TARGET_SPEED. This avoids the BLE disconnects that occur when speed commands are sent during motor startup.

Run-down After STOP

After a session-ending STOP the belt keeps moving for a few seconds. On the KS-HD-Z1D, a START or speed command sent during that run-down is acknowledged but has no effect. start() and set_speed() therefore wait until the belt reports 0 km/h before starting it again. The run-down is known from the library's own acknowledged STOP as well as from the device's status event.

Halts Take Priority

stop() and pause() cancel a pending start() or set_speed(): an older start that is still waiting (for the belt to move, or for the run-down to end) gives up, and START or a speed command is not sent once a halt was requested. set_speed() decides between "set directly" and "start first" under the same lock as stop().

Reset and Control

FTMS RESET revokes control. The library requests control again before the next command (also when the RESET acknowledgement was lost); without it the KS-HD-Z1D answers nothing.

STOP While Running

The KingSmith R3 (KS-AP-*) answers FTMS STOP with OPERATION_FAILED while the belt is moving, and the belt keeps running. KS Fit never sends STOP to a moving belt: it pauses, then ends the session. For devices listed in FTMS_PAUSE_BEFORE_STOP_PREFIXES (currently only KS-AP-, verified on the R3), stop() does the same:

  1. It sends PAUSE whatever the cached speed is, because the cached value may be stale or lag a remote start.
  2. It waits for Treadmill Data received after the PAUSE to report 0 km/h.
  3. Only then does it send STOP.

If the link drops, telemetry stops arriving, or the belt is still moving at the timeout, STOP is not sent, stop() returns False, and the log says which case it was. Other FTMS devices keep the plain STOP behaviour.

The R3 also rejects both PAUSE and STOP during the 3-2-1 countdown after a START, and the belt then starts anyway. The firmware can't be halted during the countdown. If STOP is rejected at 0 km/h, stop() watches for the belt to start for a few seconds and pauses it as soon as it moves (on the R3 that takes about a second at 1 km/h). It then ends the session as above. If the belt stays at rest, there was no session to end and stop() returns False.

Multi-step commands (start, stop, set_speed, …) are serialised within a controller, and so are Control Point acknowledgements. pause() only waits for an in-flight Control Point write, and stop() cancels a pending start before queueing (see Halts Take Priority).

BLE Connection Drops

KingSmith FTMS devices may occasionally drop the connection, typically around a cold start. The library does not reconnect or replay commands on its own: call connect() again (Home Assistant's integration does this) and re-send the speed if needed. After a reconnect the cached speed is reset to 0 until fresh telemetry arrives.

Paused Session After Connecting

Connecting to a paused KS-HD-Z1D brings no status event. The library reads the first Treadmill Data frame instead: 0 km/h with elapsed time kept means a paused session (BeltState.PAUSED), 0 s means stopped.

Remote Control and ESPHome Bluetooth Proxies

ESPHome Bluetooth proxies (as used by Home Assistant) keep the link at an 8.75-11.25 ms connection interval. At that interval the KS-HD-Z1D ignores its own remote control while connected. When connected through such a proxy, the library asks for 30-50 ms (the BlueZ default) right after connecting; the remote then keeps working. Older proxy firmware without this feature ignores the request.

Connection Exclusivity

Only one BLE client can connect to the treadmill at a time — KS Fit and any client of this library are mutually exclusive.

MC-21 Vendor Pre-amble

The MC-21 family (KS-MC21-*, KS-SMC21C-*, ZP-ZEALR1-*) requires a vendor pre-amble before each FTMS Control Point command, and acks via Fitness Machine Status events rather than Control Point indications. The library detects this and handles it transparently. See docs/ftms-protocol-reference.md for the protocol details and docs/ks-fit-reverse-engineering.md for the analysis.

Requirements

License

MIT

Metadata

Release files for walkingpad-controller 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for walkingpad-controller 1.1.1
File Size Uploaded Provenance Actions
walkingpad_controller-1.1.1.tar.gz 122.5 kB With provenance Details for walkingpad_controller-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for walkingpad-controller 1.1.1
File Interpreter ABI Platform Actions
walkingpad_controller-1.1.1-py3-none-any.whl Python 3 none any Details for walkingpad_controller-1.1.1-py3-none-any.whl

Total release size: 177.2 kB

Release files / walkingpad_controller-1.1.1.tar.gz

Download URL walkingpad_controller-1.1.1.tar.gz
Size 122.5 kB
Tags Source
SHA-256 checksum
How to use checksums
763058c6304bf358d2d4b56cad7f7a267768cbca03294003dc08aad4718573d5
BLAKE2b-256 checksum
How to use checksums
a7484ee01422895b399fbce783b3b30fc18a92e62263c54ab8fb2922c2022689
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / walkingpad_controller-1.1.1-py3-none-any.whl

Download URL walkingpad_controller-1.1.1-py3-none-any.whl
Size 54.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6deba67ba6b155e360c6c9544180e7e707240b8dc53b05b8d26a793373376352
BLAKE2b-256 checksum
How to use checksums
3fe16df5082edbdfd018ab896d9ad0e0a074a1384eff33c008a278c53937e6ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for walkingpad-controller 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for walkingpad_controller-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page