diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 41da82a4..1302e431 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms -custom: ['https://paypal.me/predbat?country.x=GB&locale.x=en_GB'] +custom: ['https://paypal.me/predbat?country.x=GB&locale.x=en_GB'] diff --git a/apps/predbat/config/apps.yaml b/apps/predbat/config/apps.yaml index dd31159e..483c71a2 100644 --- a/apps/predbat/config/apps.yaml +++ b/apps/predbat/config/apps.yaml @@ -317,6 +317,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index e6ba9863..ea56c2ef 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -32,7 +32,7 @@ import asyncio import json -THIS_VERSION = "v8.7.0" +THIS_VERSION = "v8.7.1" PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "predheat.py", "futurerate.py"] from download import predbat_update_move, predbat_update_download, check_install @@ -3270,6 +3270,40 @@ def add_now_to_octopus_slot(self, octopus_slots, now_utc): self.log("Car is charging now - added new IO slot {}".format(slot)) return octopus_slots + def load_free_slot(self, octopus_free_slots, export=False, rate_replicate={}): + """ + Load octopus free session slot + """ + start_minutes = 0 + end_minutes = 0 + + for octopus_free_slot in octopus_free_slots: + start = octopus_free_slot["start"] + end = octopus_free_slot["end"] + rate = octopus_free_slot["rate"] + + if start and end: + try: + start = self.str2time(start) + end = self.str2time(end) + except (ValueError, TypeError): + start = None + end = None + self.log("Warn: Unable to decode Octopus free session start/end time") + if start and end: + start_minutes = self.minutes_to_time(start, self.midnight_utc) + 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 free 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 + else: + self.rate_import[minute] = rate + self.load_scaling_dynamic[minute] = self.load_scaling_free + rate_replicate[minute] = "saving" + def load_saving_slot(self, octopus_saving_slots, export=False, rate_replicate={}): """ Load octopus saving session slot @@ -9173,6 +9207,29 @@ def fetch_sensor_data(self): # Basic rates defined by user over time self.rate_export = self.basic_rates(self.get_arg("rates_export", [], indirect=False), "rates_export") + # Octopus free session + octopus_free_slots = [] + if "octopus_free_session" in self.args: + entity_id = self.get_arg("octopus_free_session", indirect=False) + if entity_id: + events = self.get_state_wrapper(entity_id=entity_id, attribute="events") + if events: + for event in events: + start = event.get("start", None) + end = event.get("end", None) + code = event.get("code", None) + if start and end and code: + start_time = self.str2time(start) # reformat the saving session start & end time for improved readability + end_time = self.str2time(end) + diff_time = start_time - self.now_utc + if abs(diff_time.days) <= 3: + self.log("Octopus free events code {} {}-{}".format(code, start_time.strftime("%a %d/%m %H:%M"), end_time.strftime("%H:%M"))) + octopus_free_slot = {} + octopus_free_slot["start"] = start + octopus_free_slot["end"] = end + octopus_free_slot["rate"] = 0 + octopus_free_slots.append(octopus_free_slot) + # Octopus saving session octopus_saving_slots = [] if "octopus_saving_session" in self.args: @@ -9251,6 +9308,7 @@ def fetch_sensor_data(self): self.rate_import, self.rate_import_replicated = self.rate_replicate(self.rate_import, self.io_adjusted, is_import=True) self.rate_import = self.rate_add_io_slots(self.rate_import, self.octopus_slots) self.load_saving_slot(octopus_saving_slots, export=False, rate_replicate=self.rate_import_replicated) + self.load_free_slot(octopus_free_slots, export=False, rate_replicate=self.rate_import_replicated) self.rate_import = self.basic_rates(self.get_arg("rates_import_override", [], indirect=False), "rates_import_override", self.rate_import, self.rate_import_replicated) self.rate_import = self.rate_scan(self.rate_import, print=True) else: @@ -9763,6 +9821,7 @@ def fetch_config_options(self): self.load_scaling = self.get_arg("load_scaling") self.load_scaling10 = self.get_arg("load_scaling10") self.load_scaling_saving = self.get_arg("load_scaling_saving") + self.load_scaling_free = self.get_arg("load_scaling_free") self.battery_rate_max_scaling = self.get_arg("battery_rate_max_scaling") self.battery_rate_max_scaling_discharge = self.get_arg("battery_rate_max_scaling_discharge") diff --git a/docs/energy-rates.md b/docs/energy-rates.md index 49fe658f..5a632f97 100644 --- a/docs/energy-rates.md +++ b/docs/energy-rates.md @@ -119,6 +119,30 @@ If you do not have an export tariff then forced export will not apply and Predba If you do not want Predbat to automatically join Octopus saving sessions and manage your battery activity for the session, simply delete or comment out the **octopus_saving_session** entry in apps.yaml. +## Octopus free (power up) events + +Predbat can automatically detect Octopus free events and adjust your battery plan according. + +For Predbat to automatically manage Octopus free sessions the following additional configuration item in apps.yaml is used. + +Note: **You must have signed up to Octoplus to benefit from these events** + +Like the electricity rates this is set in the apps.yaml template to a regular expression that should auto-discover the Octopus Energy integration. + +**octopus_free_session** - Will point to the free event sensor that is exposed by the Octopus Energy Integration. This event sensor contains the dates/times of +all the free events. + +```yaml + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' +``` + +Note: **This event may need to be enabled in Home Assistant first [How to Enable Octopus events](https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/faq/#there-are-entities-that-are-disabled-why-are-they-disabled-and-how-do-i-enable-them)** + +If you normally increase your house usage during a free session then you can change **input_number.predbat_load_scaling_free** to allow Predbat to assume an energy +increase in this period. E.g. setting to a value of 1.2 would indicate you will use 20% more energy that normal during this period. (Default is 1.2) + +If you do not want Predbat to see these sessions then comment out the **octopus_free_session** setting. + ## Octopus Rates URL If you do not wish to use the Octopus Energy integration and are an Octopus Energy customer then you can configure Predbat to get the electricity rates diff --git a/templates/fox.yaml b/templates/fox.yaml index 78db8c1c..908e1852 100644 --- a/templates/fox.yaml +++ b/templates/fox.yaml @@ -259,6 +259,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/ginlong_solis.yaml b/templates/ginlong_solis.yaml index 906226f6..8c4b0b41 100644 --- a/templates/ginlong_solis.yaml +++ b/templates/ginlong_solis.yaml @@ -224,6 +224,26 @@ pred_bat: octopus_ready_time: 're:(time.octopus_energy_([0-9a-z_]+|)_intelligent_target_time)' octopus_charge_limit: 're:(number.octopus_energy([0-9a-z_]+|)_intelligent_charge_target)' + # Carbon Intensity data from National grid + carbon_intensity: 're:(sensor.carbon_intensity_uk)' + + # Example alternative configuration for Ohme integration release >=v0.6.1 + #octopus_intelligent_slot: 'binary_sensor.ohme_slot_active' + #octopus_ready_time: 'time.ohme_target_time' + #octopus_charge_limit: 'number.ohme_target_percent' + + # Set this to False if you use Octopus Intelligent slot for car planning but when on another tariff e.g. Agile + #octopus_slot_low_rate: False + + # 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_penny: 8 + + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/givenergy_cloud.yaml b/templates/givenergy_cloud.yaml index 95f995fe..f1a94689 100644 --- a/templates/givenergy_cloud.yaml +++ b/templates/givenergy_cloud.yaml @@ -286,6 +286,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/givenergy_ems.yaml b/templates/givenergy_ems.yaml index 38f4ffd9..460b3b87 100644 --- a/templates/givenergy_ems.yaml +++ b/templates/givenergy_ems.yaml @@ -283,6 +283,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/givenergy_givtcp.yaml b/templates/givenergy_givtcp.yaml index 86c6335e..5ce3f9c3 100644 --- a/templates/givenergy_givtcp.yaml +++ b/templates/givenergy_givtcp.yaml @@ -323,6 +323,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/huawei.yaml b/templates/huawei.yaml index 58be39c8..4c538cb3 100644 --- a/templates/huawei.yaml +++ b/templates/huawei.yaml @@ -228,18 +228,29 @@ pred_bat: # Will automatically disable if not found, or comment out to disable fully # When enabled it overrides the 'car_charging_planned' feature and predict the car charging based on the intelligent plan (unless octopus intelligent charging is False) # This matches either the intelligent slot from the Octopus Plugin or from the Intelligent plugin - - octopus_intelligent_slot: 're:(binary_sensor.octopus_intelligent_slot|re:binary_sensor.octopus_energy_intelligent_dispatching)' + octopus_intelligent_slot: 're:(binary_sensor.octopus_energy_([0-9a-z_]+|)_intelligent_dispatching)' octopus_ready_time: 're:(time.octopus_energy_([0-9a-z_]+|)_intelligent_target_time)' - octopus_charge_limit: 're:(number.octopus_energy([0-9a-z_]+|)_intelligent_charge_target)' + octopus_charge_limit: 're:(number.octopus_energy_([0-9a-z_]+|)_intelligent_charge_target)' + + # Carbon Intensity data from National grid + carbon_intensity: 're:(sensor.carbon_intensity_uk)' # Example alternative configuration for Ohme integration release >=v0.6.1 #octopus_intelligent_slot: 'binary_sensor.ohme_slot_active' #octopus_ready_time: 'time.ohme_target_time' #octopus_charge_limit: 'number.ohme_target_percent' - # Carbon Intensity data from National grid - carbon_intensity: 're:(sensor.carbon_intensity_uk)' + # Set this to False if you use Octopus Intelligent slot for car planning but when on another tariff e.g. Agile + #octopus_slot_low_rate: False + + # 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_penny: 8 + + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' # 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 diff --git a/templates/luxpower.yaml b/templates/luxpower.yaml index 4f8b34b3..abb4a334 100644 --- a/templates/luxpower.yaml +++ b/templates/luxpower.yaml @@ -324,6 +324,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/sofar.yaml b/templates/sofar.yaml index 490bbab9..212f1aa2 100644 --- a/templates/sofar.yaml +++ b/templates/sofar.yaml @@ -230,6 +230,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/solaredge.yaml b/templates/solaredge.yaml index 48f5b5f9..3b134aa6 100644 --- a/templates/solaredge.yaml +++ b/templates/solaredge.yaml @@ -229,6 +229,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/solax_sx4.yaml b/templates/solax_sx4.yaml index c758454f..373e9dd6 100644 --- a/templates/solax_sx4.yaml +++ b/templates/solax_sx4.yaml @@ -262,6 +262,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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 diff --git a/templates/sunsynk.yaml b/templates/sunsynk.yaml index a202fa7c..c09a5cf3 100644 --- a/templates/sunsynk.yaml +++ b/templates/sunsynk.yaml @@ -300,6 +300,10 @@ pred_bat: octopus_saving_session: 're:(binary_sensor.octopus_energy([0-9a-z_]+|)_saving_session(s|))' octopus_saving_session_octopoints_per_penny: 8 + # Octopus free session points to the free session Sensor in the Octopus plugin + # Note: You must enable this event sensor in the Octopus Integration in Home Assistant for it to work + octopus_free_session: 're:(event.octopus_energy_([0-9a-z_]+|)_octoplus_free_electricity_session_events)' + # 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