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

Added new calculate_fast_plan feature #450

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import appdaemon.plugins.hass.hassapi as hass
import adbase as ad

THIS_VERSION = "v7.14.7"
THIS_VERSION = "v7.14.8"
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
TIME_FORMAT_OCTOPUS = "%Y-%m-%d %H:%M:%S%z"
Expand Down Expand Up @@ -343,8 +343,9 @@
{"name": "car_charging_plan_smart", "friendly_name": "Car Charging Plan Smart", "type": "switch", "default": False},
{"name": "car_charging_from_battery", "friendly_name": "Allow car to charge from battery", "type": "switch", "default": False},
{"name": "calculate_discharge_oncharge", "friendly_name": "Calculate Discharge on charge slots", "type": "switch", "enable": "expert_mode", "default": True},
{"name": "calculate_fast_plan", "friendly_name": "Calculate plan faster (less accurate)", "type": "switch", "enable": "expert_mode", "default": True},
{"name": "calculate_second_pass", "friendly_name": "Calculate full second pass (slower)", "type": "switch", "enable": "expert_mode", "default": False},
{"name": "calculate_tweak_plan", "friendly_name": "Calculate tweak second pass (faster)", "type": "switch", "enable": "expert_mode", "default": False},
{"name": "calculate_tweak_plan", "friendly_name": "Calculate tweak second pass", "type": "switch", "enable": "expert_mode", "default": False},
{"name": "calculate_inday_adjustment", "friendly_name": "Calculate in-day adjustment", "type": "switch", "enable": "expert_mode", "default": True},
{
"name": "calculate_plan_every",
Expand Down Expand Up @@ -5469,6 +5470,7 @@ def publish_html_plan(self, pv_forecast_minute_step, load_minutes_step, end_reco
if self.set_charge_freeze and (limit == self.reserve):
state = "FreezeChrg→"
state_color = "#EEEEEE"
limit_percent = soc_percent
elif limit_percent == soc_percent_min:
state = "HoldChrg→"
state_color = "#34dbeb"
Expand Down Expand Up @@ -5568,7 +5570,10 @@ def publish_html_plan(self, pv_forecast_minute_step, load_minutes_step, end_reco
html += "<td rowspan=" + str(rowspan) + " bgcolor=" + state_color + ">" + state + "</td>"
elif not in_span:
html += "<td bgcolor=" + state_color + ">" + state + "</td>"
html += "<td bgcolor=#FFFFFF> " + show_limit + "</td>"
if start_span:
html += "<td rowspan=" + str(rowspan) + " bgcolor=#FFFFFF> " + show_limit + "</td>"
elif not in_span:
html += "<td bgcolor=#FFFFFF> " + show_limit + "</td>"
html += "<td bgcolor=" + pv_color + ">" + str(pv_forecast) + pv_symbol + "</td>"
html += "<td bgcolor=" + load_color + ">" + str(load_forecast) + "</td>"
if self.num_cars > 0: # Don't display car charging data if there's no car
Expand Down Expand Up @@ -8891,8 +8896,13 @@ def fetch_config_options(self):
self.debug_enable = self.get_arg("debug_enable")
self.previous_status = self.get_state(self.prefix + ".status")
forecast_hours = self.get_arg("forecast_hours", 48)
self.calculate_fast_plan = self.get_arg("calculate_fast_plan")

if self.calculate_fast_plan:
self.calculate_max_windows = max(int(forecast_hours * 2), 24)
else:
self.calculate_max_windows = max(int(forecast_hours), 12)

self.calculate_max_windows = max(int(forecast_hours), 24)
self.num_cars = self.get_arg("num_cars", 1)
self.inverter_type = self.get_arg("inverter_type", "GE", indirect=False)
self.calculate_plan_every = max(self.get_arg("calculate_plan_every"), 5)
Expand Down
10 changes: 9 additions & 1 deletion docs/customisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ especially on more complex tariffs like Agile when run on lower power machines s
You can tweak **input_number.predbat_calculate_plan_every** (_expert mode_) to reduce the frequency of replanning while
keeping the inverter control in the 5 minute slots. E.g. a value of 10 or 15 minutes should also give good results.

If you have performance problems leave **switch.predbat_calculate_second_pass** (_expert mode_) turned off as it's
If you have performance problems leave **switch.predbat_calculate_second_pass** (_expert mode_) turned Off as it's
quite CPU intensive and provides very little improvement for most systems.

If you have performance problems leave **switch.predbat_calculate_fast_plan** (_expert mode_) turned On to help
reduce your CPU load.

## Battery loss options

**input_number.battery_loss** accounts for energy lost charging the battery, default 0.05 is 5%
Expand Down Expand Up @@ -151,6 +154,11 @@ if **car_charging_planned** is set correctly in apps.yaml to detect your car bei

See the Predbat mode setting as above for basic calculation options

**switch.predbat_calculate_fast_plan** (_expert mode_) When True (default) the plan is calculated with a limited number of
windows to make calculations faster. When False all windows are considered but planning will take a little longer but be
more accurate. The end result is unlikely to change in fast mode as the next windows are always considered but the longer
term plan will be last accurate.

**switch.predbat_calculate_discharge_oncharge** (_expert mode_) When True calculated discharge slots will
disable or move charge slots, allowing them to intermix. When False discharge slots will never be placed into charge slots.

Expand Down
3 changes: 2 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ The Integration that communicates with your inverter will be depend on the brand
## AppDaemon install

- Install the AppDaemon add-on [https://github.com/hassio-addons/addon-appdaemon](https://github.com/hassio-addons/addon-appdaemon)
- You will find the appdaemon.yaml file in addon_configs/a0d7b954_appdaemon
- You will find the appdaemon.yaml file in addon_configs/a0d7b954_appdaemon ![image](https://github.com/springfall2008/batpred/assets/48591903/bf8bf9cf-75b1-4a8d-a1c5-fbb7b3b17521)
- If using the File Editor remember to turn off **enforce base path** to allow access: ![image](https://github.com/springfall2008/batpred/assets/48591903/298c7a19-3be9-43d6-9f1b-b46467701ca7)
- Add to the appdaemon: section **apps_dir** which should point to /homeassistant/appdaemon/apps
- Set the **time_zone** correctly in appdaemon.yaml (e.g. Europe/London)
- Add **thread_duration_warning_threshold: 120** to the appdaemon.yaml file in the appdaemon section
Expand Down
4 changes: 2 additions & 2 deletions templates/appdaemon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ admin:
api:
hadashboard:
logs:
main_log:
main_log:
filename: /homeassistant/appdaemon/appdaemon.log
log_size: 10000000
log_size: 10000000