This article has been re-written 2018.01.22. I have added more details (mostly copy-paste) from glynhudson/leaf-python-mqtt on Github. I will advise you to follow the readme on Github instead, to get the newest update.

My setup

Lenovo with Ubuntu 16.04 and Home Assistant, but this was also testet on my last setup with Rasbian on RaspberryPi.

MQTT broker

One of the problems with the MQTT-broker in HA was understanding what was going on. I tried installing multiple MQTT-clients to monitor the topics. All of them connected just fine, but there was no stream of data. It did worked somehow, as I got the Carwings-data through MQTT to HA. I also tried to push an update for the car, but nothing happened.

I ended up registering an account on CloudMQTT. From there I created a homeassistant user and added the broker URL, username, password and port in /home/<user>/leaf-python-mqtt/config.ini.

MQTT client

Sometimes it can be nice to see if the messages is actually being sent over the MQTT stream. For that you need a client. There is a lot of client, but somehow I have problem with most of them.

(Update: I dropped the sensor.leaf_battery_remaining and added round(2) for the battery_percent)

Automation

After getting MQTT to work as expected, I could do some automation. The script below will fetch new status from the car at 21:00, then check if the car is NOT_CHARGING and the battery is below 50% at 21:30. If this criteria is met, it will send a push-message to remind me.