Nissan Leaf Component(s)/Platform


#22

Never mind, I see you wrote one! Nice. I will place your version into my hass.io system and try it out!


#23

kurol, thanks for your help! I added the custom_componant folder to my config share and it is now working. I got a config error for the component the first time the first time it loaded. When I reviewed the error log it showed that pywings2 could not be loaded. I figured that it just timed out when trying to load the copy the first time off the internet and would probably load it from cache the next time. I rebooted and sure enough, it all started to work.
17%20PM


#24

You shouldn’t need to change the references as I used relative (from .. import) importing instead.

Thanks for the device tracker implementation, it’s irritating trying to do it blind!


#25

There was only one module that needed a reference change for me because it was missing the relative reference. I can’t remember which one though.


#26

Ben & Kurol,
Updates stopped while my car was parked over the weekend. Error log said something about being unable to renew the key. After I logged into the owners portal over the web, things started working again for everything except location. I can’t find any errors yet for the device tracker. If I ask for the car location from Nissan Connect EV, it works. I suspect Nissan might have updated something because the new mobile app reported the car’s location for the first time. In the past it always just said "error in getting car location"
Dan


#27

How strange. Never had anything like that show up. You didn’t set your refresh interval really low did you?


#28

Nope, I just copy the settings example from the code. I edited my post above. The offical app reported location for the first time. It had always errored in the past. Maybe a Nissan change?


#29

Wait are you in the US? The US has a separate API for the new app, this component uses the old API as every country outside the US still uses it (and it’s still functional within the US… I assume)


#30

Yep, US. My apps using the old API are still working for now.


#31

I realized I forgot to turn on the debug log for the leaf components.
I replaced my VIN but otherwise unmodified.

Argh. It is working again. When I started the car at work, it started to report its location again.

2018-02-22 17:57:23 DEBUG (SyncWorker_4) [custom_components.device_tracker.nissan_leaf] Setting up Scanner (device_tracker) for Nissan Leaf
2018-02-22 17:57:23 DEBUG (SyncWorker_7) [custom_components.device_tracker.nissan_leaf] No position found for vehicle LEAF_VIN
2018-02-22 17:57:23 DEBUG (MainThread) [custom_components.switch.nissan_leaf] Registered LeafChargeSwitch component with HASS for VIN LEAF_VIN
2018-02-22 17:57:23 DEBUG (MainThread) [custom_components.switch.nissan_leaf] Registered LeafClimateSwitch component with HASS for VIN LEAF_VIN
2018-02-22 17:57:24 DEBUG (SyncWorker_12) [custom_components.sensor.nissan_leaf] Adding sensors
2018-02-22 17:57:24 DEBUG (MainThread) [custom_components.sensor.nissan_leaf] Registered LeafRangeSensor component with HASS for VIN LEAF_VIN
2018-02-22 17:57:24 DEBUG (MainThread) [custom_components.sensor.nissan_leaf] Registered LeafRangeSensor component with HASS for VIN LEAF_VIN
2018-02-22 17:57:24 DEBUG (MainThread) [custom_components.sensor.nissan_leaf] Registered LeafBatterySensor component with HASS for VIN LEAF_VIN
2018-02-22 17:58:38 DEBUG (SyncWorker_16) [custom_components.device_tracker.nissan_leaf] Updating device_tracker for Dan’s Leaf with position <pycarwings2.responses.CarwingsMyCarFinderResponse object at 0x71fca510>


#32

I haven’t had the time to put on some serious debugging.

I can just say I’m experiencing similar issues.

I find the Nissan carwings API implementation overall to be somewhat unstable since it relies on polling of response codes and multiple tries. I think the pycarwings2 python implementation API could be improved with better failure mode handling, and maybe “smarter” retry-logic.

My experience, I do get position updates. Suddenly I don’t for some time. The component currently tries to refresh continuously until a position is received. I’m not sure if the use of other Android/iOS/Web apps influence. At one time if seems that login with a different device helps the HA component, sometimes it appears to interfere with the HA component.

I would need all help on this one to track actual failure scenarios.


#33

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.


#34

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.


#35

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.


#36

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.


#37

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

https://github.com/BenWoodford/home-assistant/tree/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.

#38

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


#39

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.


#40

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.


#41

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.