2
I Built a Home Assistant Card to Track My EV Lease Mileage β Keeps me on Target! ππ
(old.reddit.com)
This is an automated archive made by the Lemmit Bot.
The original was posted on /r/homeassistant by /u/Boffy31 on 2025-03-03 10:41:26+00:00.
Hey HA folks! π
I wanted to share a custom Home Assistant dashboard card I built to track my EV lease mileage in real-time.
π§ How It Works
- Uses
sensor.leaf_odometer
to pull my carβs odometer reading - Compares it against my lease start mileage (242 miles) and the lease start date
- Calculates how many miles I should have driven based on an 8,000 miles/year allowance
- Displays whether Iβm over, under, or exactly on pace
- Changes the text color dynamically:
- π΄ Over limit
- π’ Under limit
π οΈ Code (for those interested)
I used custom:config-template-card
(From HACS) with a markdown card to display the status dynamically:
type: custom:config-template-card
entities:
- sensor.leaf_odometer
card:
type: markdown
title: Lease Mileage Position
content: >
{% set odometer = states('sensor.leaf_odometer') | float(0) %}
{% set lease_start_miles = 242 %}
{% set start_date_str = '2025-02-17' %}
{% set allocated_miles_per_year = 8000 %}
{% set start_date = as_datetime(start_date_str).astimezone() %}
{% set now_date = now().astimezone() %}
{% set days_elapsed = (now_date - start_date).days %}
{% set fraction_of_year = days_elapsed / 365 %}
{% set allowed_to_date = fraction_of_year * allocated_miles_per_year %}
{% set miles_since_lease_start = odometer - lease_start_miles %}
{% set difference = miles_since_lease_start - allowed_to_date %}
{% if difference > 0 %}
## Over by {{ difference | round(0) }} miles
{% elif difference < 0 %}
## Under by {{ difference | abs | round(0) }} miles
{% else %}
## Exactly on pace!
{% endif %}
π― Why I Made This
I wanted an easy way to see at a glance whether Iβm over or under my lease mileage without manually doing the maths. Now I can adjust my driving habits accordingly.
Would love to hear your thoughts. Any ideas for improving this?