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 — 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)

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

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.2.0.tar.gz (17.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.2.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: walkingpad_controller-0.2.0.tar.gz
  • Upload date:
  • Size: 17.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.2.0.tar.gz
Algorithm Hash digest
SHA256 510780a395b7145c69b9baed5b8f5e042e785de5757d3eda78fdf412cf06bc7f
MD5 94ca61d674920e9f031167e6b1016b6c
BLAKE2b-256 61585b19063ee1471337ef2c4022b68b1ca2221af4c6c30123b49ace86c8f99f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for walkingpad_controller-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d43a281157030d91c27c694ccd72abeeee6dbdbd2fae1af5ea3f2f68c6134da
MD5 51e26d04f0a61e7e348a5b3dc2417d97
BLAKE2b-256 324f6deac55afbc3153a1e5be78e72f0402b7a1250dbc5f627e609f98b78d0c5

See more details on using hashes here.

Provenance

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