Nissan Leaf Component(s)/Platform

For an AZE1 new-shape LEAF, you could try my solution or @Sriracha’s fork. Not a full integration, but works well here.

2 Likes

I have this problem again.
I resolve in the same way of previous time. I edited the file
homeassistant/lib/python3.8/site-packages/pycarwings2/pycarwings2.py

at line 125:
headers={"User-Agent": "pycarwings2/2.10"}

with this:
headers={"User-Agent": ""}

By(t)e

4 Likes

@filcole Hi mate, it looks like the Nissan Leaf Integration has been borked again with the latest core-2021.5.5 update. Would you be able to take a look at it please?

Logger: pycarwings2.pycarwings2
Source: /usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py:164
First occurred: 6:40:30 PM (1 occurrences)
Last logged: 6:40:30 PM

carwings error INVALID PARAMS: 404

@andbad has a fix in the above post.

Thanks etc. :slight_smile:

Thank you! This fixed it.

For people using Container based install (OS, supervised, Docker), the file path is:
/usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py

For supervised and Docker, use this command to get into HA Core Container to get at the file:
docker container exec -it homeassistant bash

2 Likes

I have the same problem using Home Assistant OS on a Raspberry Pi with core-2021.5.3
Been struggling to get to file. Is there a way to edit the file on my setup?

I use the Leaf data to always charge the car to 70% overnight in low tariff. If I need the car, I set a departure percentage, day and time and the automation will top up the car if needed and activate climate control just before I am leaving.
I just realize now how much I love this automation, now it is broken.

Try this for HA OS (the second set of steps)

Then inside HA container, use the path I posted above with Linux CLI editor of your choice (nano or vi)

Thanks! I’ll dive into this when I have enough time, probably Tuesday.
Let you know.

Sorry, i have home assistant based on linux on a vm in proxmox.
I cannot find /usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py even it’s the fil I see in the log.
I user the terminal extension to do ssh, is it the issue??
Kindly

Gregori

My integration was working fine, I was using some Node red automation and everything was perfect
but since three day ago the Nissan Leaf entity vanished and my dashboard show instead

Entity not available: sensor.leaf1mail_charge (and etc…)

Looking at the log I have some error

2021-05-22 17:32:54 ERROR (SyncWorker_9) [pycarwings2.pycarwings2] carwings error INVALID PARAMS: 404
2021-05-22 17:32:54 ERROR (SyncWorker_9) [homeassistant.components.nissan_leaf] An unknown error occurred while connecting to Nissan: <class 'pycarwings2.pycarwings2.CarwingsError'>
2021-05-22 17:50:20 ERROR (SyncWorker_2) [homeassistant.components.nissan_leaf] An unknown error occurred while connecting to Nissan: <class 'pycarwings2.pycarwings2.CarwingsError'>

I didn’t touch the config since but here it is


nissan_leaf:
  username: !secret nissan_user
  password: !secret nissan_pwd
  region: "NE"
  update_interval:
    hours: 1
  update_interval_charging:
    minutes: 15
  update_interval_climate:
    minutes: 5
  force_miles: false
logger:
  default: critical
  logs:
    homeassistant.components.nissan_leaf: debug
    homeassistant.components.sensor.nissan_leaf: debug
    homeassistant.components.switch.nissan_leaf: debug

See my answer above. Nissan change something in its server.

By(t)e

Sorry. ok thanks.

I can see the file using SSH but It’s seems like nano is not installed, how can I make the change?

Try vi rather than vim

1 Like

Thank you!

Screenshot 2021-05-24 at 11.12.09 Screenshot 2021-05-24 at 11.12.01

I created a (ugly) card for my wife’s leaf, but I would like to add a text like “last check: 10 min ago” or whatever.

any idea how to implement that? or then only showing the late update date?

for example how could I display binary_sensor.leaf1mail_charging_status sub state (updated_on) formatted like HH:MM ?

At the linked page it was suggested to use the Portainer add-on to access the homeassistant container. That turned out to be surprisingly easy.
When inside the container I used VI to edit pycarwings2.py, using the path provided by wyx087 and the change provided by andbad.

My car is connected again, thanks guys!

1 Like

I implemented this myself today.

Created a sensor with the charge level and time of last update:

      leaf_charge_and_last_updated:
        friendly_name: "Laadniveau + tijd update"
        value_template: "{{ states('sensor.leaf1stee_charge') }}% om {{ as_timestamp(state_attr('sensor.leaf1stee_charge', 'updated_on')) | timestamp_custom('%H:%M') }}"

