Skip to content

Commit

Permalink
added current average of last 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Jul 23, 2023
1 parent b914e8c commit af4ec01
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 20 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v1.0.x
* Added: Bluetooth: Show signal strength of BMS in log by @mr-manuel
* Added: Create unique identifier, if not provided from BMS by @mr-manuel
* Added: Current average of the last 5 minutes by @mr-manuel
* Added: Daly BMS: Auto reset SoC when changing to float (can be turned off in the config file) by @transistorgit
* Added: Exclude a device from beeing used by the dbus-serialbattery driver by @mr-manuel
* Added: Implement callback function for update by @seidler2547
Expand All @@ -12,7 +13,6 @@
* Added: Temperature names to dbus and mqtt by @mr-manuel
* Added: Use current average of the last 300 cycles for time to go and time to SoC calculation by @mr-manuel
* Added: Validate current, voltage, capacity and SoC for all BMS. This prevents that a device, which is no BMS, is detected as BMS. Fixes also https://github.com/Louisvdw/dbus-serialbattery/issues/479 by @mr-manuel
* Changed: Calculate only positive Time-to-SoC points by @mr-manuel
* Changed: Enable BMS that are disabled by default by specifying it in the config file. No more need to edit scripts by @mr-manuel
* Changed: Fix daly readsentence by @transistorgit
* Changed: Fix Sinowealth not loading https://github.com/Louisvdw/dbus-serialbattery/issues/702 by @mr-manuel
Expand All @@ -25,6 +25,8 @@
* Changed: Improved driver reinstall when multiple Bluetooth BMS are enabled by @mr-manuel
* Changed: Improved Jkbms_Ble driver by @seidler2547 & @mr-manuel
* Changed: Reduce the big inrush current if the CVL jumps from Bulk/Absorbtion to Float https://github.com/Louisvdw/dbus-serialbattery/issues/659 by @Rikkert-RS & @ogurevich
* Changed: Time-to-Go and Time-to-SoC use the current average of the last 5 minutes for calculation by @mr-manuel
* Changed: Time-to-SoC calculate only positive points by @mr-manuel
* Removed: Cronjob to restart Bluetooth service every 12 hours by @mr-manuel


Expand Down
8 changes: 5 additions & 3 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ def prepare_voltage_management(self) -> None:
or utils.BULK_AFTER_DAYS < bulk_last_reached_days_ago
)
):
"""
logger.info(
f"set bulk_requested to True: first time (0) or {utils.BULK_AFTER_DAYS}"
+ f" < {round(bulk_last_reached_days_ago, 2)}"
)
"""
self.bulk_requested = True

self.bulk_battery_voltage = round(utils.BULK_CELL_VOLTAGE * self.cell_count, 2)
Expand Down Expand Up @@ -396,7 +398,7 @@ def manage_charge_voltage_linear(self) -> None:
chargeMode = "Float"
# reset bulk when going into float
if self.bulk_requested:
logger.info("set bulk_requested to False")
# logger.info("set bulk_requested to False")
self.bulk_requested = False
# IDEA: Save "bulk_last_reached" in the dbus path com.victronenergy.settings
# to make it restart persistent
Expand Down Expand Up @@ -436,7 +438,7 @@ def manage_charge_voltage_linear(self) -> None:
self.charge_mode += " (Linear Mode)"

# uncomment for enabling debugging infos in GUI
# """
"""
self.charge_mode_debug = (
f"max_battery_voltage: {round(self.max_battery_voltage, 2)}V"
)
Expand Down Expand Up @@ -550,7 +552,7 @@ def manage_charge_voltage_step(self) -> None:
self.charge_mode = "Float"
# reset bulk when going into float
if self.bulk_requested:
logger.info("set bulk_requested to False")
# logger.info("set bulk_requested to False")
self.bulk_requested = False
self.bulk_last_reached = current_time

Expand Down
61 changes: 46 additions & 15 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ def setup_vedbus(self):
# Create TimeToGo item
if utils.TIME_TO_GO_ENABLE:
self._dbusservice.add_path("/TimeToGo", None, writeable=True)
self._dbusservice.add_path(
"/CurrentAvg",
None,
writeable=True,
gettextcallback=lambda p, v: "{:0.2f}A".format(v),
)

# Create TimeToSoc items
if len(utils.TIME_TO_SOC_POINTS) > 0:
Expand Down Expand Up @@ -592,6 +598,20 @@ def publish_dbus(self):
if len(self.battery.current_avg_lst) > 300:
del self.battery.current_avg_lst[0]

"""
logger.info(
str(self.battery.capacity)
+ " - "
+ str(utils.TIME_TO_GO_ENABLE)
+ " - "
+ str(len(utils.TIME_TO_SOC_POINTS))
+ " - "
+ str(int(time()) - self.battery.time_to_soc_update)
+ " - "
+ str(utils.TIME_TO_SOC_RECALCULATE_EVERY)
)
"""

if (
self.battery.capacity is not None
and (utils.TIME_TO_GO_ENABLE or len(utils.TIME_TO_SOC_POINTS) > 0)
Expand All @@ -608,30 +628,35 @@ def publish_dbus(self):
2,
)

self._dbusservice["/CurrentAvg"] = self.battery.current_avg

crntPrctPerSec = (
abs(self.battery.current_avg / (self.battery.capacity / 100)) / 3600
)

# Update TimeToGo item
if utils.TIME_TO_GO_ENABLE:
# Update TimeToGo item, has to be a positive int since it's used from dbus-systemcalc-py
self._dbusservice["/TimeToGo"] = (
abs(
int(
self.battery.get_timeToSoc(
# switch value depending on charging/discharging
utils.SOC_LOW_WARNING
if self.battery.current_avg < 0
else 100,
crntPrctPerSec,
True,
if self.battery.current_avg is not None:
# Update TimeToGo item, has to be a positive int since it's used from dbus-systemcalc-py
self._dbusservice["/TimeToGo"] = (
abs(
int(
self.battery.get_timeToSoc(
# switch value depending on charging/discharging
utils.SOC_LOW_WARNING
if self.battery.current_avg < 0
else 100,
crntPrctPerSec,
True,
)
)
)
if self.battery.current_avg
and abs(self.battery.current_avg) > 0.1
else None
)
if self.battery.current_avg
and abs(self.battery.current_avg) > 0.1
else None
)
else:
self._dbusservice["/TimeToGo"] = None

# Update TimeToSoc items
if len(utils.TIME_TO_SOC_POINTS) > 0:
Expand All @@ -643,6 +668,12 @@ def publish_dbus(self):
)

except Exception:
exception_type, exception_object, exception_traceback = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
pass

if self.battery.soc is not None:
Expand Down
6 changes: 6 additions & 0 deletions etc/dbus-serialbattery/qml/PageBattery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ MbPage {
]
}

MbItemValue {
description: qsTr("Current (last 5 minutes avg.)")
item.bind: service.path("/CurrentAvg")
show: item.seen
}

MbItemValue {
id: soc

Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _get_list_from_config(


# Constants - Need to dynamically get them in future
DRIVER_VERSION = "1.0.20230717dev"
DRIVER_VERSION = "1.0.20230723dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit af4ec01

Please sign in to comment.