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

Average fuel consumption issue #105565

Open
onlize opened this issue Dec 12, 2023 · 15 comments
Open

Average fuel consumption issue #105565

onlize opened this issue Dec 12, 2023 · 15 comments

Comments

@onlize
Copy link

onlize commented Dec 12, 2023

The problem

Subaru Average fuel consumption sensor does not show numbers between 26.7 and 27. Every time when I have 26.7, it shows correct information. When it goes to 26.8 or 26.9, it shows 27. When the Average fuel consumption drops to 26.7, it shows 26.7. After that, if I go higher, it shows 27.

What version of Home Assistant Core has the issue?

I set it up with 2023.9.x, updated every time, and now it is 2023.12.1 with the same issue.

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Subaru

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

Hey there @G-Two, mind taking a look at this issue as it has been labeled with an integration (subaru) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of subaru can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign subaru Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


subaru documentation
subaru source
(message by IssueLinks)

@G-Two
Copy link
Contributor

G-Two commented Jan 15, 2024

It looks like it is probably a rounding error during the conversion from the native units (liters per 100km) to miles per gallon.

https://github.com/home-assistant/core/blob/5b3e1306f82b2d370154e57657250b3107ae768a/homeassistant/components/subaru/sensor.py#L239C17-L239C17

In the past, the subaru API did not provide MPG, so the calculation had to be done. Looking at the most recent data, it looks like they now provide MPG so we should be able to avoid the rounding error in a future release.

@onlize
Copy link
Author

onlize commented Jan 18, 2024

I am not sure that is the problem. The average was going down. Started at 26.7. It ignored 26.6, it ignored 26.5 and today it finally dropped to 26.4 from 26.7.

@G-Two
Copy link
Contributor

G-Two commented Jan 20, 2024

It's not ignoring it, that's just the result of the lossy conversion from l/100km to mi/gal. The Subaru API reports avgFuelConsumptionLitersPer100Kilometers in 0.1 liter increments, which results in mi/gal conversions that change in ~0.3 mile increments. I've reproduced the error below.

Python 3.11.6 (main, Oct 28 2023, 15:08:23) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from homeassistant.util.unit_conversion import DistanceConverter, VolumeConverter
>>> from homeassistant.const import UnitOfLength, UnitOfVolume
>>> 
>>> L_PER_GAL = VolumeConverter.convert(1, UnitOfVolume.GALLONS, UnitOfVolume.LITERS)
>>> KM_PER_MI = DistanceConverter.convert(1, UnitOfLength.MILES, UnitOfLength.KILOMETERS)
>>> 
>>> L_PER_GAL
3.785411784
>>> KM_PER_MI
1.6093439999999999
>>> 
>>> #https://github.com/home-assistant/core/blob/5b3e1306f82b2d370154e57657250b3107ae768a/homeassistant/components/subaru/sensor.py#L239C17-L239C17
>>> #round((100.0 * L_PER_GAL) / (KM_PER_MI * avgFuelConsumptionLitersPer100Kilometers), 1)
>>>
>>> round((100.0 * L_PER_GAL) / (KM_PER_MI * 8.7), 1)
27.0
>>> round((100.0 * L_PER_GAL) / (KM_PER_MI * 8.8), 1)
26.7
>>> round((100.0 * L_PER_GAL) / (KM_PER_MI * 8.9), 1)
26.4
>>> 

The good news is that the Subaru API now appears to directly report avgFuelConsumptionMpg in addition to avgFuelConsumptionLitersPer100Kilometers, so we should be able to use that value directly instead of the lossy calculation.

Before I can implement the change, I'll need to see your HA generated device diagnostics report during a time when the HA reported fuel consumption state doesn't exactly match what your actual vehicle is showing. Please paste or attach the diagnostics info to this issue.

@onlize
Copy link
Author

onlize commented Jan 21, 2024

I'd be happy to do this, but please tell me how.

@G-Two
Copy link
Contributor

G-Two commented Jan 21, 2024

During a time when the fuel consumption is incorrect, navigate to:
Settings -> Devices & services -> Subaru -> 1 Device -> Download diagnostics

image

Check the file contents to ensure it doesn't contain any information that should be redacted, then attach to this issue.

Thanks!

@onlize
Copy link
Author

onlize commented Jan 21, 2024

Here is the file. The car shows 26.3, but HA shows 26.4.
subaru-c6b0503fe64918d3fb4d68dd4b5f22c6-2023 Forester Sport-3cf33d68e8c8aae1686426a46491e39c.json.txt

@G-Two
Copy link
Contributor

G-Two commented Mar 24, 2024

@onlize unfortunately the diagnostics file wasn't helpful since it only shows the data after it has been processed by subarulink and home assistant (i.e. it's the same incorrect data). I just submitted a PR #114119 that will return all the raw API data from Subaru, which will help. Once that PR is added to the next HA release, you'll be able to grab a more detailed diagnostic that shows every bit of data. This will help me see where to get a more accurate fuel consumption value.

@onlize
Copy link
Author

onlize commented Mar 25, 2024

Okay, thank you. Please let me know when you want me to send you new logs.

@G-Two
Copy link
Contributor

G-Two commented Jun 11, 2024

@onlize the PR has been merged, please send new device diagnostics dump, and I can look into it with more detail now.

@onlize
Copy link
Author

onlize commented Jun 20, 2024

Hi, sorry for delay. Here is the latest diagnostic.
subaru-c6b0503fe64918d3fb4d68dd4b5f22c6-2023 Forester Sport-3cf33d68e8c8aae1686426a46491e39c.json

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@onlize
Copy link
Author

onlize commented Sep 19, 2024

I have the latest version of Home Assistant installed and I still have the same issue.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@onlize
Copy link
Author

onlize commented Dec 18, 2024

Hi, I have the latest version of HA and the issue is not fixed yet.

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

No branches or pull requests

3 participants