Nissan Leaf Component(s)/Platform

…bump…

I hate to be that guy, but is there a way to keep Home Assistant from requesting this information that is not available?

Sorry, I have no idea. I can’t get the component working with one of my Leafs at all!

So I enabled the debug logging and did a bit more digging.

On the “good” Leaf, I see:

DEBUG (SyncWorker_0) [pycarwings2.pycarwings2] Response HTTP Status Code: 200
DEBUG (SyncWorker_0) [pycarwings2.pycarwings2] Response HTTP Response Body: b'{"status":200,"userId":"username","vin":"MYVIN","resultKey":"7O0rgQ0SWUCtbYPNv7EjBDKOKXsv5HYdGAuNqLFmFr5Hqu4CSj"}'
DEBUG (MainThread) [homeassistant.components.nissan_leaf] Waiting 30 seconds for battery update (MYVIN) (0)

…whereas my “bad” Leaf …

DEBUG (SyncWorker_5) [pycarwings2.pycarwings2] Response HTTP Status Code: 200
DEBUG (SyncWorker_5) [pycarwings2.pycarwings2] Response HTTP Response Body: b'{"status":200,"BatteryStatusRecords":[]}'

…goes no further. I’ve noted that the 200 response message in the “bad” leaf does not respond with any JSON content.

Is the dev still looking at this thread? :wink:

And now it’s working. What did I do?

  1. Noticed yesterday that the phone app was no longer able to receive any updates about this vehicle.

  2. Noticed today that the phone app was now updating correctly.

  3. Rebooted the HASS box.

And now it works. With both Leafs. So I guess it was their crappy servers all along…

1 Like

If you have an older Leaf you need to set the Nissan Connect setting to false, otherwise it’ll attempt to setup the device tracker which that car doesn’t have.

On another note, seems that Nissan’s servers are so unreliable that I may need to start rebooting HASS every night as it stops being able to fetch data after a while. Though turning the climate control on still works which is odd

Thanks @BenWoodford, I don’t guess I ever scrolled to the top where it clearly states this. Our 2015 had its headunit upgraded, no longer carwings, but I guess this still does not work with MY2015.

nissan_leaf:
–username: <username/email>
–password:
–region: (see below)
–nissan_connect: <true/false> (optional, defaults to true) - False for MY2015 or older!
–update_interval: (see below, default is 30)
–update_interval_charging: (default is 15)
–update_interval_climate: (default is 5)
–force_miles: true

I’m reading this at work but excited to get home to make this small change to keep the error from occurring on the back-end.

Hi All,
I’'m pretty new to setting up Home Assistant device trackers (but are familiar with python/pycarwings2 etc)…
Pretty fresh recent HomeAssistant setup here on my Debian home server.
All entitities received, all looking good, BUT I cannot find out how to make the device_tracker show up…
I am able to receive the location of my car using the pycarwings2 api scripts…

Setting de debug as shown https://www.home-assistant.io/components/nissan_leaf/ shows that at least homeassistant is getting the right location (I changed some info in it to not reveal my vin etc):

