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-* devices, WiLink for older models
  • Real-time status — speed, distance, duration, calories, steps via BLE notifications
  • Cold-start handling — retry logic for KingSmith FTMS devices that need START_OR_RESUME before accepting speed commands
  • Reconnect recovery — pending target speed is automatically re-applied after BLE reconnection
  • KingSmith extensions — step counter via proprietary FTMS extension (bit 13)

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 at 3.0 km/h
    await controller.start(target_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
connect() Connect and auto-detect protocol
disconnect() Disconnect from the device
start(target_speed=None) Start the belt, optionally at a target 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

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)
  • Other KingSmith devices with BLE names starting with KS-HD-

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. After a cold start, there is a delay of several seconds before SET_TARGET_SPEED takes effect. The library handles this automatically with retry logic.

BLE Connection Drops

KingSmith FTMS devices may drop the BLE connection shortly after a cold start, especially at weaker signal strength. The library stores the pending target speed and can re-apply it after reconnection via the status callback mechanism.

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.

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.1.0.tar.gz (16.7 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.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for walkingpad_controller-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ff119ac929ff6d25b84999d58849012238b5a819abed0a963ba543404a22177
MD5 e373a4fbfd4cb5b952c3d728d07e1bd2
BLAKE2b-256 a1b813b796b33563c332cc49a6564ac006f0c791de7c90ca6cff1baeeb544f45

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.1.0.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for walkingpad_controller-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2e4d08212668d087a5b535f5f4a48c7b0703dc6b2995a6aebe4a57302173565
MD5 4189e54571464511aa134a97209f39a9
BLAKE2b-256 65033e5ec992be7963e5f62601d0c2d953d4e387970e3666c5d2f4ab3936d9e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.1.0-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