6 posts / 0 new
Last post
mdallaire
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.

https://github.com/mdallaire/ovms-hass-configs

 

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

sensors:
  - 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"

switch:
  - 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 
      on

    state_off: |
      Climate Control 
      off
    payload_on: "climatecontrol on"
    payload_off: "climatecontrol off"
    availability: 
      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: ''
trigger:
- platform: mqtt
topic: ovms/[mqtt-client-name]/[vehiculeID]//metric/v/e/heating
payload: 'no'
condition: []
action:
- service: switch.turn_off
data: {}
target:
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:

    leaf_2015:
    name: leaf_2015
    mac:
    icon:
    picture:
    track: true

  2. Create an automation with the following:

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

drobtravels
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.

mdallaire
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.

jdanders
I got stuck on that too. The

I got stuck on the status not working too. The response has a trailing space in it, and if you use the format proposed here a "smart" text editor will remove the trailing space. I fixed it by changing the YAML to a raw string instead of multiline:

    state_on: "Climate Control \non\n"
    state_off: "Climate Control \noff\n"

LeafySHV
Hi,

Hi,

I'd love to be able to do this with my own 2015 Nissan Leaf. But I'm struggling to understand how to configure OVMS for V3 as a starting point .. "For this to work you will need to have your OVMS configured to use MQTT (refered to Server V3 or OVMS V3)"

Can you point me in the direction of instructions? Can the OVMS module connect to a mosquito broker run as an add-on to home assistant?

jdanders
Another github repo

Hi, I just finished trying to create a complete set of YAML files for MQTT and OVMS. I borrowed the MQTT switch and button syntax from you -- thanks for that!

https://github.com/jdanders/ovms-leaf-home-assistant-yaml

Log in or register to post comments
randomness