Skip to content
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

General average does not match the value of the app #28

Open
luizfeliperc opened this issue Sep 4, 2023 · 2 comments
Open

General average does not match the value of the app #28

luizfeliperc opened this issue Sep 4, 2023 · 2 comments

Comments

@luizfeliperc
Copy link

When doing the app analysis, and the sensor attribute analysis, I noticed that the overall average is not the same as what it shows in the app.

General average showing the value of 7.17 km/L
image

General average showing the value of 2.90 km/L

image

@sthevenp
Copy link

I have experience the same so it would be great what calculation result shows in the sensor.

@koostamas
Copy link

I had the same issue, so I investigated and found out what the root cause is. The Drivvo API returns that higher number as the general average, because it calculates with the total volume including the last refuelling, but that's not correct, because the last tank of gas is not yet consumed (at the point of making the last log in the app anyway), so it shouldn't be included in the calculation. The good thing is that the integration returns (almost) everything that we need to calculate the correct value, so the correct formula for the data that we have access to is: (Total volume refuelings - Last refueling volume) / (Total volume refuelings * General fuel average) * 100. So I just created a template sensor with this template:

{% set entity_id = 'sensor.new_refuellings' %}
{% set total_volume = state_attr(entity_id, 'refuelling_volume_total') %}
{% set last_volume = state_attr(entity_id, 'refuelling_volume') %}
{% set drivvo_average = state_attr(entity_id, 'media_geral') %}
{{ (total_volume - last_volume) / (total_volume * drivvo_average) * 100 }}

By the way, this calculation results in the value being L/100 km, so if you want the original km/L unit, you need to change the formula to (Total volume refuelings * General fuel average) / (Total volume refuelings - Last refueling volume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants