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

Auto opt into saving sessions, remove old assumed rate sensor #418

Merged
merged 8 commits into from
Dec 4, 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
1 change: 1 addition & 0 deletions .cspell/custom-dictionary-workspace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ nattribute
nearr
nord
Nordpool
octoplus
octopoints
Ohme
oncharge
Expand Down
3 changes: 2 additions & 1 deletion apps/predbat/config/apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down
37 changes: 18 additions & 19 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.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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -4695,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 {} assumed 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
Expand Down Expand Up @@ -8549,20 +8534,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Octopus told me that they're passing on £2.25, although clearly plenty / all have been higher than that so far, so I think it'd be safe to take £2.25 as a minimum.

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:
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_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)

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_penny) / octopoints_per_penny # Octopoints per pence
if start and end and saving_rate > 0:
octopus_saving_slot = {}
octopus_saving_slot["start"] = start
Expand Down
14 changes: 12 additions & 2 deletions docs/config-yml-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions docs/energy-rates.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down