Skip to content

feat: add cost per mileage to trips dashboard #4678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jheredianet
Copy link
Contributor

This is a little improvement to the Trips dashboard. It adds information about the cost per mileage.

Copy link

netlify bot commented Apr 19, 2025

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit a4be4f6
🔍 Latest deploy log https://app.netlify.com/sites/teslamate/deploys/680a553a58b821000742d7db
😎 Deploy Preview https://deploy-preview-4678--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@swiffer
Copy link
Collaborator

swiffer commented Apr 19, 2025

The value is misleading if battery level on beginning of trip and end of trip differs, right?

@JakobLichterfeld JakobLichterfeld changed the title Add cost per mileage feat: add cost per mileage to trips dashboard Apr 20, 2025
@JakobLichterfeld JakobLichterfeld added enhancement New feature or request area:dashboard Related to a Grafana dashboard labels Apr 20, 2025
@JakobLichterfeld JakobLichterfeld marked this pull request as draft April 21, 2025 08:04
@JakobLichterfeld
Copy link
Member

Adittionally, please ensure

"When making larger changes to Grafana Dashboards please include updated screenshots (1920x1080 @ x2, Grafana running in Kiosk mode) in ./website/static/screenshots. Ensure to blur sensitive information."

(https://docs.teslamate.org/docs/development#making-changes-to-grafana-dashboards)

@jheredianet
Copy link
Contributor Author

misleading

I don't understand what you mean. To estimate the cost per mileage, I'm just dividing the cost / mileage (obtained by the odometer). I'm not using the SOC. So in a Trip it's possible to have the battery level with the same value or more than the initial value when starting a trip, because when you travel you usually charge the battery on the road, one o more times.

@jheredianet
Copy link
Contributor Author

Adittionally, please ensure

"When making larger changes to Grafana Dashboards please include updated screenshots (1920x1080 @ x2, Grafana running in Kiosk mode) in ./website/static/screenshots. Ensure to blur sensitive information."

(https://docs.teslamate.org/docs/development#making-changes-to-grafana-dashboards)

Done!

@swiffer
Copy link
Collaborator

swiffer commented Apr 24, 2025

👍 can we keep size at 3840x2160 ?

@jheredianet jheredianet marked this pull request as ready for review April 24, 2025 15:16
@swiffer
Copy link
Collaborator

swiffer commented Apr 24, 2025

misleading

I don't understand what you mean. To estimate the cost per mileage, I'm just dividing the cost / mileage (obtained by the odometer). I'm not using the SOC. So in a Trip it's possible to have the battery level with the same value or more than the initial value when starting a trip, because when you travel you usually charge the battery on the road, one o more times.

Assume you start your trip with a full battery, drive, charge, drive, end your trip.

See calc for consumption which takes this into account.

I would add a note saying cost can vary based on soc at start / end at least. Same for totals).

@swiffer
Copy link
Collaborator

swiffer commented Apr 24, 2025

What about (consumption/1000 * avg price per kwh * km) driven.

Or a hint / (N/A) if soc before first drive differs more than x% when compared with soc after last charge or drive in selected period.

@jheredianet
Copy link
Contributor Author

Assume you start your trip with a full battery, drive, charge, drive, end your trip.

See calc for consumption which takes this into account.

I would add a note saying cost can vary based on soc at start / end at least. Same for totals).

Sorry, but I still don't understand. If I'm going on a trip, the SOC (State Of Charge) doesn't matter. It's simply that if charging at home + charging on the road cost me X € and I've traveled Y kilometers, then X/Y gives me the cost per km, or multiplied by 100, it would be the cost per 100 km. The part I don't understand here is what SOC or Consumption has to do with it.

@swiffer
Copy link
Collaborator

swiffer commented Apr 25, 2025

Sorry, was on mobile - the explanation was a little rough.

Your calculation is completely right - but only if you are charging as much energy as needed for driving.

scenario:

beginning of trip
30% state of charge - you charge to 90% - cost: 4 eur
driving 350km to 10% of charge
charging to 50% - cost: 3 eur
end of trip

total cost: 7 eur, cost per 100km: 2 eur

but - you end up with 20% more energy in your battery than what you have had at the beginning of the trip.

the total /per 100km cost would be lower if only charged to 30% at the end of your trip.

@jheredianet
Copy link
Contributor Author

Your calculation is completely right - but only if you are charging as much energy as needed for driving.

scenario:

beginning of trip 30% state of charge - you charge to 90% - cost: 4 eur driving 350km to 10% of charge charging to 50% - cost: 3 eur end of trip

total cost: 7 eur, cost per 100km: 2 eur

but - you end up with 20% more energy in your battery than what you have had at the beginning of the trip.

the total /per 100km cost would be lower if only charged to 30% at the end of your trip.

