this post was submitted on 03 Mar 2025
2 points (100.0% liked)

Home Assistant

414 readers
2 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY...

founded 2 years ago
MODERATORS
 
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?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here