Nissan Leaf Component(s)/Platform

I’m currently working on a component to integrate with the Nissan Leaf CarWings/Nissan Connect API, providing battery charge, turning on charging (but not off, they don’t support that…), turning climate control on/off, etc.

Github Repo is here, for anyone who wants to follow/contribute: https://github.com/BenWoodford/home-assistant/tree/nissanleaf

WARNING: I don’t know how often this will poll your Leaf right now, so you’ve been warned. If you kill your 12V, I accept no responsibility.

UPDATE

The following components are available:

  • Leaf Charge % (Numeric Sensor)
  • Plugged In State (Binary Sensor)
  • Range with AC Off (Numeric Sensor)
  • Range with AC On (Numeric Sensor)
  • Charging Status (Switch)
  • Climate Control (Switch)

You can’t turn charging off, as per the API. Best to integrate your home charger for that.

Range abides by the unit system in your HASS config, so metric or imperial. You can force it to miles using force_miles: true though

The config block is as follows:

nissan_leaf:
    username: <username/email>
    password: <password>
    region: <region> (see below)
    nissan_connect: <true/false> (optional, defaults to true)
    update_interval: <minutes> (see below, default is 30)
    update_interval_charging: <minutes> (default is 15)
    update_interval_climate: <minutes> (default is 5)
    force_miles: true

Notes

Region: This must be one of: “NNA” (USA), “NE” (Europe), “NCI” (Canada), “NMA” (Australia) “NML” (Japan). I have only tested this component in Europe.

Nissan Connect: If your car has the updated head unit (Nissan Connect rather than Car Wings) then you can pull the location, which will be added as a device tracker in the future. If you have a pre-2016 24kwh Leaf then you will have CarWings and should set this to false or it will crash the component.

Interval: This is the interval in minutes to poll the car. The lower this is, the higher the risk to your 12V battery - if it dies, that’s on you. A 30 minute poll should be fine and not cause any battery distress, unless you’re leaving it unplugged and sat idle for weeks on end which is a pretty silly thing to do anyway. You’ve also got intervals for when charging and when climate control is on - don’t be silly with these, 1 or 2 minutes will likely queue them up before they finish.

Reporting Bugs

Please use the following logger config when reporting issues, there is a lot of info under the debug level that can be useful.

logger:
  default: critical
  logs:
    homeassistant.components.nissan_leaf: debug
    homeassistant.components.sensor.nissan_leaf: debug
    homeassistant.components.switch.nissan_leaf: debug
6 Likes

I had a version of this working a while back but got stuck on the async issues. I’ve just found my code. Would love to get this working with you, currently I’m using the https://github.com/glynhudson/leaf-python-mqtt hack to get HA to understand my leaf.

Ideal for me would be:

  1. Sensors to detect the battery status, charging status, connection status and climate control status
  2. Service to start charging
  3. Service to turn on/off climate control
  4. Device tracker for location

I’ll make some comments in your repo if that’s Ok.

p.s. you’ll love your leaf! I do!

1 Like

That’s the plan! Until I get the Leaf in a week I’m stuck so waiting on that. Wouldn’t a switch cover both status and on/off for the climate control? I’ll double check the climate status but I don’t think it shows current temperature or anything does it?

Fair shout on plugged in status though! Device location I’m storing in the main platform component but haven’t started work on yet

I was writing an app in swift that would do this too. I also got stuck on asych issues as I haven’t really done anything in swift before.

Supposedly, some people have been getting emails from Nissan saying the nissanconnect service is about to get a really nice new app. I’m wondering if Nissan’s changes will also make our work here obsolete like the switch from XML to JSON. We might have to start over.

Yeah there’s a new app on the horizon soon, and they’ll be changing things to support multiple cars too. Once I’ve got this working as a basic level I’ll move to supporting multiple cars in preparation. It should then just be a case of moving to the new API. As the main platform component handles everything involving talking to Nissan it should be the only one that needs modification… hopefully.

But yeah, I’m aware of the changes that are going to be made. The 2.ZERO is starting to ship soon so we should be getting the new app relatively soon too. Dealers have a training session this week I believe, and hopefully they’ll be told the date for the new app then too.

I called in an asked about the apple watch app a while ago when they had the promotional material on their website. They told me it would only work on newer leafs, so I began work on my app.

