Monitoring Your Nissan Leaf Battery with Lelink OBD2 and ESPHome: Seeking Reliable Connection

Monitoring the battery health of your Nissan Leaf can be crucial, especially for understanding its long-term performance and range. For those looking to integrate this data into their smart home systems, using an OBD2 dongle with ESPHome offers a promising avenue. This article delves into a user’s experience attempting to set up battery monitoring for a Nissan Leaf using a Lelink2 BLE OBD2 dongle and an ESPHome Bluetooth gateway, highlighting the challenges faced and exploring potential solutions.

The Initial Setup and Bluetooth Connectivity Hurdles

The user’s goal was straightforward: to capture the Nissan Leaf’s battery state using readily available components. The chosen hardware included a Nissan Leaf, a Lelink2 BLE OBD2 dongle (based on ELM327), and a GL-S10 ESPHome Bluetooth gateway. Leveraging ESPHome’s built-in BLE capabilities, an initial configuration was established.

The ESPHome configuration aimed to connect to the Lelink OBD2 dongle via Bluetooth Low Energy (BLE) and send AT commands to retrieve data. The configuration snippet below illustrates the initial approach:

ble_client:
  - mac_address: B4:99:XX:XX:XX:XX
    id: lelink
    name: LELink BLE OBDII
    on_connect:
      then:
        - lambda: |-
            ESP_LOGI("ble_client_lambda", "Connected to lelink");
    on_disconnect:
      then:
        - lambda: |-
            ESP_LOGI("ble_client_lambda", "Disconnected from lelink");

text_sensor:
  - platform: ble_client
    ble_client_id: lelink
    internal: True
    notify: True
    name: "lelink leaf response"
    id: lelink_leaf_response_text
    service_uuid: "0000ffe0-0000-1000-8000-00805f9b34fb"
    characteristic_uuid: "ffe1"
    on_notify:
      then:
        - lambda: |-
            ESP_LOGI("ble_client_lambda", "notify from lelink_leaf");

interval:
  - interval: 30s
    then:
      - logger.log:
          level: INFO
          format: "Sending ATZ"
      - ble_client.ble_write:
          id: lelink
          service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
          characteristic_uuid: ffe1
          # List of bytes to write.
          value: [0x41, 0x54, 0x5A, 0x0D, 0x0A] #ATZrn

This configuration was designed to send the “ATZ” command (a common command to reset ELM327 devices) every 30 seconds and listen for responses from the Lelink dongle. Testing with BLE tools on a smartphone confirmed that sending “ATZ(cr)(lf)” as an ASCII byte array to the Lelink dongle yielded the expected “OBDII v1-5 >” response.

Inconsistent Data and the Search for Robustness

However, when implementing this setup with ESPHome, the results were inconsistent. While some data was received, it was not reliable, and the expected “OBDII v1-5 >” response was not consistently obtained. The logs showed fragmented and incomplete responses, indicating potential issues with data transmission or handling.

[15:53:44][I][main:171]: Sending ATZ
[15:53:44][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP >'
[15:53:45][I][ble_client_lambda:140]: notify from lelink
[15:53:46][D][text_sensor:067]: 'lelink response': Sending state 'A'
[15:54:14][I][main:171]: Sending ATZ
[15:54:14][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP '
[15:54:14][I][ble_client_lambda:140]: notify from lelink OBDII v1.'
[15:54:15][I][ble_client_lambda:140]: notify from lelink >'
[15:54:15][I][ble_client_lambda:140]: notify from lelink
[15:54:44][I][main:171]: Sending ATZ
[15:54:44][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
[15:54:44][D][text_sensor:067]: 'lelink response': Sending state 'AT'
[15:54:44][I][ble_client_lambda:140]: notify from lelink '
[15:54:44][I][ble_client_lambda:140]: notify from lelink >'
[15:54:45][I][ble_client_lambda:140]: notify from lelink
[15:54:46][D][text_sensor:067]: 'lelink response': Sending state 'A'
[15:55:14][I][main:171]: Sending ATZ
[15:55:14][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
[15:55:14][D][text_sensor:067]: 'lelink response': Sending state 'AT'
[15:55:14][I][ble_client_lambda:140]: notify from lelink '
[15:55:14][I][ble_client_lambda:140]: notify from lelink >'
[15:55:15][I][ble_client_lambda:140]: notify from lelink

This inconsistency raises questions about the reliability of the BLE connection in this specific context. The user is now considering developing a custom C++ component for ESPHome to potentially achieve more robust communication with the Lelink OBD2 dongle.

Exploring the Best Approach for Reliable OBD2 Data

The question remains: what is the most effective approach to ensure reliable data retrieval from a Lelink OBD2 dongle connected to a Nissan Leaf using ESPHome? While the built-in BLE tools offer a starting point, the observed inconsistencies suggest that further investigation and potentially a more tailored solution are needed. Exploring a custom C++ component could provide greater control over the BLE communication and data handling, potentially leading to a more stable and dependable system for monitoring Nissan Leaf battery data. Further community insights and experiences with similar setups would be invaluable in determining the optimal path forward.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *