Skip to content

Commit

Permalink
Added consumption efficiency factor configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuinigeRijder committed Oct 8, 2024
1 parent d6aaf7e commit 1e1b506
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ use_geocode_email = True
language = en
odometer_metric = km
include_regenerate_in_consumption = False
consumption_efficiency_factor_dailystats = 1.0
consumption_efficiency_factor_summary = 1.0
```

Explanation of the configuration items:
Expand All @@ -219,11 +221,15 @@ Explanation of the configuration items:
- pin: pincode of your bluelink account, required for CANADA, and potentially USA, otherwise pass a blank string
- use_geocode: (default: True) find address with the longitude/latitude for each entry
- use_geocode_email: (default: True) use email to avoid abuse of address lookup
- language: (default: en) the Bluelink App is reset to English for users who have set another language in the Bluelink App in Europe when using hyundai_kia_connect_api, you can configure another language as workaround
- language: (default: en) the Bluelink App is reset to English for users who have set another language in the Bluelink App in Europe when using hyundai_kia_connect_api, you can configure another language as workaround. See Note 2
- odometer_metric, e.g. km or mi
- include_regenerate_in_consumption, in [R3.23.0](https://github.com/ZuinigeRijder/hyundai_kia_connect_monitor/releases/tag/R3.23.0) the regeneration is taken into account for the consumption in daily stats, to better match the boardcomputer values. However, some users have better results in the old situation. Included a setting, default is the old situation before R3.23.0.
- include_regenerate_in_consumption, when set to True the regeneration is taken into account for the consumption calculation in daily stats. However, I think that the next 2 configuration items will better match the boardcomputer values.
- consumption_efficiency_factor_dailystats, see Note 1
- consumption_efficiency_factor_summary, see Note 1

*Note: language is only implemented for Europe currently.*
*Note 1: I think that the consumption values ​​of the on-board computer are corrected with an efficiency number, e.g. 1 kWh of energy results in 0.9 kWh of real energy (losses when converting battery kWh by the car). So therefor I introduced an efficiency configuration factor in monitor.cfg, consumption_efficiency_factor_dailystats and consumption_efficiency_factor_summary. For example, when setting this to 0.9, 10% of the energy is lost during the conversion and is used in the consumption calculation. Default the values are 1.0, so no correction.*

*Note2: language is only implemented for Europe currently.*

[For a list of language codes, see here.](https://www.science.co.il/language/Codes.php). Currently in Europe the Bluelink App shows the following languages:
- "en" English
Expand Down
9 changes: 9 additions & 0 deletions dailystats.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def dbg(line: str) -> bool:
get(monitor_settings, "include_regenerate_in_consumption", "False").lower()
== "true"
)
CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS = to_float(
get(monitor_settings, "consumption_efficiency_factor_dailystats", "1.0")
)


# indexes to splitted monitor.dailystats.csv items
DATE = 0
Expand Down Expand Up @@ -478,6 +482,8 @@ def print_tripinfo(
if kwh_consumed > 0.0:
kwh = f"({float_to_string_no_trailing_zero(kwh_consumed)}kWh)"
km_mi_per_kwh = safe_divide(distance_summary_trip, kwh_consumed)
if CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS > 0.0:
km_mi_per_kwh *= CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS
consumption = (
f"({float_to_string_no_trailing_zero(km_mi_per_kwh)}{ODO_METRIC}/kWh)"
)
Expand Down Expand Up @@ -544,6 +550,9 @@ def print_dailystats(
battery_care_perc = safe_divide(batterycare * 100, consumed)
km_mi_per_kwh = safe_divide(distance, consumed / 1000)
kwh_per_km_mi = safe_divide(100, km_mi_per_kwh)
if CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS > 0.0:
km_mi_per_kwh *= CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS
kwh_per_km_mi /= CONSUMPTION_EFFICIENCY_FACTOR_DAILYSTATS

consumed_kwh = consumed / 1000
regenerated_kwh = regenerated / 1000
Expand Down
2 changes: 2 additions & 0 deletions monitor.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ use_geocode_email = True
language = en
odometer_metric = km
include_regenerate_in_consumption = False
consumption_efficiency_factor_dailystats = 1.0
consumption_efficiency_factor_summary = 1.0
8 changes: 7 additions & 1 deletion summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def dbg(line: str) -> bool:
config_parser.read(get_filepath("monitor.cfg"))
monitor_settings = dict(config_parser.items("monitor"))
ODO_METRIC = get(monitor_settings, "odometer_metric", "km").lower()
CONSUMPTION_EFFICIENCY_FACTOR_SUMMARY = to_float(
get(monitor_settings, "consumption_efficiency_factor_summary", "1.0")
)

config_parser.read(get_filepath("summary.cfg"))
summary_settings = dict(config_parser.items("summary"))
Expand Down Expand Up @@ -629,9 +632,12 @@ def print_summary(
cost = discharged_kwh * -AVERAGE_COST_PER_KWH
cost_str = f"{cost:.2f}"
km_mi_per_kwh = safe_divide(delta_odo, -discharged_kwh)
km_mi_per_kwh_str = f"{km_mi_per_kwh:.1f}"
if km_mi_per_kwh > 0.0:
kwh_per_km_mi = safe_divide(100, km_mi_per_kwh)
if CONSUMPTION_EFFICIENCY_FACTOR_SUMMARY > 0.0:
km_mi_per_kwh *= CONSUMPTION_EFFICIENCY_FACTOR_SUMMARY
kwh_per_km_mi /= CONSUMPTION_EFFICIENCY_FACTOR_SUMMARY
km_mi_per_kwh_str = f"{km_mi_per_kwh:.1f}"
kwh_per_km_mi_str = f"{kwh_per_km_mi:.1f}"
else:
# do not show positive discharges
Expand Down
2 changes: 1 addition & 1 deletion tests/OUTPUT/test.summary.log
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
TRIP, 2023-01-03, 12:22, 21857.5, 6.9, , -1.5, 4.8, 21.0, 0.36, 74, 75, 74, 76, 79, 79, 79, 79, , 1, 281, "29a; Westeinde; Besoijen; Waalwijk; Noord-Brabant; Nederland; 5141 AA; Nederland" ,
TRIP, 2023-01-03, 19:32, 21919.9, 62.4, , -10.9, 5.7, 17.5, 2.68, 59, 63, 59, 74, 81, 80, 79, 81, , 1, 219, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-03, Tue, 21919.9, 69.3, , -12.3, 5.6, 17.8, 3.04, 59, 70, 59, 76, 81, 80, 79, 81, , 2, 219, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-04, Wed, 21919.9, , , -7.3, 0.0, , 1.79, 49, 51, 49, 59, 88, 87, 81, 88, , , 182, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-04, Wed, 21919.9, , , -7.3, , , 1.79, 49, 51, 49, 59, 88, 87, 81, 88, , , 182, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
TRIP, 2023-01-06, 16:08, 21973.1, 53.2, , -5.1, 10.5, 9.6, 1.25, 42, 46, 42, 49, 86, 87, 86, 88, , 1, 156, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-06, Fri, 21973.1, 53.2, , -5.1, 10.5, 9.6, 1.25, 42, 45, 42, 49, 86, 87, 86, 88, , 1, 156, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
TRIP, 2023-01-07, 13:34, 21977.2, 4.1, , -1.5, 2.8, 35.4, 0.36, 40, 41, 40, 42, 88, 87, 86, 88, , 1, 155, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
Expand Down
2 changes: 1 addition & 1 deletion tests/OUTPUT/test.summary.logday
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Period, Date, Info, Odometer, Delta km, +kWh, -kWh, km/kWh, kWh/100km, Cost Euro, SOC%, Avg, Min, Max, 12V%, Avg, Min, Max, #Charging, #Trips, Range, Address ,
DAY, 2023-01-02, Mon, 21850.6, 3.5, , , , , , 76, 76, 76, 76, 79, 80, 79, 90, , 2, 294, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-03, Tue, 21919.9, 69.3, , -12.3, 5.6, 17.8, 3.04, 59, 70, 59, 76, 81, 80, 79, 81, , 2, 219, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-04, Wed, 21919.9, , , -7.3, 0.0, , 1.79, 49, 51, 49, 59, 88, 87, 81, 88, , , 182, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-04, Wed, 21919.9, , , -7.3, , , 1.79, 49, 51, 49, 59, 88, 87, 81, 88, , , 182, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-06, Fri, 21973.1, 53.2, , -5.1, 10.5, 9.6, 1.25, 42, 45, 42, 49, 86, 87, 86, 88, , 1, 156, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-07, Sat, 21977.2, 4.1, , -1.5, , , , 40, 41, 40, 42, 88, 87, 86, 88, , 1, 155, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
DAY, 2023-01-08, Sun, 22132.2, 155.0, 44.3, -22.5, 6.9, 14.5, 5.54, 70, 53, 19, 80, 89, 88, 86, 89, 1, 2, 265, "9;Kwakstraat; Duckstad; Nederland; 7054; AN" ,
Expand Down

0 comments on commit 1e1b506

Please sign in to comment.