Ok, I understand your point. Normally, on a trip, you always leave home with the highest possible SOC and charge only enough to get to your destination.
But, if you need to be more precise, the ideal would be to end the trip at the same SOC you left with. If that's the case, what I've often done is:

Since this dashboard allows you to select the start and end date (which can be hours, days, or weeks), what I've done is to set the start and end dates and times (before and after the trip) so that the SOC matches at both ends.

For example, I leave the car charging overnight, leave at 6 a.m., make the trip, charge along the way, and arrive at my destination, let's say with 30%. So, what I do is to use this dashboard and set the start date and time when the car was at 30% (to match the end SOC of the whole trip). This way, the price would be more accurate, as you indicate.

What I don't want to include is the consumption variable in the calculation, because it could happen that I went on a picnic in the countryside and had the car stopped hours with the doors open, the music playing, and the Sentinel active. Therefore, it's energy consumption that wasn't necessarily used to move the car. I don't know if I explained myself well.

In any case, what estimation do you consider appropriate for this? Because what you proposed previously (consumption/1000 * avg price per kwh * km) driven, I don't think is accurate either.

I think the goal of this dashboard is for the user to know how much energy has been spent during a trip from start to finish.

@JakobLichterfeld
Copy link
Member

JakobLichterfeld commented Apr 26, 2025

Ok, I understand your point. Normally, on a trip, you always leave home with the highest possible SOC and charge only enough to get to your destination.

This is only valid for some users. For users without a charging point at home, or for users without a charging point at their destination, the approach is completely different. Even with a charger at home leaving with 100% doesn't make sense it many cases.

Personally, the only solution I can see is to manually set the cost of charging and calculate the price per km in the relevant time frame.

@JakobLichterfeld JakobLichterfeld marked this pull request as draft April 26, 2025 07:32
@jheredianet jheredianet requested a review from swiffer April 26, 2025 07:35
@jheredianet
Copy link
Contributor Author

jheredianet commented Apr 26, 2025

Ok, I understand your point. Normally, on a trip, you always leave home with the highest possible SOC and charge only enough to get to your destination.

This is only valid for some users. For users without a charging point at home, or for users without a charging point at their destination, the approach is completely different. Even with a charger at home leaving with 100% doesn't make sense it many cases.

I believe it doesn't matter where you charge, at home or on the street. In any case, there's always a price to pay. And that's what it's all about: knowing how much your trip cost, not precisely by the meter travelled, but rather a global estimate of the expense.

Personally, the only solution I can see is to manually set the cost of charging and calculate the price per km in the relevant time frame.

In Teslamate, you actually always have to enter the charging costs manually (unless you have a geofence), and in this panel, those are the costs it uses to calculate.

Based on your comments, are you suggesting not including this information panel?

@JakobLichterfeld
Copy link
Member

What I don't want to include is the consumption variable in the calculation, because it could happen that I went on a picnic in the countryside and had the car stopped hours with the doors open, the music playing, and the Sentinel active. Therefore, it's energy consumption that wasn't necessarily used to move the car.

As a user, this is consumed energy for that specific trip, imo.

Based on your comments, are you suggesting not including this information panel?

In the suggested way it is not matching users expectations as you can see on the discussion.

@jheredianet
Copy link
Contributor Author

What I don't want to include is the consumption variable in the calculation, because it could happen that I went on a picnic in the countryside and had the car stopped hours with the doors open, the music playing, and the Sentinel active. Therefore, it's energy consumption that wasn't necessarily used to move the car.

As a user, this is consumed energy for that specific trip, imo.

Yes, you are right. The actual estimation considers it (the actual cost per km with be a little higher)

Based on your comments, are you suggesting not including this information panel?

In the suggested way it is not matching users expectations as you can see on the discussion.

Ok, feel free to discard this PR. I will include it on my own Custom Grafana Dashboards repository for those who finds it useful.

@swiffer
Copy link
Collaborator

swiffer commented Apr 26, 2025

Currently on a longer trip (cologne to barcelona). Will play around with some calculations afterwards.

@JakobLichterfeld
Copy link
Member

Currently on a longer trip (cologne to barcelona).

Safe trip!

Ok, feel free to discard this PR. I will include it on my own Custom Grafana Dashboards repository for those who finds it useful.

I think the idea is a great addition from a user perspective! I just want to make sure we are on the same page.

Will play around with some calculations afterwards.

Great idea, so we can all come to a common understanding and solution @swiffer and @jheredianet

@jheredianet
Copy link
Contributor Author

jheredianet commented Apr 26, 2025

Currently on a longer trip (cologne to barcelona). Will play around with some calculations afterwards.

Have a nice trip 👍🏼

BTW, if you ever come to Madrid, ping me, we can share a time together 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dashboard Related to a Grafana dashboard enhancement New feature or request waiting for feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants