VW to ABRP via Home Assistant

I have a Volkswagen ID series car that I’m pretty happy with. The car automatically uploads telemetry such as the current battery state of charge and, with a bit of work, this can be pulled into Home Assistant for viewing and then re-exported to A Better Route Planner to give live range planning.

First, add ha_vwid as a custom component to your Home Assistant installation. I did this by:

cd /data/hass/third_party
git clone https://github.com/raymondd78/ha_vwid
cd ../custom_components
ln -s ../third_party/ha_vwid/custom_components/vwid
systemctl restart hass

The data had steps in it that looked like VW was throttling my queries, so I reduced the poll rate as well:

--- a/custom_components/vwid/sensor.py
+++ b/custom_components/vwid/sensor.py
@@ -80,7 +80,7 @@ async def async_setup_entry(
         _LOGGER,
         name = "VW ID Sensor",
         update_method = async_update_data,
-        update_interval = timedelta(seconds=30),
+        update_interval = timedelta(seconds=121),
     )
 
     # Fetch initial data so we have data when entities subscribe

Next, go to the Home Assistant UI and enable the Volkswagen ID integration. You’ll need your We Connect ID user name, password, and VIN. Once done you can add a panel showing the vehicle highlights:

Home Assistant panel showing the vehicle data

Now that Home Assistant has the data, create a command that can post the data to the Iternio Telemetry API:

rest_command:
  update_abrp:
    method: POST
    headers:
      authorization: !secret abrp_api_key
    content_type: "charset=utf-8; application/x-www-form-urlencoded"
    url: >
      {% set tlm = {
      "utc": float(as_timestamp(utcnow())),
      "soc": states('sensor.volkswagen_id_state_of_charge'),
      "est_battery_range": float(states('sensor.volkswagen_id_current_range_in_km')),
      "is_charging": int(states('sensor.volkswagen_id_charge_rate')) > 0,
      } -%}
      https://api.iternio.com/1/tlm/send?token={{token}}&tlm={{tlm|to_json|urlencode}}

Note that this takes the telemetry, encodes it as JSON, then posts it as a query parameter. You can add other types to the tlm dict.

See the API documentation on how to obtain an API key. Once you have this, add it to secrets.yaml like abrp_api_key: APIKEY 12341234-1234-1234-1234-12312341234.

Finally, log into ABRP and use the ABRP OBD Connection > Link generic section to get a token for your vehicle. Use this to create an automation rule that runs the REST command whenever the range changes or time passes:

- alias: Push car to ABRP
  trigger:
    - platform: state
      entity_id: sensor.volkswagen_id_current_range_in_km
      to:
    - platform: time_pattern
      minutes: "/8"
  action:
    - service: rest_command.update_abrp
      data:
        token: the-token-you-get-from-the-link-generic-ui-in-abrp

As a bonus, if you enable the Home Assistant Prometheus integration then you can also graph the charging and time remaining:

Grafana dashboard showing state of charge and time remaining

and then use an expression like

predict_linear((homeassistant_sensor_unit_minutes>0)[30m:2m], 0) 
  unless (homeassistant_sensor_unit_minutes==0)

to get a finer estimate of when the charge will complete and alert when it’s almost done.

Avatar
Michael Hope
Software Engineer