BLE (LELink2) / leaf open-source libraries

My Nissan Leaf Forum

Help Support My Nissan Leaf Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

LeafAutomator

New member
Joined
Apr 19, 2023
Messages
1
I would like to implement an extension for Home Assistant ( an opensource home Automation solution) that communicates with the LeLink2 as my Leaf returns home, to at least capture the current battery charge.
This could then trigger automations/ show on dashboards the state of charge.
Are there any opensource libraries that implement the communication with a Lelink over BLE?
I understand the BLE turns off a few minutes after the car is turned off.
 
I would like to implement an extension for Home Assistant ( an opensource home Automation solution) that communicates with the LeLink2 as my Leaf returns home, to at least capture the current battery charge.
This could then trigger automations/ show on dashboards the state of charge.
Are there any opensource libraries that implement the communication with a Lelink over BLE?
I understand the BLE turns off a few minutes after the car is turned off.
I don't have any experience with the LeLink2, but those metrics you mention are certainly available on the CAN bus and readily decodable using pulicly known methods. It should definitely be possible to extract them to your HA system in various ways :)

The way that I'm doing it is with an MCP2515 CAN board and an ESP32 microcontroller with wifi. I use OpenHab in the role that you use Home Assistant but otherwise similar ideas, ie presence detection when the device is near home, automatically obtaining and logging current SoC and odometer reading upon arrival back, and controlling the EVSE's own power supply to enable limiting vehicle charge to presets (eg 75%).

One thing to keep in mind when using an OBD solution is that unlike the *ZE0 models, in the ZE1 Leaf there is no CAN bus background traffic to monitor at the OBD - you have to bridge on to one of the 3 CAN busses elsewhere in the car to get that (ie downstream of the CAN gateway). If you're working with an older model then it's no problem as all the CAN traffic is right there at the OBD connector. It can still be done at the OBD on the ZE1 too, but your micro has to constantly poll the ECUs instead of just sniffing the background traffic, and that's an order of magnitude more work to implement.
 
I would like to implement an extension for Home Assistant ( an opensource home Automation solution) that communicates with the LeLink2 as my Leaf returns home, to at least capture the current battery charge.
This could then trigger automations/ show on dashboards the state of charge.
Are there any opensource libraries that implement the communication with a Lelink over BLE?
I understand the BLE turns off a few minutes after the car is turned off.
I am documenting my progress here:
https://mynissanleaf.com/threads/my-nissan-leaf-2021-obd2-elm327-bluetooth-adventure.35042/

I now have a trace of what Leaf Spy Pro is doing, so it should be relatively straight-forward (but "hard" work) from here.
 
This would be very neat, to get just Leaf battery SOC from the BLE OBD adapter in the car. I have an old android tablet in the garage as a dashboard, and it would be great to get that data into the rest of the controls for my home power system. I got an OVMS way back but never got around to setting it up. The home power system controls the EVSE charge rate, mostly to consume excess solar.
 
I thought I would wade into the discussion:
@pmbdk have you made any further progress?

I've started working on this myself. I have a ZE1 Leaf and a LeLink OBD dongle. I would love to go the OVMS route, but I baulked at the cost of the module. Maybe one day.

So far I've built a python module that wraps a bleak client (Home Assistant uses bleak) to have an interface similar to pySerial (LeLink tunnels the ELM327 over BLE GATT). Then I've adapted python-OBD to use my ble-serial module (since it was using pySerial).

This should handle most of the ISO 15765-4 CAN (11 bit ID,500 Kbaud) protocol with flow control, framing etc. Currently testing this.

Next step is to write the commands and decoders for the Leaf messages.

And then, write a home assistant custom component to wrap in into HA. I'm hoping this part will be fairly straightforward since I've done it once before (https://github.com/pbutterworth/astralpool_chlorinator). There will no doubt be some head scratchers here since the peripheral device (car) will only be sparsely available and HA doesn't like unavailable entities. But anything is possible.

Any assistance is vastly appreciated.
 
I thought I would wade into the discussion:
@pmbdk have you made any further progress?

I've started working on this myself. I have a ZE1 Leaf and a LeLink OBD dongle. I would love to go the OVMS route, but I baulked at the cost of the module. Maybe one day.

So far I've built a python module that wraps a bleak client (Home Assistant uses bleak) to have an interface similar to pySerial (LeLink tunnels the ELM327 over BLE GATT). Then I've adapted python-OBD to use my ble-serial module (since it was using pySerial).

This should handle most of the ISO 15765-4 CAN (11 bit ID,500 Kbaud) protocol with flow control, framing etc. Currently testing this.

Next step is to write the commands and decoders for the Leaf messages.

And then, write a home assistant custom component to wrap in into HA. I'm hoping this part will be fairly straightforward since I've done it once before (https://github.com/pbutterworth/astralpool_chlorinator). There will no doubt be some head scratchers here since the peripheral device (car) will only be sparsely available and HA doesn't like unavailable entities. But anything is possible.

Any assistance is vastly appreciated.
I’m very happy to see someone doing this, my geek coder is being deactivated.

Drop links to your work on GitHub if you can.
 
The BT proxy is easier than you might think. Especially if you buy one of these (Aliexpress).
And then go to here (esphome) and follow the instructions.
Thanks. I've already built and flashed several ESPHome projects. The part I anticipated as being a "bit complicated" was the software/configuration side. My OpenEVSE unit arrives today, so this is something that I hope to get set up in the near future. Too bad about having the extra step of turning the ignition on without stepping on the brake in order to get readings throughout the charge process, but I figure if I can pick up the starting SoC when the car arrives, I ought to be able to use that to derive a charging progress in HA.

Sure appreciate you sharing your work, and the reply here!
 
Back
Top