Categories
Uncategorised

How to add OVMS (open vehicles) to Home Assistant

OVMS (Open Vehicles) is a great hardware module that connects to my Nissan LEAF and allows me to perform remote functions like turning on the climate control, checking charge status, range, etc. I’m also a big fan of Home Assistant, and have almost everything in my house hooked up to it. There is no official (or unofficial) integration for OVMS to Home Assistant. However, OVMS has a HTTP API, and Home Assistant supports generic RESTful sensors.

Read on to find out how to hook up your OVMS module to Home Assistant!

Getting Started

Firstly, you’ll need your OVMS module to be hooked up, configured correctly, and working with the default OVMS app. Once your app is connected to your OVMS module and you can see live data coming through, it’s time to move on.

Generating an API Token

You’ll need to generate an API Token from the openvehicles.com API. To do this, you’ll need to open up the Terminal on your computer. Once there, type the command below and hit enter, replacing <USERNAME> and <PASSWORD> with your OVMS username/password that you use to login to openvehicles.com.

curl --location --request POST 'https://api.openvehicles.com:6869/api/token?username=<USERNAME>&password=<PASSWORD>'

After you run that command, you will see an output on your screen similar to the one below. You’ll need to copy your API Token (highlighted in bold) to a safe place.

{"application":"notspecified","owner":"<YOUR_USERNAME>","permit":"auth","purpose":"notspecified","token":"RiVINShnbS0wNG5tJUlNYUZJbUNeR1NcYSdwM0l7aDpWOyE2QkQxSCwrLWh8Ow"}

Find your list of metrics

Now you need to find a list of all the metrics that you want available in home assistant. There are 3 main collections of metrics that the OVMS API makes available. These are Status, Charging, and Location. If you have a 2012 era Nissan LEAF like I do, skip below and copy my config file. Otherwise, read on.

To find all of the available metrics, run the following commands in your terminal. Make a note of all the metrics that you want available in Home Assistant. Be sure to replace <USERNAME> with your username, <VEHICLE_ID> with your OVMS vehicle ID, and <YOUR_API_TOKEN> with the token you retrieved earlier.

Status

curl --location --request GET 'https://api.openvehicles.com:6869/api/status/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_TOKEN>'

Charging

curl --location --request GET 'https://api.openvehicles.com:6869/api/charge/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_TOKEN>'

Location

curl --location --request GET 'https://api.openvehicles.com:6869/api/charge/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_TOKEN>'

Home Assistant Configuration

Now you’ll need to configure Home Assistant to retrieve data from the OVMS API and pull out the metrics that you want. Add a configuration to your configuration.yaml in the sensor section like below. You can update the scan_interval to whatever you’d like, but be considerate and don’t go lower than when your OVMS sends updates, or at a minimum every 60 seconds.

sensor:
  - platform: rest
    scan_interval: 120
    name: car_status
    resource: https://api.openvehicles.com:6869/api/status/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
    value_template: "{{ value_json.soc }}"
    json_attributes:
      - soh
      - soc
      - etc...

  - platform: rest
    scan_interval: 120
    name: car_location
    resource: https://api.openvehicles.com:6869/api/location/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
    value_template: "{{ value_json.longitude }},{{ value_json.latitude }}"
    json_attributes:
      - longitude
      - latitude
      - etc...

  - platform: rest
    scan_interval: 60
    name: car_charging
    resource: https://api.openvehicles.com:6869/api/charge/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
    value_template: "{{ value_json.chargestate }}"
    json_attributes:
      - battvoltage
      - cac100
      - carawake
      - caron
      - etc...

Save and validate

Save the new configuration, and use the handy “Check Configuration” button on the Configuration > Server Controls page. If there are no errors, then restart your home assistant server.

When the server starts back up, you should see some new entities called sensor.car_status, sensor.car_location, and sensor.car_charging. Use this in your automations or expose them via HomeKit like I did! Check below for my full configuration, including HomeKit friendly template sensors (although HomeKit does not support this very well as it doesn’t have native EV support).

HomeKit Example

You can see what this looks like in the screenshot from my iPhone below. I’ve configured the SoC as a humidity sensor so it reads as a percentage, and the range as an illuminance sensor. Unfortunately, HomeKit lacks an EV entity type, so this is the best I could come up with.

