Nissan Leaf Component(s)/Platform

Have you checked whether or not your MQTT broker is receiving messages?

I’ve found the problem now, sods laws near immediately after posting, I’ve modified the below to use a username and password. I could see connections being made to the broker on HASS but nothing happening so guessed it could be having a problem transmitting the data.

retdict.forEach((k, v) => print('mosquitto_pub -r -h ${host} -t "${topic}/${vin}/${k}" -m "${v}"'));

TO

retdict.forEach((k, v) => print('mosquitto_pub -r -h ${host} -u <USERNAME> -P <PASSWORD> -t "${topic}/${vin}/${k}" -m "${v}"'));

OK. The page says “You must have a working MQTT server on your LAN that is not password-protected.” — the username and password are your Nissan app details. If your broker has a username and password, then yes, your changes are necessary.

Next time I do an update I’ll include an MQTTUSERNAME and MQTTPASSWORD to allow for this. UPDATE: this is now done.

Is it working now?

1 Like

Yes thankyou, as I say I’m new to this and only setup an MQTT server yesterday.

It’s working great though, really appreciate your work.

image

1 Like

Unfortunately this doesn’t change anything. I’ve rebooted several times past few days. But the error keeps popping up.

2021-01-16 10:41:52 ERROR (SyncWorker_1) [pycarwings2.pycarwings2] carwings error INVALID PARAMS: -2010

2021-01-16 10:41:52 ERROR (SyncWorker_1) [homeassistant.components.nissan_leaf] An unknown error occurred while connecting to Nissan: <class ‘pycarwings2.pycarwings2.CarwingsError’>‘

Do you know anything else I can try?

Oops, wrong action

Hi Troon

Your idea of running a docker container is really great !
So I follow the steps you describe on github to create the image but I think there was an error like

7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 4259 kB of archives.
After this operation, 10.2 kB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command ‘/bin/sh -c apt-get upgrade’ returned a non-zero code: 1

The folder leaf2mqtt has been created inside my docker folder, then I cd to there and run the ./image-build.sh command.
The result was a unbuntu:20.10 image and container plus another container (random named, ni image) that refuse to start.
Should I have first replace MY_VIN before building the image ?

What am I missing ?

I see climate switch issue has been posted to github. The climate switch works in automations and scripts. So here is what I use as a work around.

  alias: leaf_start_climate
  description: ''
  trigger: []
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.leaf_climate_control
  - delay: 00:03:00
  - service: automation.trigger
    data: {}
    entity_id: automation.leaf_update


  alias: leaf_update
  description: ''
  trigger: []
  condition: []
  action:
  - service: nissan_leaf.update
    data:
      vin: xxxxxxxxxxxxxx

I think my Dockerfile was missing the -y flag on the apt upgrade command that aborted for you. Please try either from scratch (I have updated on Github) or manually edit your Dockerfile so that the third line reads

RUN apt-get upgrade -y

The MY_VIN only needs replacing once you’ve got the MQTT feed working and want to create the sensors.

Thanks for your answer Troon !
Exact, the - y flag was missing !
Give it a try right now and tell you the result.
Many thanks again

Edit : container up and running !!! Cool !!! Thanks for yourhelp

Troon, it’s me again !

Help needed for those parts

  1. MQTTTOPIC : I set this to leaf and you should too unless you have a good reason not to
  2. MQTTHOST : LAN IP address of your MQTT broker.
  3. USERNAME : your NissanConnect username — the one you use to log into the app.
  4. PASSWORD : your NissanConnect password — the one you use to log into the app.

Where to add this ? Sorry, I’m an old noob man…

You need to set these environment variables in your Docker container run statement. If you run from the command line, something like this:

sudo docker run --rm --env USERNAME=[your username] --env PASSWORD="[your password]" --env MQTTHOST="[IP address]" --env MQTTTOPIC="leaf" leaf2mqtt

:+1:

You rock !

:metal:

Excellent job !
I’ll follow your work carefully
Last question (atm…), do you know if the Dart library is avalaible in french ? (meaning km instead of miles ) ?

The library I’m using is here. It does also provide values in kilometres, but it’d probably be easier just to set up some template sensors in Home Assistant:

- platform: mqtt
  name: LEAF GOM
  state_topic: "leaf/MY_VIN/GOM"
  value_template: "{{ value.replace(' mi', '') }}"
  unit_of_measurement: "mi"

- platform: template
  sensors:
    leaf_gom_km:
      friendly_name: "GOM en km"
      unit_of_measurement: "km"
      value_template: "{{ (states('sensor.leaf_gom')|float * 1.61)|round(0) }}"

I will try your easiest method.
It’s nice to have such knowledge, I’m jealous :wink:

Learned simply through experience, it’ll come. Just try to understand all the code you see and use a bit at a time. I’m envious of your ability to keep up in another language!

:laughing:

Regarding to me, it’s easier to understand your language instead of this one {{ (states(‘sensor.leaf_gom’)|float * 1.61)|round(0) }}

Many thanks again

Here’s the result.
Thanks to your help !

1 Like

Since I upgraded from 2021.1.4 to 2021.1.5, the leaf integration logs the error “carwings error INVALID PARAMS: -2010”
and the leaf entities are no longer available.
The official app works correctly.
Anyone else has this issue recently?

Also, here is my EVs dashboard if anyone is interested:

Obviously the leaf one is broken because of the error :frowning:

If anyone is curious about the datetimes on the right, They are: Leaf departure time, Leaf climate start time and Leaf charge time.
I made a tasker shortcut on my phone that presents me with a clock on which I set the time of departure for the next day. I have multiple automations that will take that and calculate the time it takes to charge to 80% using the last 5 days as a mean. Then it will start the charge at the right time and start climate if it is cold outside 30 minutes before departure. The automations will smoothly flash my bedside light when I go to sleep if I forgot to set the time.
It worked very well until now.