Create car milage chart

Hi guys,
I have a leasing car for 36 months that I’m currently tracking in google sheet.
For these 36 months Im allowed to drive 4 500 (Swedish miles) 45 000 km.

I have no added an integration with the Kia so the odometer of the car is updating every 30 minutes so so.

My goal is to create a chart (based on apex-chart integration) that can track the expected and the outcome of the km.

I basically need help adding/populating the expected usage data and the odometer data in to the same chart so I can track the outcome every day or week.

Odometer is in km:

Odometer sensor entity:
sensor.sportage_odometer

Example I’ve done in google sheet (blue is the expected line to follow, red is the actual outcome. I need to stay under the blue line after 36 month or it gets expensive… :stuck_out_tongue: - I have manually updated these data points every Sunday…)

Creating the sensors shouldn’t be an issue. It seems that you already have one of them in HA already (your current odometer reading?).

The issue is going to be creating the long term chart since HA won’t have access to those sensors after they get purged from the HA db, which I think happens at 10 days by default. So at most you could chart the last 10 days. But that won’t do you any good long term.

you could store those sensors in a long term data storage solution like Influxdb and you could chart them there but I don’t really know enough about Influxdb to help you there.

1 Like

What he said ^

But keeping a sensor of what your allowance is so far, is easyish. First setup an input datetime in helpers with the date you started the lease. Lets call it input_datetime.car_start

You are allowed 45000km over 3 years or 1095 days. That is 41.095 km per day (on average).

Then set up a template That gets the days since the start date and now() and multiply by 41.095. That is the figure you need to keep under.

{{(as_timestamp(now())-state_attr("input_datetime.car_start","timestamp")) / 86400 * 41.095 }}

You can set this up as a template sensor.

1 Like

Or a state_class of total_increasing will push it to HA’s own long-term stats. I do this for a few sensors, since I don’t want (need) the InfluxDB setup. It’s simple to implement and can be plotted.

1 Like

Can we access that data for long term charts?

Here is what I plot:


And here’s my configuration:

sensor.daily_internet_usage_in:
  friendly_name: 'Daily Downloads'
  icon: mdi:download
  state_class: total_increasing
sensor.daily_internet_usage_out:
  friendly_name: 'Daily Uploads'
  icon: mdi:upload
  state_class: total_increasing
sensor.apple_tv_playing:
  device_class: duration
  unit_of_measurement: h
  state_class: total_increasing
  - type: statistics-graph
    title: Daily Consumption
    entities:
      - sensor.daily_internet_usage_in
      - sensor.daily_internet_usage_out
    days_to_show: 7
    period: day
    chart_type: bar
    stat_types:
      - state
      - type: statistics-graph
        entities:
          - sensor.apple_tv_playing
        days_to_show: 7
        period: day
        chart_type: bar
        stat_types:
          - state
1 Like

How do I do that and how does that map what im allowed to drive? like 41.095 km / day? and cross run that with the odometer?

Add this into configuration.yaml?

sensor.expected_car_usage:
  friendly_name: 'Expected car usage'
  icon: mdi:car
  state_class: total_increasing

Add a graph to my GUI:

- type: statistics-graph
    title: Car usage
    entities:
      - sensor.expected_car_usage
      - sensor.sportage_odometer
    days_to_show: 30
    period: day
    chart_type: bar
    stat_types:
      - state

Will give it a try!

Yeah, try that out. You’d need to apply your own logic with additional sensors and automations to alert on the average and such, but I think this is a starting point. Just for completeness’ sake: My sensors are all utility meter sensors, but I don’t think that matters. The utility meter is only useful if you are going to reset/roll the data. In your case it’s basically one cycle. The cycle is optional. Just wanted to mention this, but don’t let this confuse you (possibly).

1 Like