If you name the sensors something appropriate, you can even ask Siri to tell you the state of charge or range, if you can deal with the annoying response as it thinks they’re different types of sensors. Hopefully Apple adds an EV entity to HomeKit in the future, so a proper integration can be made!

Example config for a 2012 Nissan LEAF

- sensor:
    - name: car_soc_homekit
      state: "{{ state_attr('sensor.car_status', 'soc') }}"
      icon: "mdi:car-electric"
      device_class: humidity
      unit_of_measurement: "%"

    - name: car_range_homekit
      state: '{{ (float(state_attr("sensor.car_status", "estimatedrange")) * 1.25) | int }}'
      icon: "mdi:speedometer-slow"
      device_class: illuminance

    - name: car_soc
      state: "{[ state_attr('sensor.car_status', 'soc') }}"
      icon: "mdi:car-electric"
      device_class: battery

    - name: car_range
      state: '{{ (float(state_attr("sensor.car_status", "estimatedrange")) * 1.25) | int }}'
      icon: "mdi:speedometer-slow"

- binary_sensor:
    - name: car_charging
      state: "{{ state_attr('sensor.car_status', 'charging') }}"
      icon: "mdi:ev-station"

- platform: rest
  scan_interval: 60
  name: car_status
  resource: https://api.openvehicles.com:6869/api/status/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
  value_template: "{{ value_json.soc }}"
  json_attributes:
    - alarmsounding
    - bt_open
    - cac100
    - carawake
    - carlocked
    - caron
    - chargestate
    - charging
    - charging_12v
    - cooldown_active
    - cp_dooropen
    - estimatedrange
    - fl_dooropen
    - fr_dooropen
    - handbrake
    - idealrange
    - idealrange_max
    - mode
    - odometer
    - parkingtimer
    - pilotpresent
    - soc
    - soh
    - speed
    - staleambient
    - staletemps
    - temperature_ambient
    - temperature_battery
    - temperature_charger
    - temperature_motor
    - temperature_pem
    - tr_open
    - tripmeter
    - units
    - valetmode
    - vehicle12v
    - vehicle12v_current
    - vehicle12v_ref

- platform: rest
  scan_interval: 60
  name: car_location
  resource: https://api.openvehicles.com:6869/api/location/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
  value_template: "{{ value_json.longitude }},{{ value_json.latitude }}"
  json_attributes:
    - altitude
    - direction
    - drivemode
    - energyrecd
    - energyused
    - gpslock
    - invefficiency
    - invpower
    - latitude
    - longitude
    - power
    - speed
    - stalegps
    - tripmeter

- platform: rest
  scan_interval: 30
  name: car_charging
  resource: https://api.openvehicles.com:6869/api/status/<VEHICLE_ID>?username=<USERNAME>&password=<YOUR_API_KEY>
  value_template: "{{ value_json.chargestate }}"
  json_attributes:
    - battvoltage
    - cac100
    - carawake
    - caron
    - charge_estimate
    - charge_etr_full
    - charge_etr_limit
    - charge_etr_range
    - charge_etr_soc
    - charge_limit_range
    - charge_limit_soc
    - chargeb4
    - chargecurrent
    - chargeduration
    - chargekwh
    - chargelimit
    - chargepower
    - chargepowerinput
    - chargerefficiency
    - chargestarttime
    - chargestate
    - chargesubstate
    - chargetimermode
    - chargetimerstale
    - chargetype
    - charging
    - charging_12v
    - cooldown_active
    - cooldown_tbattery
    - cooldown_timelimit
    - cp_dooropen
    - estimatedrange
    - idealrange
    - idealrange_max
    - linevoltage
    - mode
    - pilotpresent
    - soc
    - soh
    - staleambient
    - staletemps
    - temperature_ambient
    - temperature_battery
    - temperature_charger
    - temperature_motor
    - temperature_pem
    - units
    - vehicle12v
    - vehicle12v_current
    - vehicle12v_ref

14 replies on “How to add OVMS (open vehicles) to Home Assistant”

Fantastic your job, I’m Italian and owner of a Twizy with OVMS
if you want I can give you my OVMS login credentials to integrate Twizy too, would you like to try? i am not able to do anything in computer science, so i need your help.
Do you think it is possible?
Thank you
Fantastico il tuo lavoro, sono italiano e possessore di una Twizy con OVMS
se vuoi posso darti le mie credenziali di accesso ad OVMS per integrare anche Twizy, ti va di provare? non sono capace di fare nulla in informatica, perciò ho bisogno del tuo aiuto.
Pensi sia possibile?
Grazie

