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.
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… - 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.
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.
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.
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
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).