Fork of pbutterworth/py-nissan-leaf-obd-ble (Python BLE/ELM327 API for Nissan Leaf OBD dongles), maintained here with a fix that releases BLE proxy connection slots
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
tim 49482f4ece
All checks were successful
Auto tag / Tag release (push) Successful in 2s
Security / Security scan (push) Successful in 31s
Test / Lint and test (push) Successful in 16s
Merge pull request 'pre-commit: ruff 0.17.5' (#7) from chore/ruff-0.17.5 into main
2026-11-20 11:38:48 +00:00
.forgejo/workflows ci: use workflow-basics @main instead of the moving v1 tag 2026-10-12 11:43:05 +02:00
src/py_nissan_leaf_obd_ble Log per-write and per-command traces at DEBUG, release 0.2.1 2026-10-12 21:31:47 +02:00
tests Log per-write and per-command traces at DEBUG, release 0.2.1 2026-10-12 21:31:47 +02:00
.gitignore fix: bound BLE operations and force-disconnect on failure to release proxy slots 2026-04-30 14:53:34 +02:00
.pre-commit-config.yaml pre-commit: ruff 0.17.5 2026-11-20 12:22:30 +01:00
LICENSE Initial package from nissan-leaf-obd-ble 2026-03-05 13:55:00 +13:00
PUSH_INSTRUCTIONS.md Add push and PyPI instructions 2026-03-05 13:56:02 +13:00
pyproject.toml Log per-write and per-command traces at DEBUG, release 0.2.1 2026-10-12 21:31:47 +02:00
README.md style: apply ruff format 2026-10-12 10:16:46 +02:00
ruff.toml Adopt shared ruff rule set (B, N, UP, SIM, C4) 2026-10-12 15:11:48 +02:00

py-nissan-leaf-obd-ble

Python hardware API for Nissan Leaf OBD-II over BLE dongles.

This library encapsulates the low-level BLE, ELM327 and CAN protocol handling used by the Home Assistant nissan_leaf_obd_ble integration, and exposes a simple async API for querying vehicle data from a BLEDevice.

It has no Home Assistant dependency and can be used in other Python applications that talk to the same BLE OBD dongle.

Installation

Once published on PyPI:

pip install py-nissan-leaf-obd-ble

Quickstart

import asyncio
from bleak import BleakScanner

from py_nissan_leaf_obd_ble import NissanLeafObdBleApiClient


async def main() -> None:
    # Discover your OBDBLE device with bleak, or obtain a BLEDevice from elsewhere
    device = await BleakScanner.find_device_by_address(
        "AA:BB:CC:DD:EE:FF", timeout=10.0
    )
    if device is None:
        raise RuntimeError("Could not find OBDBLE device")

    client = NissanLeafObdBleApiClient(device)
    data = await client.async_get_data()
    print(data)


if __name__ == "__main__":
    asyncio.run(main())

Configurable BLE UUIDs

The default GATT service and characteristic UUIDs match the LeLink OBD BLE dongle. When used with the Home Assistant integration, the service and read/write characteristic UUIDs are configurable per device in the UI. For custom use, async_get_data(options=None) accepts an optional options dict with keys service_uuid, characteristic_uuid_read, and characteristic_uuid_write; omit keys to use the library defaults.

Custom commands

async_get_data() accepts two optional parameters for adapting to different Leaf generations or adding new PIDs without modifying this package:

  • extra_commands — a dict[str, OBDCommand] that is merged with the default leaf_commands. Keys matching existing commands replace them; new keys are appended.
  • disabled_commands — a set[str] of command names to skip entirely.
from py_nissan_leaf_obd_ble import NissanLeafObdBleApiClient
from py_nissan_leaf_obd_ble.OBDCommand import OBDCommand


def my_decoder(messages):
    d = messages[0].data
    return {"ambient_temp": (d[3] - 40) * 0.5}


custom = {
    "ambient_temp": OBDCommand(
        "ambient_temp", "Ambient temperature", b"0322115e", 4, my_decoder, header=b"797"
    )
}

data = await client.async_get_data(extra_commands=custom, disabled_commands={"unknown"})

When called from the Home Assistant integration, extra_commands and disabled_commands are populated automatically from the user's overrides.yaml; see the integration README for details.

License

This package includes code derived from python-OBD (a derivative of pyOBD), licensed under the GNU General Public License, version 2 or later.

See LICENSE for full terms.