Skip to content

Translation tool from ELM bluetooth dongle connected to OBD2 port in the car to MQTT server for HomeAssistant

Notifications You must be signed in to change notification settings

getget1980/ZoeELM2MQTT

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zoe ELM2MQTT

Translation tool from ELM bluetooth dongle connected to OBD2 port in the car to MQTT server for HomeAssistant

Initial steps

Clone the repository to your local folder. Open the file elm2mqtt.ino using Arduino IDE. Edit the file secrets.h - add your wifi SSID, wifi password, mqtt server, mqtt username/password and most importantly, the ELM327 OBD dongle name and bluetooth pin. Once modified, save the file. Set the board type in Arduino to WEMOS LOLIN32. Change the partition scheme to "Minimal SPIFFS (Large APPS with OTA)". Otherwise the code will not fit into memory. Make sure you install necessery libraries:

  • ArduinoOTA
  • PubSubClient
  • WebSockets (by Markus Sattler) Compile the code and upload to your ESP32 board.

Get the ESP32 somewhere near the car, plug the ELM dongle to the car OBD2 port and turn the ESP32 on. The ESP will connect to your local network and will start to try to connect to the dongle. The ELM will only work while the car is charging or doors are open, otherwise the battery data will not be available.

Warning on ESP32 version

As Espressif continues to develop the ESP32 ecosystem, some parts become incompatible over time. The version of this code works with ESP32 version 2.0.17. You might need to downgrate your current version of boards definition in order for the code to compile correctly. See the image no how to do this.

image

Monitoring

There is a possibility to monitor the ESP32 communication using in-built websocket server. Connect to the IP address of the ESP32 and you'll be present with basic interface. In the bottom input, type "h" for help and it will show the list of available commands. It will also continously print debug messages from the dongle - attempting to measure the battery statistics every 60 seconds (configurable by changing variable rInt).

HomeAssistant part

The tool reports data to MQTT server. HomeAssistant can use this feature to create virtual entities based on MQTT. In configuration file, add following section:

mqtt:
  sensor:
    - name: "Zoe - State of Charge"
      state_topic: "elm327report/result/SoC"
      unique_id: "zoe.SoC"
      unit_of_measurement: "%"

    - name: "Zoe - Odometer"
      state_topic: "elm327report/result/Odometer"
      icon: mdi:gauge-full
      unit_of_measurement: "km"
      unique_id: "zoe.Odometer"      
            
    - name: "Zoe - Available range"
      state_topic: "elm327report/result/AvailableRange"
      icon: mdi:gauge-low
      unit_of_measurement: "km"
      unique_id: "zoe.Range"
      
    - name: "Zoe - Available Energy"
      state_topic: "elm327report/result/AvailableEnergy"
      icon: mdi:lightning-bolt
      unit_of_measurement: "kWh"
      unique_id: "zoe.Energy"
      
    - name: "Zoe - Dongle status"
      state_topic: "elm327report/status"
      unique_id: "zoe.DongleState"
      
    - name: "Zoe - Debug - message sent"
      state_topic: "elm327report/debug/elmSend"
      unique_id: "zoe.ElmSend"
      
    - name: "Zoe - Debug - message received"
      state_topic: "elm327report/debug/elmResponse"
      
    - name: "Zoe - Debug - ODB connection status"
      state_topic: "elm327report/heartbeat"
      unique_id: "zoe.ElmHeartbeat"

template: sensor:

- name: "Zoe SoC icon"    
  state: "{{ states('sensor.zoe_state_of_charge') }}"
  unit_of_measurement: "%"
  icon: >
     {% if states('sensor.zoe_state_of_charge') | float(0) < 80 %}
       mdi:battery-10
     {% else %}
       mdi:battery-80
     {% endif %}

This will create entities in HomeAssistant with the corresponding MQTT message topics and start to track the data.

To-Do

  • Integrate WiFi manager with MQTT settings
  • make MQTT username/password optional
  • extract the OBD AT commands to separate file
  • create file editor for the OBD commands

About

Translation tool from ELM bluetooth dongle connected to OBD2 port in the car to MQTT server for HomeAssistant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.9%
  • C 1.1%