If you have an OVMS module already installed, it should be very similar to the guide above. Unfortunately I don’t really have the time to help you out, but if you get stuck with anything specific feel free to drop another comment and I’ll do my best to point you in the right direction.

Generating API (first step) failed.
I receive this error message:
curl: (35) error:1400410B:SSL routines:CONNECT_CR_SRVR_HELLO:wrong version number

What do I wrong?

There is an error in the above. The https port is 6869, not 6868. This is why we get the SSL wrong version number error.

Peter, change port number from 6868 to 6869. (You will need to do that in all the URLs above). Also a typo in the example YAML car_charging URL (refers to “status” instead of “charge”)

curl –location –request GET ‘https://api.openvehicles.com:6869/api/status/VEHICLENAME?username=USERNAME&password=APIKEY’
curl: (3) URL using bad/illegal format or missing URL
Der Befehl “password” ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

Anyone has an idea?

Hi, I can’t understand what language that is, but I think it’s the same problem I was having, it says something like “it’s not an internal or external command”. I solved it by changing the quotes on the URL (I had to ask chat-GPT), in your case it should look like:
curl –location –request GET “https://api.openvehicles.com:6869/api/status/VEHICLENAME?username=USERNAME&password=APIKEY”
I hope it helps.

I have problems with saving or outputting individual values from the sum of the values from e.g. Status in converted values. The value of the kilometre counter is output without a decimal point, i.e. too large by a factor of 10. However, I cannot manage this conversion directly in the sensor configuration, nor later in the entity card.
How should I deal with this? Can you give an example?

platform: rest
scan_interval: 120
name: twizy_status
resource: https://ovms.dexters-web.de:6869/api/status/?username=&password=
value_template: “{{ value_json.alarmsounding }},{{ value_json.bt_open }},{{ value_json.cac100 }},{{ value_json.carawake }},{{ value_json.carlocked }},{{ value_json.caron }},{{ value_json.chargepowerinput }},{{ value_json.chargerefficiency }},{{ value_json.chargestate }},{{ value_json.charging }},{{ value_json.charging_12v }},{{ value_json.cooldown_active }},{{ value_json.cp_dooropen }},{{ value_json.estimatedrange }},{{ fl_dooropen }},{{ value_json.fr_dooropen }},{{ value_json.handbrake }},{{ value_json.idealrange }},{{ value_json.idealrange_max }},{{ value_json.m_msgage_d }},{{ value_json.m_msgage_s }},{{ value_json.m_msgtime_d }},{{ value_json.m_msgtime_s }},{{ value_json.mode }},{{ value_json.odometer }},{{ value_json.parkingtimer }},{{ value_json.pilotpresent }},{{ value_json.soc }},{{ value_json.soh }},{{ value_json.speed }},{{ value_json.staleambient }},{{ value_json.staletemps }},{{ value_json.temperature_ambient }},{{ value_json.temperature_battery }},{{ value_json.temperature_cabin }},{{ value_json.temperature_charger }},{{ value_json.temperature_motor }},{{ value_json.temperature_pem }},{{ value_json.tr_open }},{{ value_json.tripmeter }},{{ value_json.units }},{{ value_json.valetmode }},{{ value_json.vehicle12v }},{{ value_json.vehicle12v_current }},{{ value_json.vehicle12v_ref }}”
json_attributes:
– alarmsounding
– bt_open
– cac100
– carawake
– carlocked
– caron
– chargepowerinput
– chargerefficiency
– chargestate
– charging
– charging_12v
– cooldown_active
– cp_dooropen
– estimatedrange
– fl_dooropen
– fr_dooropen
– handbrake
– idealrange
– idealrange_max
– m_msgage_d
– m_msgage_s
– m_msgtime_d
– m_msgtime_s
– mode
– odometer
– parkingtimer
– pilotpresent
– soc
– soh
– speed
– staleambient
– staletemps
– temperature_ambient
– temperature_battery
– temperature_cabin
– temperature_charger
– temperature_motor
– temperature_pem
– tr_open
– tripmeter
– units
– valetmode
– vehicle12v
– vehicle12v_current
– vehicle12v_ref

Leave a Reply

Your email address will not be published.