From 1e1b50679451cfaa847d7541a2c2abad766c95e9 Mon Sep 17 00:00:00 2001 From: Zuinige Rijder Date: Tue, 8 Oct 2024 12:14:28 +0200 Subject: [PATCH] Added consumption efficiency factor configuration --- README.md | 12 +++++++++--- dailystats.py | 9 +++++++++ monitor.cfg | 2 ++ summary.py | 8 +++++++- tests/OUTPUT/test.summary.log | 2 +- tests/OUTPUT/test.summary.logday | 2 +- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a4707bd..7e01b54 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/dailystats.py b/dailystats.py index ee51505..40cdd93 100644 --- a/dailystats.py +++ b/dailystats.py @@ -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 @@ -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)" ) @@ -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 diff --git a/monitor.cfg b/monitor.cfg index 2796f65..9812e78 100644 --- a/monitor.cfg +++ b/monitor.cfg @@ -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 diff --git a/summary.py b/summary.py index 07a2915..777e9c8 100644 --- a/summary.py +++ b/summary.py @@ -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")) @@ -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 diff --git a/tests/OUTPUT/test.summary.log b/tests/OUTPUT/test.summary.log index 5b96747..5653a97 100644 --- a/tests/OUTPUT/test.summary.log +++ b/tests/OUTPUT/test.summary.log @@ -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" , diff --git a/tests/OUTPUT/test.summary.logday b/tests/OUTPUT/test.summary.logday index a504449..f942b6c 100644 --- a/tests/OUTPUT/test.summary.logday +++ b/tests/OUTPUT/test.summary.logday @@ -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" ,