No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
tim 93b8afdad2
All checks were successful
Auto tag / Tag release (push) Successful in 2s
CI / Lint (push) Successful in 10s
Hassfest / Validate integration (push) Successful in 8s
Security / Security scan (push) Successful in 11s
Merge pull request 'pre-commit: ruff 0.17.5' (#11) from chore/ruff-0.17.5 into main
2026-11-20 11:38:37 +00:00
.forgejo/workflows Add auto-tag, forgejo-release and CHANGELOG (shared release flow) 2026-10-25 18:09:07 +01:00
custom_components Do not raise ConfigEntryNotReady when dongle is not yet visible 2026-10-15 12:00:06 +02:00
.gitignore fix: recover from hung BLE fetch so advert wakeups work again 2026-03-30 10:01:25 +13:00
.pre-commit-config.yaml pre-commit: ruff 0.17.5 2026-11-20 12:22:48 +01:00
CHANGELOG.md Add auto-tag, forgejo-release and CHANGELOG (shared release flow) 2026-10-25 18:09:07 +01:00
hacs.json first commit 2024-07-14 19:22:50 +12:00
README.md style: apply ruff format 2026-10-12 10:12:34 +02:00
ruff.toml Adopt shared ruff rule set (B, N, UP, SIM, C4) 2026-10-12 15:06:48 +02:00
setup.cfg first commit 2024-07-14 19:22:50 +12:00

Nissan Leaf OBD BLE — Home Assistant Custom Integration

hacs_badge GitHub Release License GitHub Issues

A Home Assistant custom integration for monitoring Nissan Leaf battery data via a Bluetooth Low Energy (BLE) ELM327 OBD-II adapter (such as the LeLink2).

When your Leaf pulls into the garage, this integration automatically connects over BLE and reads live battery diagnostics — state of charge, state of health, and more — making them available as native Home Assistant sensors for dashboards, automations, and history tracking.

Note: This integration is in active development. See Known Issues for current limitations.


Features

  • State of Charge (SoC) — real-time battery percentage
  • State of Health (SoH) — long-term battery degradation tracking
  • Battery capacity — available and total capacity in kWh
  • Communicates over Bluetooth Low Energy — no Wi-Fi or cloud dependency
  • Works with an ESPHome Bluetooth proxy (e.g. GL-iNet GL-S10), so your HA host doesn't need to be near the car
  • Uses a pure-Python BLE stack built on bleak — the same library bundled with Home Assistant

Requirements

Hardware

Item Details
LeLink2 ELM327 BLE OBD-II adapter Plugs into the Nissan Leaf's OBD-II port. Other ELM327 BLE dongles may also work.
Bluetooth radio Either the HA host's built-in Bluetooth, or an ESPHome Bluetooth proxy (recommended for garage setups).

Recommended setup: A GL-iNet GL-S10 flashed with ESPHome as a Bluetooth proxy placed in/near the garage. This lets your HA host (wherever it lives) receive BLE advertisements from the LeLink2 dongle without needing to be physically close.

Software

  • Home Assistant 2023.6 or later
  • HACS (for HACS installation)

Installation

  1. Open HACS in Home Assistant.
  2. Go to Integrations and click the three-dot menu (⋮) in the top right.
  3. Select Custom repositories.
  4. Paste the repository URL:
    https://github.com/pbutterworth/nissan-leaf-obd-ble
    
    and set the category to Integration. Click Add.
  5. Find Nissan Leaf OBD BLE in the HACS integration list and click Download.
  6. Restart Home Assistant.
  7. Go to Settings → Devices & Services → Add Integration, search for Nissan Leaf OBD BLE, and follow the setup wizard.

Option 2 — Manual

  1. Download the latest release or clone this repository.
  2. Copy the custom_components/nissan_leaf_obd_ble folder into your Home Assistant config/custom_components/ directory:
    config/
    └── custom_components/
        └── nissan_leaf_obd_ble/
            ├── __init__.py
            ├── manifest.json
            ├── config_flow.py
            ├── sensor.py
            └── ...
    
  3. Restart Home Assistant.
  4. Go to Settings → Devices & Services → Add Integration, search for Nissan Leaf OBD BLE, and follow the setup wizard.

Configuration

The integration is configured via the UI (Config Flow). You will be prompted for:

  • BLE device address — the MAC address of your LeLink2 / ELM327 adapter (e.g. AA:BB:CC:DD:EE:FF). You can find this in Settings → Devices & Services → Bluetooth after bringing the LeLink2 dongle within range.
  • Scan interval — how often (in seconds) to attempt a BLE connection and poll data when the device is detected.

After setup, open the device and click Configure to adjust polling intervals (fast / slow / extra-slow), cache behaviour (keep sensor values when out of range), and BLE UUIDs (service, read characteristic, write characteristic). Use the UUID options if your dongle uses different GATT UUIDs than the default LeLink ones; see Other dongles and automatic discovery below.


Other dongles and automatic discovery

Automatic Bluetooth discovery (when a device appears in HA’s “Discovered” list and this integration is suggested) is driven by the integration’s manifest. Home Assistant only offers this integration for BLE devices that advertise a service UUID listed in manifest.json under the bluetooth array. By default, only the LeLink service UUID (0000ffe0-0000-1000-8000-00805f9b34fb) is listed.

Using a dongle with different GATT UUIDs

  • You can still add the integration manually: Settings → Devices & Services → Add Integration → Nissan Leaf OBD BLE, then pick your device from the list (devices are filtered by local name “OBDBLE”). After adding, open the device, click Configure, and set the three BLE UUIDs (service, read characteristic, write characteristic) to match your dongle so the connection works.

Making automatic discovery work for another dongle

  • If your dongle advertises a different service UUID and you want it to show up in “Discovered” for this integration, you can manually edit the integration’s manifest.json after installation:
    1. Open config/custom_components/nissan_leaf_obd_ble/manifest.json on your Home Assistant host.

    2. Add another object to the bluetooth array with your dongle’s advertised service_uuid. Example:

      "bluetooth": [
        { "service_uuid": "0000ffe0-0000-1000-8000-00805f9b34fb" },
        { "service_uuid": "YOUR_OTHER_DONGLE_SERVICE_UUID" }
      ]
      
    3. Restart Home Assistant so discovery picks up the change.

  • Note: HACS or a manual update of the integration may overwrite manifest.json; you may need to re-apply this edit after updating unless multiple UUIDs are added to the integration in a future release.

Entities

Once set up, the integration creates a device for your Nissan Leaf and exposes the following sensor entities:

Entity Unit Description
sensor.nissan_leaf_state_of_charge % Current traction battery charge level
sensor.nissan_leaf_state_of_health % Battery health / degradation indicator
sensor.nissan_leaf_battery_capacity kWh Available (usable) battery capacity

More entities may be added as the integration matures. See open issues and the HA Community thread for the latest status.


How It Works

The LeLink2 dongle tunnels the ELM327 serial protocol over BLE GATT. This integration includes a custom bleserial module that wraps Home Assistant's bundled bleak client to expose a pySerial-like interface. On top of that, a modified python-OBD layer handles ELM327 command formatting, ISO 15765-4 CAN framing, and flow control — producing decoded Leaf-specific PID responses that are then published as HA sensor states.

Nissan Leaf CAN bus
        │
  OBD-II port
        │
  LeLink2 dongle  ◄──── BLE ────►  ESPHome Bluetooth Proxy  ◄──── Wi-Fi ────►  Home Assistant
                                          (GL-S10)                               nissan_leaf_obd_ble

Overriding OBD Commands and Decoders

Different Nissan Leaf generations and trim levels use different OBD PIDs and message formats. Rather than waiting for a new package release, you can override any command directly in your Home Assistant config directory.

Quick start

Create the file config/custom_components/nissan_leaf_obd_ble/overrides.yaml. Restart Home Assistant (or reload the integration) for changes to take effect.

overrides.yaml format

Top-level keys are BLE device MAC addresses (upper-case). Use _all_ to apply overrides to every Nissan Leaf config entry in your HA install.

# config/custom_components/nissan_leaf_obd_ble/overrides.yaml

_all_:                          # applies to every Leaf instance
  commands:
    ambient_temp:
      command: "0322115e"       # replace the PID; keeps the built-in decoder

DC:0D:30:AA:BB:CC:              # applies only to this BLE address
  commands:

    # Change the scale factor for the 12V battery voltage reading
    bat_12v_voltage:
      decoder:
        type: linear_scale
        byte_offset: 3
        scale: 0.1

    # Add a completely new sensor not in the default set
    hv_charger_temp:
      command: "03221299"
      header: "797"
      bytes: 4
      decoder:
        type: linear_scale
        byte_offset: 3
        scale: 0.5
        offset: -40.0
      sensor:                   # HA entity metadata (required for new commands)
        name: "HV Charger Temperature"
        unit: "°C"
        device_class: temperature
        state_class: measurement
        icon: "mdi:thermometer"
        precision: 1

    # Skip a command entirely (e.g. one that causes issues on your model)
    unknown:
      enabled: false

Any field you omit inherits from the built-in definition. You only need to specify what changes.

Supported decoder types

Type Required fields Optional fields Description
linear_scale byte_offset scale (default 1.0), offset (default 0.0) value = data[byte_offset] * scale + offset
multi_byte_int byte_start, byte_end signed (false), byte_order (big), scale, offset int.from_bytes(data[start:end]) then scale
struct_unpack format, byte_start, byte_end scale, offset struct.unpack(fmt, data[start:end])[0] then scale
lookup byte_offset, values default Map byte value → string via a dict
bit_flag byte_offset, bit_mask — (data[byte_offset] & bit_mask) == bit_mask → bool
equality byte_offset, value — data[byte_offset] == value → bool
multi_field fields (list of sub-specs) — Runs each field's sub-spec; returns a merged dict
python function — Calls a named function from decoders.py (see below)

Python escape hatch

For decoders too complex for YAML templates (e.g. multi-step bit manipulation across many bytes), you can write a Python function instead.

Create config/custom_components/nissan_leaf_obd_ble/decoders.py alongside overrides.yaml:

# config/custom_components/nissan_leaf_obd_ble/decoders.py


def my_lbc_decoder(messages):
    d = messages[0].data
    soc = int.from_bytes(d[33:36], "big") * 0.0001
    health = int.from_bytes(d[30:32], "big") / 102.4
    return {"state_of_charge": soc, "hv_battery_health": health}

Then reference the function in overrides.yaml:

DC:0D:30:AA:BB:CC:
  commands:
    lbc:
      decoder:
        type: python
        function: my_lbc_decoder

The module is loaded once when the integration starts. Any errors during loading or in function lookups are reported in the HA log.


Troubleshooting

The integration can't find my LeLink2 adapter

  • Confirm the dongle is plugged in and powered (ignition on or accessory mode).
  • Check Settings → Devices & Services → Bluetooth in HA to verify the adapter is advertising.
  • If using an ESPHome Bluetooth proxy, ensure it's online and the proxy component is enabled.

Sensors show unavailable after the car leaves

  • This is expected behaviour. The integration only polls when the BLE device is in range.

No data / sensors stuck

  • Enable debug logging and check the HA logs for custom_components.nissan_leaf_obd_ble:
    # configuration.yaml
    logger:
      default: warning
      logs:
        custom_components.nissan_leaf_obd_ble: debug
    
  • Share logs in the HA Community thread or open an issue.

Known Issues

  • The integration is under active development and may have rough edges.
  • Newer Nissan Leaf models (ZE1 / Gen 2 onwards) do not have background CAN traffic at the OBD port — the car must be on for data to be polled.
  • Only the LeLink2 BLE adapter has been tested; other ELM327 BLE adapters may work but are untested.

Contributing

Contributions are very welcome! Please:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/my-new-sensor).
  3. Commit your changes and open a Pull Request.

Bug reports and feature requests can be filed as GitHub Issues.



License

This project is licensed under the MIT License.