Nissan Leaf Component(s)/Platform

@TNT_Larsn Did it work for your Raspberry pi?

Also thank you but, no, I don’t take donations :slight_smile: There is so many people who work way way more for free on home assistant, you could donate there, or to Tobias, the My Leaf author who builds the libraries used by leaf2mqtt, he takes donations through the My Leaf app.

Timing on this could not be more perfect. I just stumbled upon your image and turned it into a local add-on. It’s running on Home Assistant Blue, so I can confirm the arm64 version works fine (on my 2016 Canadian leaf).

This is great, thank you for the work you’ve put into this.

1 Like

I have not created a real add-on yet, but for those interested, you can create a local add-on by creating a folder in /addons called leaf2mqtt

Then create a file called config.json containing the following

{
	"name": "Leaf2MQTT",
	"version": "latest",
	"slug": "leaf2mqtt",
	"description": "Leaf2MQTT add-on",
	"startup": "application",
	"url": "https://github.com/yp87/leaf2mqtt",
	"image": "yp87/leaf2mqtt",
	"arch": ["aarch64", "amd64"],
	"environment": {
		"LEAF_USERNAME": "",
		"LEAF_PASSWORD": "",
		"LEAF_TYPE": "",
		"MQTT_HOST": "",
		"MQTT_PORT": "1883",
		"MQTT_USERNAME": "",
		"MQTT_PASSWORD": "",
		"MQTT_BASE_TOPIC": "leaf",
		"UPDATE_INTERVAL_MINUTES": "60",
		"CHARGING_UPDATE_INTERVAL_MINUTES": "15",
		"COMMAND_ATTEMPTS": "5",
		"LOG_LEVEL": "Warning"
	}
}

Edit environment variables as required. This pulls the latest image, so you can uninstall and install again to update when needed.

You can also add icon.png and logo.png in the /addons/leaf2mqtt folder with the following image for some nice visuals.

logo

4 Likes

Thank you. Works like a charm

I get the error

SEVERE: 2022-05-04 17:16:12.055273: main: V0.10

When I run the addon.

My login credentials are 100% correct as I verified them with the My Leaf app. I have an MQTT broker setup and working.

The code I’m using

{
    "name": "Leaf2MQTT",
    "version": "latest",
    "slug": "leaf2mqtt",
    "description": "Leaf2MQTT add-on",
    "startup": "application",
    "url": "https://github.com/yp87/leaf2mqtt",
    "image": "yp87/leaf2mqtt",
    "arch": ["aarch64", "amd64"],
    "environment": {
        "LEAF_USERNAME": "my_email_address",
        "LEAF_PASSWORD": "my_password",
        "LEAF_TYPE": "newerThanMay2019",
        "MQTT_HOST": "192.168.0.238",
        "MQTT_PORT": "1883",
        "MQTT_USERNAME": "mqtt",
        "MQTT_PASSWORD": "mqtt",
        "MQTT_BASE_TOPIC": "leaf",
        "UPDATE_INTERVAL_MINUTES": "60",
        "CHARGING_UPDATE_INTERVAL_MINUTES": "15",
        "COMMAND_ATTEMPTS": "5",
        "LOG_LEVEL": "Warning"
    }
}

When logging into the My Leaf app i need to select ‘World’. I don’t know if that is relevant…

Any ideas?

Try setting log level to Info. Should give you more details.

Are you able to run the image normally (not as an addon)?

I get the same result running as a docker container on my Ubuntu VM. I’ll try changing the logging and see what it says.

Unfortunately setting the log level to Info didn’t yield any more information from the log.

Hello!
This log is there to ensure we see the version no matter the log level. It is not a real error.

I can reduce the severity of this log since I did not really update the version with each changes anyway

So if I don’t get any other messages in the log. Does that mean the add-on is functioning correctly?

The best way to see if it is working correctly is to try it by refreshing battery information, starting climate, etc :slight_smile:

I would not assume that it is correctly working if there is no apparent issues in the logs.

I did the change, there should be a new docker image available soon

Thanks. I uninstalled and reinstalled and it’s working now with same config as before. Thanks buddy

1 Like

Thanks to @EtienneMD, his addon configuration is now part of the leaf2mqtt repository.

Home Assistant add-on

Click the icon below to add this repository to your Home Assistant instance or follow the procedure highlighted on the Home Assistant website.

Install leaf2mqtt add-on repo.

This seems promising! How do you configure it once added as an add-on?

Everything is configured on the add-on configuration page.

More info on configuration options on the project repo.

1 Like

Thanks—had to uninstall/reinstall. It works! Though, like previous versions, it still doesn’t seem to update the battery as reliably as the climate/location. Might post some logs later after a little more observation.

I’m really pleased for the possibility to integrate our car into Home Assistant, via Leaf2Mqtt. I went through this post and learned that @Sriracha has been really kind and kept updating the addon for the rest of us. Amazing!

I do need some help however with extracting the stats values. I don’t seem to get anything out - I’m checking with MQTT explorer as well as the listener tool in Home Assistant. It would be interesting to get the kilometersPerKwh and the kwhUsed etc.

I did race an issue - stats - help needed · Issue #32 · yp87/leaf2mqtt · GitHub, but perhaps it’s only something simple I’m missing. I’ve noticed there is a tripHistory and therefor tried swopping stats to tripHistory to alter the dates, but no luck.

Could someone help please…

Hi

I have nissan Leaf 2014 and I could not add it on my home assistant dashboard.
the config file looks like:

nissan_leaf:

username: XXXX

password: XXXXX

region: NE

update_interval:

hours: 1

update_interval_charging:

minutes: 15

update_interval_climate:

minutes: 5

force_miles: false

sensor:

  • platform: template

    sensors:

    leaf_state:

    value_template: "Ladd: {{ states('binary_sensor.leaf_charging_status') }}"
    

    leaf_range_ac:

    value_template: "A/C räckvid: {{ states('sensor.leaf_range_ac') }}"
    

    leaf_range:

    value_template: "räckvid: {{ states('sensor.leaf_range') }}"
    

    leaf_battery:

    unit_of_measurement: '%'
    
    value_template: "{{ states('sensor.leaf_charge') }}"
    
    icon_template: "{%- if states.sensor.leaf_charge.state >= '95' %}mdi:battery{%- elif states.sensor.leaf1mich_charge.state == '100' %}mdi:battery{%- elif states.sensor.leaf1mich_charge.state <= '15' %}mdi:battery-outline{% else %}mdi:battery-{{(states.sensor.leaf1mich_charge.state|float / 10)|round*10}}{%- endif %}"
    

what should I write on " states.sensor.leaf1mich_charge.state " instead of Leaf1Mich ? where can I know the nickname ?

what is the wrong with my code ? I am new at home assistant and i am very thankfull if you can explain step by step / thanks

I’ve just installed yp87’s version for my new leaf, but I’m wondering how people deal with the 12v battery as I understand that it runs flat when you are not using the car.

Currently my update interval is set to every 24 hours, but I’d like to change that to 1 hour.

  • Can I run a script to disable the updates during vacation?
  • If I would run flat, how hard (or simple) would it be to recharge the 12V battery? Does the car start without?
  • Can I monitor the 12v battery through mqtt?

Other things to do when the car is sometimes not used for multiple days (or more)?

For the last couple of years I have had an update interval of about 10 minutes and have never had a problem with the 12v battery. If I remember correctly, the drive battery will recharge the 12v battery so long as it’s not plugged in. So if you are leaving the car at home while you are on vacation, you would be best leaving the car unplugged.

If it were to go flat then it would be a pain, as the car cannot start. I guess your garage or breakdown service could recharge the battery enough to get you started, just as with a normal car.