Then it seems it will work on all leafs (as it should) so here I am with one step in my app I’ve ben stuck on for two weeks, and the email gos out saying “coming soon…”

No, I’m not bitter at all.

The confusion regarding the new app is real.

Supposedly we aren’t getting the Alexa skill in the UK, only the US and Canada get it. And we apparently don’t have to pay a subscription fee either… it’s all very weird and confusing

Saw post on r/leaf and I would love to look at this component this weekend. So do I just need to copy the leaf component code, sensor, and switch code to the same location as your Home Assitant branch? It looks like it downloads pycarwings2 from your Github account. I am pretty computer savvy, but I have only started to play with Python. I have used Perl a lot in the past, but I am very motivated to help with testing and maybe code once I understand more about Hass component programming.

You won’t find it terribly useful just yet, I’m afraid. It’s also setup to reference the components using the internal component namespace rather than the custom one so you’d need to modify that. And it doesn’t actually update the states yet :slight_smile: working on that one though

Good news!

It now works for monitoring, the switches don’t do anything but I’m working on those too. I’ve updated the OP with info.

Awesome progress! Been watching your updates and trying to learn about python/component/github as I do.
I think I have made things difficult on myself by having a Hass.io setup, so I am not sure I can install it without it being part of a repository like this example by notoriousbdg . Seams to be a system that describes where the files go and where they should store data. I might take one of my extra microSD cards and create a dev copy of my Home Assistant using the old Pi setup system. Thank you so much for your work on this.

I don’t use HASS.io so I can’t be much help I’m afraid! The repo you linked is for addons which are additional Docker containers, rather than for components. I think you need to enable the SSH or Samba addon which will then let you modify the config (and add custom components)?

In other news, the switches now work! Turned my heater on via Alexa yesterday, as a smart home device instead of having to address the skill directly.

I’ve just updated the repo to include smart-intervals. You can now set update_interval_charging and update_interval_climate to have shorter polling when it’s charging or climate control is on.

Mostly put this in because I’d turn CC on before going shopping, and HASS would still think it was on when I was done.

I’e also moved the plugged in status to a binary sensor, and added “Nissan” and “Leaf” as default manufacturer/model for homebridge, as well as the VIN for the serial.

Enjoy!

I’ve submitted the component as a PR for Home Assistant, so if anyone is able to test it before it gets merged in I’d be eternally grateful.

Also need someone with a newer Leaf who can develop the device tracker

I think I can get this onto my hass.io install tonight. I have a leaf with location (2016). Not so oddly, the official app update broke location, but it works with Leaf Manager.

1 Like

Here is a cool update on Ben’s work. Ben has updated it so that it correctly reads new Nissan Connect version for 2016 (and I think 2017) models. I have included some screenshots of the module working with my test version of Home Assistant. Tomorrow I plan to test having it turn on the pre-heat for my car when my sees my phone leave the wifi near my work desk, and it is after 3:30pm.
11%20PM

Leaf_switches

Great work @BenWoodford !

So I implemented the device tracker and added a pull request to your branch, please pass it on to the PR if you wish. It’s tested locally using a hass.io setup and a Nissan Leaf 2016.

You can find the pull request here: https://github.com/BenWoodford/home-assistant/pull/1/files

I’m using Hass.io and have got this to run as a custom_component. @BenWoodford is correct, easiest way in hass.io to add a component is to first install the hassio addon for Samba, then in you ‘config’ folder add a ‘custom_components’ folder where you put your component files. simply copy them here.
Be careful though with your library references,
to reference a built in component you would use ‘homeassistant.components.<component_name>’ and for a custom component the same would be ‘custom_componetns.<component_name>’.

I changed the library references in the binary_switch, switch, sensor, device_tracker files to have them reference the custom_components/nissan_leaf.py correctly.

Hope this helps!

Awesome. That I understood, and with hass.io backups I don’t have to worry if I really trash something. That makes things much easier because I am working the device tracker now and I did not want to even attempt to merge my additions until I had tested it with my Leaf.

Thanks for the help!

Hey, Since you have a 2016 Leaf that can report its location would you want to work together on testing that function. On a side note, how is the SOH on your 30kWr battery? Mine is down to 80% at 25K miles.