From d5a727d884cf5ca1964d1fde8dc23af8f6b7a186 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:25:01 +0000 Subject: [PATCH 1/8] Auto join saving sessions, remove previous assumed rate sensor --- apps/predbat/predbat.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 4d08b603..223d55c6 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -16,7 +16,7 @@ import appdaemon.plugins.hass.hassapi as hass import adbase as ad -THIS_VERSION = "v7.13.23" +THIS_VERSION = "v7.13.24" 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" @@ -297,17 +297,6 @@ "enable": "expert_mode", "default": 0.95, }, - { - "name": "metric_octopus_saving_rate", - "friendly_name": "Octopus Saving session assumed rate", - "type": "input_number", - "min": 1, - "max": 500, - "step": 2, - "unit": "fraction", - "icon": "mdi:currency-usd", - "default": 0.0, - }, {"name": "set_reserve_min", "friendly_name": "Set Reserve Min", "type": "input_number", "min": 4, "max": 100, "step": 1, "unit": "%", "icon": "mdi:percent", "default": 4.0}, { "name": "rate_low_threshold", @@ -4696,7 +4685,7 @@ def load_saving_slot(self, octopus_saving_slots, export=False): if start_minutes >= 0 and end_minutes != start_minutes and start_minutes < self.forecast_minutes: self.log( - "Setting Octopus saving session in range {} - {} export {} assumed rate {}".format( + "Setting Octopus saving session in range {} - {} export {} rate {}".format( self.time_abs_str(start_minutes), self.time_abs_str(end_minutes), export, rate ) ) @@ -8549,20 +8538,34 @@ def fetch_sensor_data(self): # Octopus saving session octopus_saving_slots = [] if "octopus_saving_session" in self.args: + saving_rate = 200 # Default rate if not reported + octopoints_per_pound = self.get_arg('octopus_saving_session_octopoints_per_pound', 8) # Default 8 octopoints per found + entity_id = self.get_arg("octopus_saving_session", indirect=False) if entity_id: - saving_rate = self.get_arg("metric_octopus_saving_rate") state = self.get_arg("octopus_saving_session", False) joined_events = self.get_state(entity_id=entity_id, attribute="joined_events") if not joined_events: entity_event = entity_id.replace("binary_sensor.", "event.").replace("_sessions", "_session_events") joined_events = self.get_state(entity_id=entity_event, attribute="joined_events") + + available_events = self.get_state(entity_id=entity_id, attribute="available_events") + if available_events: + for event in available_events: + code = event.get("code", None) + start = event.get("start", None) + end = event.get("end", None) + saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_pound) / octopoints_per_pound # Octopoints per pence + if code: + self.log("Joining Octopus saving event code {} start {} end {} price per kWh {}".format(code, start, end, saving_rate)) + self.call_service("octopus_energy.join_octoplus_saving_session_event", event_code=code, target=entity_id) + if joined_events: for event in joined_events: start = event.get("start", None) end = event.get("end", None) - saving_rate = event.get("octopoints_per_kwh", saving_rate * 8) / 8 # 8 Octopoints per pence + saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_pound) / octopoints_per_pound # Octopoints per pence if start and end and saving_rate > 0: octopus_saving_slot = {} octopus_saving_slot["start"] = start From df2331f1de8d6a1fb6418cd48a820e8f43b55bba Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:26:28 +0000 Subject: [PATCH 2/8] Update apps.yaml - added octopoints_per_pound --- apps/predbat/config/apps.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/predbat/config/apps.yaml b/apps/predbat/config/apps.yaml index f02a6f96..9e05d567 100644 --- a/apps/predbat/config/apps.yaml +++ b/apps/predbat/config/apps.yaml @@ -245,8 +245,9 @@ pred_bat: octopus_charge_limit: 're:(number.octopus_energy([0-9a-z_]+|)_intelligent_charge_limit)' # Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed - # rate configured with input_number.predbat_metric_octopus_saving_rate in-side HA + # Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8) octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' + octopus_saving_session_octopoints_per_pound: 8 # Energy rates # Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latest basic metric From 8f5d6f4e7a411884dc86ce44eb698edee5e56fbe Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:30:44 +0000 Subject: [PATCH 3/8] Update config-yml-settings.md --- docs/config-yml-settings.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/config-yml-settings.md b/docs/config-yml-settings.md index be81d2a8..ff4fc7cb 100644 --- a/docs/config-yml-settings.md +++ b/docs/config-yml-settings.md @@ -133,8 +133,18 @@ They are set to a regular expression and auto-discovered but you can comment out event.octopus_energy_electricity_xxxxxxxx_export_next_day_rates ``` -- **octopus_intelligent_slot** - If you have Intelligent Octopus and the Octopus Energy plugin installed point to the 'slot' sensor -- **octopus_saving_session** - Points to the sensor in the Octopus Energy plugin that publishes saving sessions (binary_sensor.octopus_energy_XXXXX_saving_sessions +- **octopus_intelligent_slot** - If you have Octopus Intelligent GO and the Octopus Energy plugin installed point to the 'slot' sensor. + +This is used to find Intelligent Go slots and thus predict when your car will charge and report the additional low rate slots outside +the normal low rate hours + +- **octopus_saving_session** - Points to the sensor in the Octopus Energy plugin that publishes saving sessions (binary_sensor.octopus_energy_XXXXX_saving_sessions). + +This is used to automatically join saving sessions and to determine the rate of the saving session. It's assumed the saving amount will +be added to your import and export rates. This calculation assumes you normally consume zero during a saving session as you are a home +battery user. + +- **octopus_saving_session_octopoints_per_penny** - Sets the Octopoints per pence (currently 8) - **switch.predbat_octopus_intelligent_charging** - When enabled Predbat will plan charging around the Intelligent Octopus slots, taking it into account for battery load and generating the slot information From 0a2954aa5f461cd1853a11a6c9bed0a6cdc6e378 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:31:47 +0000 Subject: [PATCH 4/8] Points are per penny not per pound --- apps/predbat/predbat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 223d55c6..bb836304 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -8539,7 +8539,7 @@ def fetch_sensor_data(self): octopus_saving_slots = [] if "octopus_saving_session" in self.args: saving_rate = 200 # Default rate if not reported - octopoints_per_pound = self.get_arg('octopus_saving_session_octopoints_per_pound', 8) # Default 8 octopoints per found + octopoints_per_penny = self.get_arg('octopus_saving_session_octopoints_per_penny', 8) # Default 8 octopoints per found entity_id = self.get_arg("octopus_saving_session", indirect=False) if entity_id: @@ -8556,7 +8556,7 @@ def fetch_sensor_data(self): code = event.get("code", None) start = event.get("start", None) end = event.get("end", None) - saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_pound) / octopoints_per_pound # Octopoints per pence + saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_penny) / octopoints_per_penny # Octopoints per pence if code: self.log("Joining Octopus saving event code {} start {} end {} price per kWh {}".format(code, start, end, saving_rate)) self.call_service("octopus_energy.join_octoplus_saving_session_event", event_code=code, target=entity_id) @@ -8565,7 +8565,7 @@ def fetch_sensor_data(self): for event in joined_events: start = event.get("start", None) end = event.get("end", None) - saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_pound) / octopoints_per_pound # Octopoints per pence + saving_rate = event.get("octopoints_per_kwh", saving_rate * octopoints_per_penny) / octopoints_per_penny # Octopoints per pence if start and end and saving_rate > 0: octopus_saving_slot = {} octopus_saving_slot["start"] = start From d25757d85b869cfb53405918893e2486c76fa4ba Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:35:21 +0000 Subject: [PATCH 5/8] Update energy-rates.md --- docs/energy-rates.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/energy-rates.md b/docs/energy-rates.md index ef760a4b..19af6679 100644 --- a/docs/energy-rates.md +++ b/docs/energy-rates.md @@ -14,9 +14,15 @@ For Predbat to automatically manage saving sessions you will need to make sure t in apps.yaml to point to the saving session binary sensor supported by the Octopus Energy plugin (see template apps.yaml for the default name) -When a saving session is active the energy rates for import and export will be overridden with the assumed rate will be taken -from the Octopus Energy add-in (v9.1.0 and above) or if not reported it can be set in Home Assistant with -**input_number.predbat_metric_octopus_saving_rate** (default is 0 so must be set if used). +When a saving session is available it will be automatically joined by Predbat and then should appear as a joined session +within the next 30 minutes. + +When a saving session has been joined the energy rates for import and export will be overridden by adding the assumed saving rate +to your normal rate. The assumed rate will be taken from the Octopus Energy add-in (v9.1.0 and above) and converted into pence +using the **octopus_saving_session_octopoints_per_penny** configuration item in apps.yaml (default is 8). + +As the saving session import and export rates are very high compared to normal you would expect Predbat to export during the entire +period if the battery is large amount, a pre-charge may happen at some point during the day to maintain the right level for the session. If you are using expert mode, for best results: **switch.predbat_combine_charge_slots** (_expert mode_) is turned off. Set **input_number.rate_low_threshold** (_expert mode_) and **input_number.rate_high_threshold** (_expert mode_) to 0 for automatic mode. From b17aa282f8de1f23cb991905cf8c0bca7a775734 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:39:13 +0000 Subject: [PATCH 6/8] [pre-commit.ci lite] apply automatic fixes --- apps/predbat/predbat.py | 10 +++------- docs/config-yml-settings.md | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index bb836304..f6b65aac 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -4684,11 +4684,7 @@ def load_saving_slot(self, octopus_saving_slots, export=False): end_minutes = min(self.minutes_to_time(end, self.midnight_utc), self.forecast_minutes) if start_minutes >= 0 and end_minutes != start_minutes and start_minutes < self.forecast_minutes: - self.log( - "Setting Octopus saving session in range {} - {} export {} rate {}".format( - self.time_abs_str(start_minutes), self.time_abs_str(end_minutes), export, rate - ) - ) + self.log("Setting Octopus saving session in range {} - {} export {} rate {}".format(self.time_abs_str(start_minutes), self.time_abs_str(end_minutes), export, rate)) for minute in range(start_minutes, end_minutes): if export: self.rate_export[minute] += rate @@ -8538,8 +8534,8 @@ def fetch_sensor_data(self): # Octopus saving session octopus_saving_slots = [] if "octopus_saving_session" in self.args: - saving_rate = 200 # Default rate if not reported - octopoints_per_penny = self.get_arg('octopus_saving_session_octopoints_per_penny', 8) # Default 8 octopoints per found + saving_rate = 200 # Default rate if not reported + octopoints_per_penny = self.get_arg("octopus_saving_session_octopoints_per_penny", 8) # Default 8 octopoints per found entity_id = self.get_arg("octopus_saving_session", indirect=False) if entity_id: diff --git a/docs/config-yml-settings.md b/docs/config-yml-settings.md index ff4fc7cb..95ae7ab7 100644 --- a/docs/config-yml-settings.md +++ b/docs/config-yml-settings.md @@ -135,13 +135,13 @@ They are set to a regular expression and auto-discovered but you can comment out - **octopus_intelligent_slot** - If you have Octopus Intelligent GO and the Octopus Energy plugin installed point to the 'slot' sensor. -This is used to find Intelligent Go slots and thus predict when your car will charge and report the additional low rate slots outside +This is used to find Intelligent Go slots and thus predict when your car will charge and report the additional low rate slots outside the normal low rate hours - **octopus_saving_session** - Points to the sensor in the Octopus Energy plugin that publishes saving sessions (binary_sensor.octopus_energy_XXXXX_saving_sessions). This is used to automatically join saving sessions and to determine the rate of the saving session. It's assumed the saving amount will -be added to your import and export rates. This calculation assumes you normally consume zero during a saving session as you are a home +be added to your import and export rates. This calculation assumes you normally consume zero during a saving session as you are a home battery user. - **octopus_saving_session_octopoints_per_penny** - Sets the Octopoints per pence (currently 8) From 039a8a340c022d80e1847490499fe1b4d2c82020 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:41:47 +0000 Subject: [PATCH 7/8] Update apps.yaml --- apps/predbat/config/apps.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/predbat/config/apps.yaml b/apps/predbat/config/apps.yaml index 9e05d567..5f801e43 100644 --- a/apps/predbat/config/apps.yaml +++ b/apps/predbat/config/apps.yaml @@ -247,7 +247,7 @@ pred_bat: # Octopus saving session points to the saving session Sensor in the Octopus plugin, when enabled saving sessions will be at the assumed # Rate is read automatically from the add-in and converted to pence using the conversion rate below (default is 8) octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' - octopus_saving_session_octopoints_per_pound: 8 + octopus_saving_session_octopoints_per_penny: 8 # Energy rates # Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latest basic metric From 58dbe5b45affe03795c05c70f1c15802e6dc41e8 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:42:42 +0000 Subject: [PATCH 8/8] Update custom-dictionary-workspace.txt --- .cspell/custom-dictionary-workspace.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index c5960dee..8ca93883 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -70,6 +70,7 @@ nattribute nearr nord Nordpool +octoplus octopoints Ohme oncharge