2019-06-09 21:38:01 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Latest server date= 9-jun-2019 21:37
2019-06-09 21:38:01 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Server Response: {‘battery_capacity’: ‘240’, ‘time_to_full_l2_6kw’: None, ‘time_to_full_trickle’: None, ‘answer’: {‘status’: 200, ‘BatteryStatusRecords’: {‘BatteryStatus’: {‘BatteryChargingStatus’: ‘NORMAL_CHARGING’, ‘BatteryRemainingAmount’: ‘200’, ‘BatteryRemainingAmountWH’: ‘21920’, ‘BatteryCapacity’: ‘240’, ‘SOC’: {‘Value’: ‘86’}, ‘BatteryRemainingAmountkWH’: ‘’}, ‘OperationDateAndTime’: ’ 9-jun-2019 21:37’, ‘NotificationDateAndTime’: ‘2019/06/09 19:37’, ‘CruisingRangeAcOff’: ‘155000’, ‘OperationResult’: ‘START’, ‘CruisingRangeAcOn’: ‘148000’, ‘TargetDate’: ‘2019/06/09 19:37’, ‘TimeRequiredToFull200’: {‘MinutesRequiredToFull’: ‘30’, ‘HourRequiredToFull’: ‘3’}, ‘PluginState’: ‘CONNECTED’}}, ‘is_connected_to_quick_charger’: False, ‘plugin_state’: ‘CONNECTED’, ‘cruising_range_ac_off_km’: 155.0, ‘cruising_range_ac_on_km’: 148.0, ‘is_charging’: True, ‘battery_percent’: 86.0, ‘is_connected’: True, ‘is_quick_charging’: False, ‘battery_remaining_amount’: ‘200’, ‘time_to_full_l2’: datetime.timedelta(0, 12600), ‘charging_status’: ‘NORMAL_CHARGING’, ‘state_of_charge’: ‘86’}
2019-06-09 21:38:01 DEBUG (Thread-2) [homeassistant.components.nissan_leaf.device_tracker] No position found for vehicle SJNFAAAA0U1234567
2019-06-09 21:38:05 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Got climate data for Leaf: {‘is_hvac_running’: False}
2019-06-09 21:38:09 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location data not in yet. (SJNFAAAA0U1234567) (1). Waiting 30 seconds
2019-06-09 21:38:40 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location data not in yet. (SJNFAAAA0U1234567) (2). Waiting 30 seconds
2019-06-09 21:39:11 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location data not in yet. (SJNFAAAA0U1234567) (3). Waiting 30 seconds
2019-06-09 21:39:42 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location_status={‘latitude’: ‘52.397211111111’, ‘longitude’: ‘4.6482027777778’}
2019-06-09 21:39:42 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location Response: {‘latitude’: ‘52.397211111111’, ‘longitude’: ‘4.6482027777778’}
2019-06-09 21:39:42 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Next update=2019-06-09 20:39:42.596723+00:00
2019-06-09 21:39:42 DEBUG (Thread-9) [homeassistant.components.nissan_leaf.device_tracker] Updating device_tracker for leaf1 with position {‘latitude’: ‘52.397211111111’, ‘longitude’: ‘4.6482027777778’}

I added a copy of my fritz tracker for nissan_leaf (and also tried with the vehicle name, and ‘nissan’), but it does not show up anywhere:

device_tracker:

  • platform: fritz
    host: 192.168.178.1
    new_device_defaults:
    track_new_devices: false
    hide_if_away: true
  • platform: nissan_leaf
    new_device_defaults:
    track_new_devices: true
    hide_if_away: true

Any hints on what this should do or how it should work?

I would be ok to manually ask for the position, but showing it on a map would be the best ( I’m a geo guy :slight_smile: )

TIA for any hints

Like this?

You don’t have to add a device tracker, it’s included in the nissan leaf platform. Just use the add entity button in lovelace to add a card (type map).

@remyderuysscher

Yes, that is what I want :slight_smile: !

But… the Nissan location does not show up in the entity list I can choose from if I choose a map…

Looking at your screendump, I also do not have the ‘Leaf Update Status’, ‘Leaf Previous Attemtp’ and the other two below in your ‘Nissan Leaf’ card… Do you have an updated version of the nissan_leaf component?

Is there a way to fire an actual getLocation-request? So the location is not requested every time, but only on demand? My feeling is that requesting the location from the leaf is even heavier then requesting the batt status…

Below is what I have in my configuration.yaml

nissan_leaf:                                                                                                                                                                                                                                          
  username: "username"
  password: "password"
  region: "NE"
  nissan_connect: true

Again: I see python debug info that we are receiving my location…
Is there maybe some caching of objects going on in the history tables? I probably started with nissan_connect: false…

