Nissan Leaf Component(s)/Platform

So far the three correlations I have found…

  1. When all information updates stop, log in to the owner’s portal fixes everything except location.
  2. The location updates resume on a car startup, but not all car startups. It might be car startup and then movement.
  3. It is not fixed by request for the cars update from the web. But it might be fixed by web request, follow by car power on.

This weekend I might see if I can get more exact details.

I think the best failure mode for the component would be to fail with an unknown for values that don’t get an update. Otherwise, it gives the illusion of data being up to date. Maybe have it switch to unknown after a configurable amount of time.

I have found one way to get the location to update twice now. Have home assistant turn on the climate control, nothing else. After a short while, Home Assistant will show the location of the car correctly.

Hey! I’m quite new to HASS and looking to add support for my Renault ZOE. Figured I could take a look at how you’ve done this for your Leaf, and try to recreate it.

I’m a bit confused about where to put the different logic though, but as far as I understood it what you’ve done is:

  1. Created a new platform and put all the logic for connecting to the API in the components/nissan_leaf.py script (handled by pycarwings dependency)

  2. Created a device tracker (that created a new device entity within hass) in the /device_tracker/nissan_leaf.py script.

The HASS documentation for creating a new platform reads: “One Home Assistant rule is that platform logic should never interface directly with devices.”.

I’m a bit confused about how to create the “Entity Class” they describe here. Is that what you’ve done? And if so, where?

Thanks for any pointers and help.

Where can i download custom component for nissan leaf. I downloded file home-assistant-nissanleaf.zip from

GitHub - BenWoodford/home-assistant at nissanleaf

and copy in

\\HASSIO\config\custom_components\nissan_leaf

Failed config
  General Errors: 
    - Component not found: nissan_leaf
    - Setup failed for nissan_leaf: Component not found.

Have you copied the correct files to the correct locations? These are the files that need copying across, it should work after that. However, I did have problems with it downloading the carwings component but, I did get it working on my PC.

\HASSIO\config\custom_component\nissan_leaf.py
\HASSIO\config\custom_component\switch\nissan_leaf.py
\HASSIO\config\custom_component\sensor\nissan_leaf.py
\HASSIO\config\custom_component\binary_sensor\nissan_leaf.py

These are not all the same file btw, they are found in the associated folders in \components.

Hope that helps, I’m quite a noob at this thing, it took me quite a while to work out where things went, but I’ve only had HA installed for a couple of weeks.

RK

Yeah my Pi setup has started to do the same thing. I have not had time to look into why it started having trouble starting the component.

I didn’t write the device tracker and it currently isn’t part of my current codebase.

The platform pulls the data and then the devices grab the data from it.

Regarding setting the values to unknown:

This isn’t really a wise move as Nissan’s servers fail too often. The battery goes down in increments of 1/12 roughly so you won’t actually be in a position where the data is out of date unless it fails for a very long time.

My general advice is to just not login on any other application. They’ve architected their backend horribly so that you can’t have more than one login session and that can really mess things up. I’ve been running the component since I first published it without any problems by following this tactic.

Good points. We should already be able to query home assistant when the value was last updated to get an idea of how stale the data is.

I think my instance is failing because it can’t get the py carwings library before home assistant gives up. It did that to me the first time, but after rebooting it worked. I was going to download and store it locally to see if that fixed it.

nissan

I am installed files from

GitHub - BenWoodford/home-assistant at nissanleaf

in custom_component folder.

    \HASSIO\config\custom_component\nissan_leaf.py
    \HASSIO\config\custom_component\switch\nissan_leaf.py
    \HASSIO\config\custom_component\sensor\nissan_leaf.py
    \HASSIO\config\custom_component\binary_sensor\nissan_leaf.py

nissan%20component%20

Configuration file

nissan_leaf:
      username: "Nissan Connect username"
      password: "Nissan Connect password"
      nissan_connect: false
      region: 'NE'
      update_interval: 30
      update_interval_charging: 15
      update_interval_climate: 5
      force_miles: true

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

@smile Have you put in your username/email and password you use to connect to the Nissan App into the config?

yes i did.
Have you complete guide how to use Nissan leaf custom component. maybe i am missing some thing. i am tried both to put my username and password in configuration.yaml file and in nissan_leaf.py, but same result.

nissan_leaf:
      username: "my nissan Connect username"
      password: "my nissan Connect password"
      nissan_connect: false
      region: 'NE'
      update_interval: 30
      update_interval_charging: 15
      update_interval_climate: 5
      force_miles: true
1 Like

Sorry mate, I’m quite a noob and it’s not my project, I’ve done my best, Good luck :frowning:

I had some time to find out why my config is failing today.
If I understand the error correctly, it is failing while trying to install the pycryptodome requirement for pycarwings2.

2018-04-03 19:46:59 ERROR (SyncWorker_3) [homeassistant.util.package] Unable to install package https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings: Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-w096xrm2/pycryptodome/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-wcsca0p2-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-w096xrm2/pycryptodome/ 2018-04-03 19:46:59 ERROR (MainThread) [homeassistant.requirements] Not initializing nissan_leaf because could not install requirement https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings 2018-04-03 19:46:59 ERROR (MainThread) [homeassistant.setup] Setup failed for nissan_leaf: Could not install all requirements.

Odd isn’t it, I’ve been running HA on an old windows PC and the Leaf element works fine.

What is really odd is that it was working on my HASSIO installation.
I think one of the latest HASSIO updates may have caused the problem. I am also having problems with the fact that all of the historical data has disappeared. I plan to reflash my my Pi’s memory card and restore from backup to see if that fixes it.

It’s likely that HASS.io doesn’t like using direct git links for libraries, which I’ve had to use for now as the author of the library hasn’t pulled my changes in yet.

I run mine straight in docker without HASS.io so haven’t come across these issues.

Please help.

    Setup failed for nissan_leaf: Could not install all requirements.
    00:02 setup.py (ERROR)
    Not initializing nissan_leaf because could not install requirement https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings
    00:02 requirements.py (ERROR)
    Unable to install package https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings: Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fz56baud/pycryptodome/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-buryeidq-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-fz56baud/pycryptodome/
    00:02 util/package.py (ERROR)

Please help me.

Setup failed for nissan_leaf: Could not install all requirements.
00:02 setup.py (ERROR)
Not initializing nissan_leaf because could not install requirement https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings
00:02 requirements.py (ERROR)
Unable to install package https://github.com/BenWoodford/pycarwings2/archive/master.zip#pycarwings: Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fz56baud/pycryptodome/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-buryeidq-record/install-record.txt --single-version-externally-managed --prefix --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-fz56baud/pycryptodome/
00:02 util/package.py (ERROR)

Where can i install pycarwings2 in Hass.io. I tried to install https://github.com/BenWoodford/pycarwings2.git`

~ install https://github.com/BenWoodford/pycarwings2.git
BusyBox v1.27.2 (2018-01-29 16:01:29 GMT) multi-call binary.

Usage: install [-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST

Copy files and set attributes

        -c      Just copy (default)
        -d      Create directories
        -D      Create leading target directories
        -s      Strip symbol table
        -p      Preserve date
        -o USER Set ownership
        -g GRP  Set group ownership
        -m MODE Set permissions
        -t DIR  Install to DIR