Nissan Leaf Component(s)/Platform

Firstly you need to install ‘SSH & Web Terminal’, go to Supervisor, Add-on Store. In the section named ‘Home Assistant Community Add-ons’ you will find the ‘SSH & Web Terminal’. Install that add-on and make sure that in the info section ‘Protection mode’ is OFF, also turn on ‘Show in sidebar’

The above may require restarts, I’m not sure.

Next in the sidebar you should have ‘Terminal’

Open this up and this is where we need to access the docker.

  • type docker exec -it $(docker ps -f name=homeassistant -q) bash
  • type cd /usr/local/lib/python3.9/site-packages/pycarwings2/
  • type vi pycarwings2.py
  • go down to line 125
  • change to headers={"User-Agent": ""}
  • to exit and save vi use :x then enter.

This is basically @andbad instructions rehashed and in one place.

Good Luck and always back up first.

Edit: I fixed an important typo !!
Second Edit: Changed to python3.9

2 Likes

I got the reply for the cd command: no such file or directory: /usr/local/lib/python3.8/site-packages/pycarwings2/

Basically this was my original problem, that i was unable to find pycarwings anywhere in my system.

Odd, have you tried to cd your way in one level at a time?

cd /usr
cd local
cd lib
cd python3.9
cd site-packages
cd pycarwings2

If you get stuck on the way, type ls and that will list the contents of the directory you’re in presently, this may show where you are going wrong.

HTH

Edited to change python3.8 to 3.9 due to Core update.

I followed it step by step, and found this:
At /usr/local/lib there is no python3.8 folder
image

I found the python folder elsewhere with the site-packages also, but there is no pycarwings2 in the site-packages.
/usr/lib/python3.8/site-packages
image

Sorry, but you MUST type in the first line … (please check out the P.S)

docker exec -it $(docker ps -f name=homeassistant -q) bash

After that, the prompt should say bash-5.0#

jim

Good Luck :slight_smile:

PS. Also just noticed that the ‘docker’ line that I gave you earlier had a typo, now fixed. Sorry.

Yaaay! Success! Thank you very much! :slight_smile:

1 Like

Trying the docker exec -it $(docker ps -f name=homeassistant -q) bash . But it keeps saying “bash: docker: command not found”. What do I do wrong?

Are you using the correct Terminal?

Did you follow the first part of my post here?

You should be installing this … SSH & Web Terminal

screenshot

Other than that, I have no idea :frowning:

1 Like

Thank you so much. I used the standard SSH & Terminal, that is why it didn’t work. Now my Leaf integration is working again. Once again, thanks

Yess it worked for me. Thanks a lot for the SSH course :slight_smile:

Strange. I did the fix and now after 2 days the Nissan Leaf integration stoped again. And after a reboot it worked again.

Sometimes happens. It’s due to Nissan server problem.

By(t)e

Thought I would add to this, after forking the brilliant work done by @Sriracha.

Here’s my forked leaf2mqtt: https://github.com/mitsumaui/leaf2mqtt

I have modified this to fix up some bugs, and add location tracking. Also provided some clarification on the documentation to configure device_tracker / climate in Home-Assistant.

Feel free to feedback, although I am no expert in dart/flutter development I will do my best. I am currently trying to extend this to collect cockpit information (mileage).

Another bonus is that a docker container image is being automatically published and can be installed without building:

docker pull ghcr.io/k8s-at-home/leaf2mqtt:latest

There’s also a helm chart for those running kubernetes:

helm repo add k8s-at-home https://k8s-at-home.com/charts/
helm repo update
helm install leaf2mqtt k8s-at-home/leaf2mqtt
2 Likes

I had a similar problem: no python3.8 directory. However there was a directory python3.9 which contained the expected subdirectories and the file to edit.

In case other people are also suffering from no car status update, error 408.

I see there had been a recent merge.

So I decided to test it out by replacing the file in question, with the updated one from github. The file is located here in HA OS homeassistant container:
/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py

I haven’t driven the car yet, but forced updates no longer give me any error messages.

Just need the upstream pycarwings2 package to merge the start-up 404 error fix now…

edit: still giving me error 408.

Edit 2: It IS working, gives me 408 error from time to time, but car battery does get updated eventually.

This worked brilliantly. Thanks

It has been released with core-2021.8.0. Will test it shortly

EDIT: :sleepy:

Logger: pycarwings2.pycarwings2
Source: /usr/local/lib/python3.9/site-packages/pycarwings2/pycarwings2.py:164
First occurred: 19:37:56 (1 occurrences)
Last logged: 19:37:56

carwings error INVALID PARAMS: 404
2021-08-04 19:37:56 ERROR (SyncWorker_2) [pycarwings2.pycarwings2] carwings error INVALID PARAMS: 404

2021-08-04 19:37:56 ERROR (SyncWorker_2) [homeassistant.components.nissan_leaf] An unknown error occurred while connecting to Nissan: <class 'pycarwings2.pycarwings2.CarwingsError'>

Yep, the 2021.8 changelog lists that change. It’s working for me without editing the file I specified in the earlier post. Still throws status 408 error but at least the battery reading is updated pretty much every hour as programmed.

You are seeing the common “invalid params” error. You need to go into HA dependency code and change a line.

See here, use python3.9 instead of 3.8.

This integration had been working for me, then it stopped working out of the blue and i’ve been banging my head off the wall with this for weeks, getting that INVALID PARAMS: -2010 error over and over again…

So this morning, after trying every combination of username & password, double checking them by signing out and back into the Leaf app and in the EVA app, but it didn’t make any difference - i knew the credentials were correct. Then i thought “i better log in to nissanconnect.eu just to make absolutely sure the credentials are correct…” and the HA integration started working again.

Coincidence?

Same for me. Up until (I think) yesterday morning, it worked by editing the pycarwings2 file like instructed a few posts back, but now it’s down.