From b03feb379485a3c5f363f8ed808137dc2b3185dc Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Tue, 6 Jun 2023 07:50:08 +0100 Subject: [PATCH] Fix bugs in REST mode - If 'charge_limit' was commented out in REST mode there would be a crash - battery_scaling not working correctly in REST mode --- apps/predbat/predbat.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 4b7a98b6..15fef856 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -88,11 +88,12 @@ def update_status(self, minutes_now): self.soc_kw = self.base.sim_soc_kw else: if self.rest_data: - self.soc_kw = self.rest_data['Power']['Power']['SOC_kWh'] - self.base.log("Inverter {} SOC_Kwh {}".format(self.id, self.soc_kw)) + self.soc_kw = self.rest_data['Power']['Power']['SOC_kWh'] * self.base.battery_scaling else: self.soc_kw = self.base.get_arg('soc_kw', default=0.0, index=self.id) * self.base.battery_scaling + self.base.log("Inverter {} SOC_Kwh {}".format(self.id, self.soc_kw)) + # If the battery is being charged then find the charge window if self.charge_enable_time: # Find current charge window @@ -210,20 +211,20 @@ def adjust_battery_target(self, soc): if current_soc != soc: self.base.log("Inverter {} Current charge Limit is {} % and new target is {} %".format(self.id, current_soc, soc)) - entity_soc = self.base.get_entity(self.base.get_arg('charge_limit', indirect=False, index=self.id)) - if entity_soc: - if SIMULATE: - self.base.sim_soc = soc + if SIMULATE: + self.base.sim_soc = soc + else: + if self.rest_api: + self.rest_setChargeTarget(soc) else: - if self.rest_api: - self.rest_setChargeTarget(soc) - else: + entity_soc = self.base.get_entity(self.base.get_arg('charge_limit', indirect=False, index=self.id)) + if entity_soc: entity_soc.call_service("set_value", value=soc) - if self.base.get_arg('set_soc_notify', False): - self.base.call_notify('Predbat: Inverter {} Target SOC has been changed to {} % at {}'.format(self.id, soc, self.base.time_now_str())) - self.base.record_status("Inverter {} set soc to {} at {}".format(self.id, soc, self.base.time_now_str())) - else: - self.base.log("WARN: Inverter {} Unable to get entity to set SOC target".format(self.id)) + else: + self.base.log("WARN: Inverter {} Unable to get entity to set SOC target".format(self.id)) + if self.base.get_arg('set_soc_notify', False): + self.base.call_notify('Predbat: Inverter {} Target SOC has been changed to {} % at {}'.format(self.id, soc, self.base.time_now_str())) + self.base.record_status("Inverter {} set soc to {} at {}".format(self.id, soc, self.base.time_now_str())) else: self.base.log("Inverter {} Current SOC is {} already at target".format(self.id, current_soc))