Skip to main content

A Python library for interfacing with TPMS (Tyre Pressure Monitoring System) devices

Project description

TPMS

Tyre Pressure Monitoring System Python Library

Overview

The TPMS (Tyre Pressure Monitoring System) Python library is designed to monitor tyre pressure and temperature for vehicles equipped with generic (AliExpress) TPMS sensors. This library has been tested on the TY06 hardware type but should also work with TY05.

V2 of this library has breaking changes and is not directly compatible with V1.

Installation

Install the TPMS library using pip:

pip install tpms

Usage

Basic Usage

from tpms_lib import TPMSDevice, TyrePosition

# Create TPMS device
tpms = TPMSDevice()

# Find available devices
available_ports = tpms.find_device()
if available_ports:
    # Connect to the first available port
    tpms.connect(available_ports[0])

    # Query sensor IDs
    tpms.query_sensor_ids()

    # Get tyre states
    tyre_states = tpms.get_all_tyre_states()
    for position, state in tyre_states.items():
        print(f"{position.name}: {state}")

    # Disconnect when done
    tpms.disconnect()

Temperature and Pressure Conversion

from tpms_lib import TPMSDevice, TyrePosition

tpms = TPMSDevice()
tpms.connect()
tyre_states = tpms.get_all_tyre_states()

for position, state in tyre_states.items():
    pressure_psi = state.air_pressure * 0.145038
    temp_f = (state.temperature * 9/5) + 32

    print(f"{position.name}:")
    print(f"  Pressure: {pressure_psi:.1f} PSI")
    print(f"  Temperature: {temp_f:.1f}°F")

    status = []
    if state.no_signal:
        status.append("NO SIGNAL")
    if state.is_leaking:
        status.append("LEAKAGE")
    if state.is_low_power:
        status.append("LOW BATTERY")

    print(f"  Status: {', '.join(status) if status else 'Normal'}")
    print()

tpms.disconnect()

Continuous Monitoring with Callback

from tpms_lib import TPMSDevice, TyrePosition, TyreState
import time

def on_tyre_state_update(position, state):
    pressure_psi = state.air_pressure * 0.145038
    temp_f = (state.temperature * 9/5) + 32

    print(f"Update for {position.name}:")
    print(f"  Pressure: {pressure_psi:.1f} PSI")
    print(f"  Temperature: {temp_f:.1f}°F")

    status = []
    if state.no_signal:
        status.append("NO SIGNAL")
    if state.is_leaking:
        status.append("LEAKAGE")
    if state.is_low_power:
        status.append("LOW BATTERY")

    print(f"  Status: {', '.join(status) if status else 'Normal'}")
    print()

tpms = TPMSDevice()
tpms.register_tyre_state_callback(on_tyre_state_update)
tpms.connect()

try:
    print("Monitoring for 60 seconds...")
    time.sleep(60)
except KeyboardInterrupt:
    print("Monitoring stopped by user")
finally:
    tpms.disconnect()

TL;DR

pip install tpms
from tpms_lib import TPMSDevice

tpms = TPMSDevice()
tpms.connect()
tyre_states = tpms.get_all_tyre_states()

for position, state in tyre_states.items():
    psi = state.air_pressure * 0.145038
    temp_f = (state.temperature * 9/5) + 32
    print(f"{position.name}: {psi:.1f} PSI, {temp_f:.1f}°F")

    if state.no_signal or state.is_leaking or state.is_low_power:
        print("  ALERT: Check tyre!")

tpms.disconnect()

Pairing Sensors

from tpms_lib import TPMSDevice, TyrePosition
import time

tpms = TPMSDevice()
tpms.connect()

def on_pairing_complete(position, tyre_id):
    print(f"Successfully paired sensor with ID {tyre_id} to {position.name}")

tpms.register_pairing_callback(on_pairing_complete)

print("Starting pairing mode for front left tyre...")
print("Please activate the sensor (add/release air or move the tyre)...")
tpms.pair_sensor(TyrePosition.FRONT_LEFT)

# Wait up to 120 seconds for pairing (matching Android app timeout)
time.sleep(120)

tpms.stop_pairing()
print("Pairing mode stopped")
tpms.disconnect()

Exchanging Tyre Positions

from tpms_lib import TPMSDevice, TyrePosition

tpms = TPMSDevice()
tpms.connect()

def on_exchange_complete(position1, position2):
    print(f"Successfully exchanged {position1.name} with {position2.name}")

tpms.register_exchange_callback(on_exchange_complete)

print("Exchanging front left and front right tyres...")
tpms.exchange_tyres(TyrePosition.FRONT_LEFT, TyrePosition.FRONT_RIGHT)
tpms.disconnect()

Resetting the Device

from tpms_lib import TPMSDevice

tpms = TPMSDevice()
tpms.connect()
tpms.reset_device()
print("Device has been reset. All paired sensors have been cleared.")
tpms.disconnect()

Example Application

An example CLI application is included. After installation, run:

tpms-monitor

The script provides a menu-driven interface for:

  • Showing current tyre states
  • Querying sensor IDs
  • Pairing sensors
  • Exchanging tyre positions
  • Resetting the device
  • Toggling debug logging

Debugging

To enable debug logging:

import logging
logging.getLogger("tpms_python.tpms_lib").setLevel(logging.DEBUG)

Protocol Details

The library implements the TPMS protocol based on reverse engineering of the Android app. The protocol uses a frame structure:

[0x55, 0xAA, length, command/data, data..., checksum]

Where:

  • 0x55, 0xAA: Header bytes
  • length: Total frame size (including headers and checksum)
  • command/data: Varies by message type
  • checksum: XOR of bytes 0 through (length-2)

The length byte also serves as a message type discriminator:

  • Length 6: Command messages (pairing, heartbeat, query, reset)
  • Length 7: Tyre exchange
  • Length 8: Tyre state updates
  • Length 9: Query ID responses

Position codes used in the protocol:

  • Front Left: 0 (pairing/state) or 1 (query ID)
  • Front Right: 1 (pairing/state) or 2 (query ID)
  • Rear Left: 16 (pairing/state) or 3 (query ID)
  • Rear Right: 17 (pairing/state) or 4 (query ID)
  • Spare: 5

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

tpms-2.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

tpms-2.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file tpms-2.1.0.tar.gz.

File metadata

  • Download URL: tpms-2.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tpms-2.1.0.tar.gz
Algorithm Hash digest
SHA256 9c8e96a4f3475881702a07d637504a6f15c31177fbee950a875b90ab3db59c2d
MD5 fe7bd3fce3f4979f4fc4268d0cd6cad3
BLAKE2b-256 fb2bd2ae6c7f82e3cf0b9b77280d26e72ede89a70676d25bd1da08e51f3075e2

See more details on using hashes here.

File details

Details for the file tpms-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: tpms-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tpms-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4492869e7934de28527939bd02dae01326d560e5848e09ed44820a482fd1fb38
MD5 675ec54905e8a1e0c2915853ed28f76f
BLAKE2b-256 843ccfa7c5cbe59484544cc657537f18b3ec824e84b0943a41d2f184e8f150be

See more details on using hashes here.

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