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

fix: always show charge energy for current and last session #414

Merged
merged 2 commits into from
Dec 9, 2022

Conversation

carleeno
Copy link
Contributor

@carleeno carleeno commented Dec 8, 2022

Fixes #295 and #413

Based on the information here, I realized that the logic to set the energy added to 0 when not charging was breaking energy calculations.

The actual energy added value is reset by tesla on it's own, so when we manually set 0, and then revert back to the tesla's value if charging starts again for the same charge session, it will cause the energy dashboard to incorrectly sum the deltas.

It appears that TOTAL_INCREASING is the right state class to use, as we don't expect the value to decrease substantially (a 10% allowance is built in). So if we just rely on the car's own charging state to reset appropriately, the energy dashboard should reflect usage correctly.

What this changes for users:

  • The energy added sensor will continue to report the last energy added value from the most recent charging session
  • The energy dashboard will no longer double/triple the energy usage for single charging sessions which pause/resume
  • The energy added sensor will show unknown instead of 0 when the data is not available (if the vehicle is offline/asleep when the integration is loaded)

Test plan

Tested in dev container with a model 3:

  • ensured while unplugged, the energy_added sensor still showed the last value from the previous charging session
  • ensured that upon plugging in a charger, the energy_added sensor reset to 0
  • ensured the energy_added sensor increased as it charged
  • ensured that when pausing charging (remaining plugged in) the energy_added sensor did not reset to 0
  • let the car sleep while plugged in then reloaded integration to get an "unknown" state for energey_added sensor
  • woke the car up and ensured the energy_added sensor reflected the last value
  • at the end of the charging session, ensured that the energy dashboard amount reflected the actual sensor

energy_added sensor showing that it did not reset to zero when pausing (the blank area is "Unknown" from reloading while asleep)
image

The energy dashboard value matches the sensor (it did not double it, even after the "unknown" period)
image

@carleeno
Copy link
Contributor Author

carleeno commented Dec 8, 2022

in draft while I test that the unknown behavior doesn't cause any problems in the energy dashboard

@evolucja
Copy link

evolucja commented Dec 8, 2022

I was about to give a try implementing this change but many thanks you've done it! :)

@carleeno carleeno marked this pull request as ready for review December 9, 2022 02:18
@alandtse alandtse merged commit be6c1f0 into alandtse:dev Dec 9, 2022
@evolucja
Copy link

evolucja commented Dec 16, 2022

further discussion here to not duplicate:
#413

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

Successfully merging this pull request may close these issues.

V3 sensor.vehicle_energy_added incompatible with energy dashboard
3 participants