3 posts / 0 new
Last post
Home-Assistant MQTT configs

EDIT: I made some changes and improvements to the configurations below but decided to move them to github to make it easier to work on going forward.



Here is an extract of my Home-Assistant config for various sensors and a pre-heat switch for my Leaf 2015 on OVMS. Hopefully it will be helpful to get people started with Home-Assistant and OVMS.

This will give you multiple sensors, a location device and a switch to turn on/off the pre-heat.

There is space for improvement, especialy with the drivetime/parktime where I would like to convert the second timestamp to a real time sensor in HA. So feedback is more than welcome :)

### This goes under your mqtt platform configuration

  - name: ovms_leaf_event
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/event"
  - name: ovms_leaf_charge_status
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/charging"
  - name: ovms_leaf_charge_state
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/state"
  - name: ovms_leaf_charge_duration
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/time"
    unit_of_measurement: "sec"
  - name: ovms_leaf_charge_voltage
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/voltage"
    unit_of_measurement: "V"
  - name: ovms_leaf_charge_amperage
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/current"
    unit_of_measurement: "A"
  - name: ovms_leaf_charge_max_amperage
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/climit"
    unit_of_measurement: "A"
  - name: ovms_leaf_charge_type
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/type"
  - name: ovms_leaf_charge_efficiency
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/efficiency"
    unit_of_measurement: "%"
  - name: ovms_leaf_charge_complete_duration
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/duration/full"
    unit_of_measurement: "min"
  - name: ovms_leaf_charge_kwh
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/c/kwh"
    unit_of_measurement: "kWh"
    value_template: "{{ value | round(2) }}"
    device_class: energy
  - name: ovms_leaf_soc
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/b/soc"
    unit_of_measurement: "%"
    device_class: battery
  - name: ovms_leaf_range_full
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/b/range/full"
    unit_of_measurement: "km"
    value_template: "{{ value | round(0) }}"
  - name: ovms_leaf_range_est
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/b/range/est"
    value_template: "{{ value | round(0) }}"
    unit_of_measurement: "km"
  - name: ovms_leaf_range_ideal
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/b/range/ideal"
    value_template: "{{ value | round(0) }}"
    unit_of_measurement: "km"
  - name: ovms_leaf_battery_temp
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/b/temp"
    value_template: "{{ value | round(0) }}"
    unit_of_measurement: "°C"
  - name: ovms_leaf_cabin_temp
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/e/cabintemp"
    value_template: "{{ value | round(0) }}"
    unit_of_measurement: "°C"
  - name: ovms_leaf_speed
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/p/speed"
    unit_of_measurement: "km/h"
  - name: ovms_leaf_odometer
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/p/odometer"
    unit_of_measurement: "km"
  - name: ovms_leaf_parktime
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/e/parktime"
    value_template: "{% set val2 = value | int %} {% if val2 is lt 60 %}{{val2}} sec{% elif val2 is ge 60 and val2 is lt 3600 %} {{val2//60}}min {% else %}{{ val2//3600}}h{{(val2%3600)// 60 }}{%endif%}"
  - name: ovms_leaf_parktime_raw
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/e/parktime"
  - name: ovms_leaf_drivetime_raw
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/e/drivetime"
  - name: ovms_leaf_mdm_network
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/m/net/mdm/network"
  - name: ovms_leaf_soh
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/xnl/v/b/soh/instrument"
    unit_of_measurement: "%"
  - name: ovms_leaf_latitude
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/p/latitude"
  - name: ovms_leaf_longitude
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/v/p/longitude"

  - name: Leaf Heating
    qos: 1
    command_topic: "ovms/[mqtt-client-name]/[vehiculeID]/client/home-assistant/command/1"
    state_topic: "ovms/[mqtt-client-name]/[vehiculeID]/client/home-assistant/response/1"
    state_on: |
      Climate Control 

    state_off: |
      Climate Control 
    payload_on: "climatecontrol on"
    payload_off: "climatecontrol off"
      topic: "ovms/[mqtt-client-name]/[vehiculeID]/metric/s/v3/connected"
      payload_available: "yes"
      payload_not_available: "no"

For the pre-heating, since the mqtt topic where its turned on and off is different from where the status is I created a small automation to turn the switch off based on the real status of the HVAC

- id: '12346' #Generated by automation interface
alias: Leaf - Status Heating
description: ''
- platform: mqtt
topic: ovms/[mqtt-client-name]/[vehiculeID]//metric/v/e/heating
payload: 'no'
condition: []
- service: switch.turn_off
data: {}
entity_id: switch.leaf_heating
mode: single


I also created an automation that combines the lat and long into a device_tracker for the car.

  1. In the device_tracker.yaml file add the following:

    name: leaf_2015
    track: true

  2. Create an automation with the following:

    - '12346' #Generated by automation interface
    alias: leaf location
    description: ''
    - platform: state
    entity_id: sensor.ovms_leaf_longitude
    - platform: state
    entity_id: sensor.ovms_leaf_latitude
    condition: []
    - service: device_tracker.see
    dev_id: leaf_2015
    - '{{ states(''sensor.ovms_leaf_latitude'') }}'
    - '{{ states(''sensor.ovms_leaf_longitude'') }}'
    mode: restart

Thank you!! I've been

Thank you!! I've been struggling with some of these.  The climate control switched worked but status did not display.  I'll have to experiment with that one a bit more.

FYI I managed to make the

FYI I managed to make the time based sensor work properly as Home Assistant timestamps devices. I put my code on github under https://github.com/mdallaire/ovms-hass-configs to make things easier to change in the future.

Log in or register to post comments