2019-06-10 12:46:16 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Updating Nissan Leaf Data               
2019-06-10 12:46:31 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Start server date=10-jun-2019 12:46     
2019-06-10 12:46:31 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Requesting battery update, SJNFAAZE0U111111111         
2019-06-10 12:46:36 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Waiting 30 seconds for battery update (SJNFAAZE0U111111111) (0)
2019-06-10 12:47:08 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Latest server date=10-jun-2019 12:46
2019-06-10 12:47:08 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Waiting 30 seconds for battery update (SJNFAAZE0U111111111) (1)
2019-06-10 12:47:40 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Latest server date=10-jun-2019 12:47
2019-06-10 12:47:40 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Server Response: {'cruising_range_ac_on_km': 167.0, 'cruising_range_ac_off_km': 175.0, 'battery_percent': 97.0, 'time_to_full_l2_6kw': datetime.timedelta(0, 360
0), 'is_connected_to_quick_charger': False, 'state_of_charge': '97', 'time_to_full_l2': datetime.timedelta(0, 4200), 'is_connected': False, 'battery_remaining_amount': '240', 'answer': {'BatteryStatusRecords': {'OperationDateAndTime': '10
-jun-2019 12:47', 'TimeRequiredToFull': {'MinutesRequiredToFull': '0', 'HourRequiredToFull': '2'}, 'BatteryStatus': {'BatteryRemainingAmount': '240', 'SOC': {'Value': '97'}, 'BatteryCapacity': '240', 'BatteryChargingStatus': 'NOT_CHARGING
', 'BatteryRemainingAmountWH': '24720', 'BatteryRemainingAmountkWH': ''}, 'PluginState': 'NOT_CONNECTED', 'TimeRequiredToFull200': {'MinutesRequiredToFull': '10', 'HourRequiredToFull': '1'}, 'CruisingRangeAcOff': '175000', 'TargetDate': '
2019/06/10 10:47', 'OperationResult': 'START', 'CruisingRangeAcOn': '167000', 'TimeRequiredToFull200_6kW': {'MinutesRequiredToFull': '0', 'HourRequiredToFull': '1'}, 'NotificationDateAndTime': '2019/06/10 10:47'}, 'status': 200}, 'is_quic
k_charging': False, 'is_charging': False, 'charging_status': 'NOT_CHARGING', 'battery_capacity': '240', 'plugin_state': 'NOT_CONNECTED', 'time_to_full_trickle': datetime.timedelta(0, 7200)}
2019-06-10 12:47:40 DEBUG (Thread-10) [homeassistant.components.nissan_leaf.device_tracker] No position found for vehicle SJNFAAZE0U111111111
2019-06-10 12:47:45 ERROR (MainThread) [homeassistant.components.nissan_leaf] An error occurred communicating with the car SJNFAAZE0U111111111
2019-06-10 12:47:48 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location data not in yet. (SJNFAAZE0U111111111) (1). Waiting 30 seconds
2019-06-10 12:48:19 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location_status={'latitude': '52.397394444444', 'longitude': '4.6482138888889'}
2019-06-10 12:48:19 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Location Response: {'latitude': '52.397394444444', 'longitude': '4.6482138888889'}                                                                              2019-06-10 12:48:19 DEBUG (MainThread) [homeassistant.components.nissan_leaf] Next update=2019-06-10 11:48:19.806324+00:00
2019-06-10 12:48:19 DEBUG (Thread-3) [homeassistant.components.nissan_leaf.device_tracker] Updating device_tracker for Leaf1rich with position {'latitude': '52.397394444444', 'longitude': '4.6482138888889'}

If you have a recent Leaf (40kWh for example) then nissan_connect must be set to true.

The Leaf Update Status is a custom template, not from the component. Debug info looks ok to me.

You can only request a full update (with location info) not a partial.

Ah, duh… My mistake, because so many new devices popped up in my fritz box (wifi router) device tracker, I changed the default tracker settings to:

device_tracker:
  - platform: fritz
    host: 192.168.178.1
    new_device_defaults:
      track_new_devices: false
      hide_if_away: true

Thinking that the ‘track_new_devices’ only was for the fritz tracker…

But apparently this is a global one? Because as soon as I set that one to true, the nissan_leaf tracker appeared as entity in lovelace… Is this to be considered as a bug? Or a yaml feature?

Still eager to know how you put the last update info in your cards… do you share your config somewhere?

Anyway, thanks for the component, all devs here!!!

Here is part of my sensor config file, just put the relevant information in the sensor (XXXXXX) and that should do it.

  - platform: template
    sensors:
      leaf_next_update:
        friendly_name: 'Leaf Next Update'
        value_template: >
          {%- macro suffix(d) %}
          {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
          {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
          {%- endmacro %}
          {% set day = as_timestamp(states.sensor.XXXXXX_charge.attributes.next_update) | timestamp_custom('%a') %}
          {% set date = as_timestamp(states.sensor.XXXXXX_charge.attributes.next_update) | timestamp_custom('%d') |int %}
          {% set time = as_timestamp(states.sensor.XXXXXX_charge.attributes.next_update) | timestamp_custom('%I:%M %p') %}
          {{ day }} {{ date }}{{ suffix(date) }} {{ time }}
  
  - platform: template
    sensors:
      leaf_last_attempt:
        friendly_name: 'Leaf Previous Attempt'
        value_template: >
          {%- macro suffix(d) %}
          {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
          {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
          {%- endmacro %}
          {% set day = as_timestamp(states.sensor.XXXXXX_charge.attributes.last_attempt) | timestamp_custom('%a') %}
          {% set date = as_timestamp(states.sensor.XXXXXX_charge.attributes.last_attempt) | timestamp_custom('%d') |int %}
          {% set time = as_timestamp(states.sensor.XXXXXX_charge.attributes.last_attempt) | timestamp_custom('%I:%M %p') %}
          {{ day }} {{ date }}{{ suffix(date) }} {{ time }}
  
  - platform: template
    sensors:
      leaf_last_update:
        friendly_name: 'Leaf Last Update'
        value_template: >
          {%- macro suffix(d) %}
          {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
          {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
          {%- endmacro %}
          {% set day = as_timestamp(states.sensor.XXXXXX_charge.attributes.updated_on) | timestamp_custom('%a') %}
          {% set date = as_timestamp(states.sensor.XXXXXX_charge.attributes.updated_on) | timestamp_custom('%d') |int %}
          {% set time = as_timestamp(states.sensor.XXXXXX_charge.attributes.updated_on) | timestamp_custom('%I:%M %p') %}
          {{ day }} {{ date }}{{ suffix(date) }} {{ time }}

Just a quick heads up, I got an email from Nissan yesterday stating that they are switching off the ‘Find My Car’ service on the 30th Jun.
Looks like we may no longer be able to track the car from that date. Irish user here, Euro servers.

Same for me in Sweden.

Is there something you can do about the update being stuck? Really often the update fails, but since there doesn’t seem to be a timeout set, it’s stuck in the updating state forever until I restart HA, which I only do after an update.
Could this component be adjusted such that it timeouts at half or a quarter of the interval setting? (Or some other sensible default.) That would be nice!

2 Likes

Has Nissan done some changes to the API? As of today the component isn’t producing any entities in HA for me.

Good to hear it’s not just me, I was working on something else installing some py-packages and thought I broke the component.

Same problem here. I can see this in the logs:

An unknown error occurred while connecting to Nissan: <class ‘pycarwings2.pycarwings2.CarwingsError’>

10:53 AM components/nissan_leaf/init.py (ERROR)

Invalid JSON returned

10:53 AM components/nissan_leaf/init.py (ERROR)

Edit. Leaf Manager app doesn’t work today, and when logging into the EV connect app I got a message that the app was updated as of today, and that the old version doesn’t work anymore. Looks like they have made some changes.

https://github.com/home-assistant/home-assistant/issues/24757

No response from the creator, even after a month.

It is more likely related to the change in Nissan API (also Nissan APP need update to work) and the car location on APP was disabled!

Lets see if the pycarwings creator find a solution!