Skip to main content

Python library for controlling KingSmith WalkingPad treadmills over BLE (FTMS and legacy WiLink protocols)

Project description

walkingpad-controller

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

Supports both FTMS (Fitness Machine Service) and legacy WiLink protocols behind a unified API. Protocol is auto-detected based on the BLE device name and advertised services.

Features

  • Unified API — single WalkingPadController class for all device types
  • Auto protocol detection — FTMS for newer KS-HD-* / KS-MC21-* / KS-SMC21C-* / ZP-ZEALR1-* devices, WiLink for older models
  • Real-time status — speed, distance, duration, calories, steps via BLE notifications
  • Cold-start handling — waits for belt to start moving and stabilize before sending speed commands, avoiding BLE disconnects on KingSmith devices
  • Reconnect recovery — pending target speed is automatically re-applied after BLE reconnection
  • KingSmith extensions — step counter via proprietary FTMS extension (bit 13), MC-21 vendor pre-amble for SET_TARGET_SPEED, supplement service detection (KS-HD-*)
  • 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 or ProtocolType.WILINK)
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 the belt (runs at minimum speed)
stop() Stop the belt
set_speed(speed_kmh) Set speed (starts belt if stopped)
switch_mode(mode) Switch operating mode (WiLink: auto/manual/standby)
register_status_callback(cb) Register a TreadmillStatus callback
register_disconnect_callback(cb) Register a disconnect callback
update_ble_device(device) Update BLE device reference after rediscovery
update_state() Poll / refresh current status from the device

TreadmillStatus

Dataclass with real-time treadmill data:

Field Type Description
belt_state int 0=stopped, 1=active, 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)
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)

Supported Devices

FTMS Protocol (tested)

  • KingSmith KS-Z1D (BLE name: KS-HD-Z1D) — confirmed working
  • 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

WiLink Protocol (via ph4-walkingpad)

  • 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, then waits an additional stabilization period before sending SET_TARGET_SPEED. This avoids the BLE disconnects that occur when speed commands are sent too early during motor startup.

BLE Connection Drops

KingSmith FTMS devices may occasionally drop the BLE connection after a cold start due to firmware limitations. The library stores the pending target speed and automatically re-applies it after reconnection (with appropriate stabilization delay). When used with the Home Assistant integration's "Stay Connected" mode, this provides seamless recovery.

Connection Exclusivity

Only one BLE client can connect to the treadmill at a time. If Home Assistant holds the connection, the KS Fit app cannot connect, and vice versa.

MC-21 Vendor Pre-amble

The KingSmith MC-21 family (KS-MC21-*, KS-SMC21C-*, ZP-ZEALR1-*) refuses standard FTMS REQUEST_CONTROL and rejects SET_TARGET_SPEED unless a fixed 8-byte payload is first written to a vendor characteristic (d18d2c10-…) embedded in the FTMS service. This library detects the characteristic on connect and replays the pre-amble before each Control Point command — matching what the official KS Fit app does. On these devices, command success is signalled via Fitness Machine Status (0x2ADA) events rather than Control Point indications; the library races both signals and accepts whichever arrives first.

For the full reverse-engineering analysis, see docs/ftms-protocol-reference.md and docs/ks-fit-reverse-engineering.md.

Requirements

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

walkingpad_controller-0.4.3.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

walkingpad_controller-0.4.3-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file walkingpad_controller-0.4.3.tar.gz.

File metadata

  • Download URL: walkingpad_controller-0.4.3.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for walkingpad_controller-0.4.3.tar.gz
Algorithm Hash digest
SHA256 468c31db58334abca12047a7141fa9d1223f64b897d9876699a801dec034323d
MD5 2948377d471e3c376e83db59dd9160ac
BLAKE2b-256 acb54215fad0a841adb1285a158b5370e5f8c407927b598dada8c2d462a782a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.4.3.tar.gz:

Publisher: publish.yml on mcdax/walkingpad-controller

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file walkingpad_controller-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for walkingpad_controller-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76b45cf5c69551256175c1572b4fa8d9bf1a751642951df536166511c88fe8a4
MD5 3d4ac5dab902613774729eb85d80161d
BLAKE2b-256 79c3291c9cbc777c848a1d236ee83b3ac6f6e04bf6db7582962c415b5619efa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.4.3-py3-none-any.whl:

Publisher: publish.yml on mcdax/walkingpad-controller

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page