At this moment it gives "26% om 22:06" as a result.
Screenshot 2021-05-28 22.44.29

1 Like

would you consider sharing the whole config ? mine is awful

Sure, what exactly are you interested in?

I started with the picture-elements card that michel72 posted in this topic.

Then I tweaked the cars range a little bit, to give it a more realistic range.

      leaf_range_ac_realistic:
        friendly_name: "Leaf Range AC real world"
        icon_template: "mdi:speedometer"
        unit_of_measurement: 'km'
        value_template: "{{ (((states('sensor.leaf1stee_range_ac') | float) | multiply(0.8)) | round(0)) }}"

And I combined the current charge level with the last updated time within one sensor:

      leaf_charge_and_last_updated:
        friendly_name: "Laadniveau + tijd update"
        value_template: "{{ states('sensor.leaf1stee_charge') }}% om {{ as_timestamp(state_attr('sensor.leaf1stee_charge', 'updated_on')) | timestamp_custom('%H:%M') }}"

I changed the picture to this one, because thats how my car looks like:

I put the cars data on the left side of the card and the charger data on the right side.

This is the whole picture-elements card:

elements:
  - entity: binary_sensor.leaf1stee_charging_status
    icon: 'mdi:ev-station'
    style:
      background-color: 'rgba(0, 0, 0, 0.3)'
      bottom: 0
      font-size: 16px
      left: 0
      line-height: 50px
      padding: 0 8px
      transform: initial
      width: 100%
    tap_action:
      action: call-service
      confirmation: true
      service: script.leaf_charge
    type: state-icon
  - entity: sensor.leaf1stee_charge
    icon: 'mdi:reload'
    style:
      bottom: 0
      color: white
      left: 38%
      line-height: 32px
      margin: 0px 0px -5px 0px
      padding: 8px
      transform: initial
    tap_action:
      action: call-service
      confirmation: true
      service: script.leaf_update
    type: state-icon
  - entity: switch.leaf1stee_climate_control
    icon: 'mdi:fan'
    style:
      bottom: 0
      color: white
      line-height: 32px
      margin: 5px 0px -5px 0px
      padding: 8px
      right: 0
      transform: initial
    tap_action:
      action: toggle
      confirmation: true
    type: state-icon
  - entity: binary_sensor.leaf1stee_plug_status
    style:
      '--paper-item-icon-color': null
      left: 0
      margin: 10px 10px
      top: 0
    type: state-icon
  - entity: sensor.zappi_charge_mode
    style:
      font-size: 12px
      color: null
      line-height: 32px
      margin: 17px 0px
      pointer-events: none
      right: 0
      text-shadow: 'rgb(0, 0, 0, 0.2) 0px 0px 2px'
      top: 0
      transform: initial
    type: state-label
  - entity: sensor.zappi_evse
    style:
      font-size: 12px
      color: null
      line-height: 32px
      margin: 1px 0px
      pointer-events: none
      right: 0
      text-shadow: 'rgb(0, 0, 0, 0.2) 0px 0px 2px'
      top: 0
      transform: initial
    type: state-label
  - entity: sensor.leaf_charge_and_last_updated
    style:
      color: null
      font-size: 12px
      line-height: 32px
      margin: 7px 15px
      pointer-events: none
      left: 0
      text-shadow: 'rgb(0, 0, 0, 0.2) 0px 0px 2px'
      top: 0
      transform: initial
    type: state-label
  - entity: input_datetime.departure_datetime
    style:
      color: null
      font-size: 12px
      line-height: 32px
      margin: '-15px 0px'
      pointer-events: none
      right: 0
      text-shadow: 'rgb(0, 0, 0, 0.2) 0px 0px 2px'
      top: 0
      transform: initial
    type: state-label
  - entity: sensor.leaf_range_ac_realistic
    style:
      color: null
      font-size: 12px
      line-height: 32px
      margin: '-10px 15px'
      pointer-events: none
      left: 0
      text-shadow: 'rgb(0, 0, 0, 0.2) 0px 0px 2px'
      top: 0
      transform: initial
    type: state-label
image: /local/images/car/nissan-leaf-gun-metallic-650x425-edit.png
type: picture-elements

The buttons outside the picture-elements card are all input_booleans for the Node Red automation, which turns my Zappi charger on and off, when I think is best for the battery pack and my wallet.

1 Like

nice job thank you ! I’l try that, seems much better than mine!
I already have a nice node red integration but my picture-elements card is pretty bad!
thanks again