leaf2mqtt
Use this at your own risk. No liability is accepted for any negative consequences.
(You probably want to use this fork which has a native Dart MQTT client)
Builds a Docker container to pull in data from the Nissan Connect platform for the LEAF and publish over MQTT, using Tobias Westergaard Kjeldsen's excellent dartnissanconnect
library which is also the basis for the MyLeaf app. Climate on/off control is available, but beware that it is slow and unreliable.
This works for my UK-based 2020 LEAF 40kWh car, and should work for any European LEAF that uses the NissanConnect app (Android or iOS). Please ensure you have installed the app and can communicate with the car before proceeding with this.
This will not work for older "original-shape" LEAFs. Don't waste any time trying.
You must have a working MQTT server on your LAN. The container uses mosquitto
for publishing its data. I use this for interfacing with Home Assistant (running on a Synology NAS, hence the Docker container approach) via MQTT sensors: see leaf-sensors.yaml
, leaf-binary-sensors.yaml
, leaf-template.yaml
and leaf-switches.yaml
for examples (and replace the MY_VIN with your VIN from the MQTT messages once you have the steps below working!).
You must also have a working Docker installation, and be comfortable building images and running them as containers. Should work fine for x86_64
architectures; others may need a little work, particularly for the dart
installation step.
Please note that I created this for my own personal use and am not looking for feedback, issues, feature requests etc. It's provided here as a starting point for your own projects.
Instructions
- Create a folder e.g.
leaf2mqtt
- Drop all these files into that folder (Code button, Download ZIP).
cd
into that folder- Run
sudo docker build --tag leaf2mqtt .
, which will prompt you for yoursudo
password, and then take quite a while to complete. You'll see a lot ofRemoving
messages: this is just slimming down the image by removing intermediate packages that aren't required at runtime. - That should have created a
leaf2mqtt
image: now you need to fire up a container from it. Doesn't need filesystem access, but you need to set five or seven environment variables:TZ
: Set this to your timezone. Mine isEurope/London
.MQTTTOPIC
: I set this toleaf
and you should too unless you have a good reason not toMQTTHOST
: LAN IP address of your MQTT broker.USERNAME
: your NissanConnect username — the one you use to log into the app.PASSWORD
: your NissanConnect password — the one you use to log into the app.MQTTUSER
: (optional) Username for your MQTT broker.MQTTPASS
: (optional) Password for your MQTT broker.
If all goes well, you should start to see the messages coming through on MQTT.
You request updates over MQTT: see leaf-switches.yaml
. It's up to you how and when you request an update: keep it to a minimum for the sake of your 12V battery. See leaf-automations.yaml
for some inspiration.