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

Fix bugs in auto opt-in saving event, add rate values to next charge/discharge slot sensors #426

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
23 changes: 17 additions & 6 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"
THIS_VERSION = "v7.14.1"
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 @@ -402,7 +402,7 @@
"type": "select",
"options": PREDBAT_MODE_OPTIONS,
"icon": "mdi:state-machine",
"default": PREDBAT_MODE_OPTIONS[PREDBAT_MODE_MONITOR],
"default": PREDBAT_MODE_OPTIONS[PREDBAT_MODE_CONTROL_CHARGEDISCHARGE],
},
{"name": "load_filter_modal", "friendly_name": "Apply modal filter historical load", "type": "switch", "enable": "expert_mode", "default": True},
{"name": "iboost_enable", "friendly_name": "IBoost enable", "type": "switch", "default": False},
Expand Down Expand Up @@ -5730,10 +5730,12 @@ def publish_discharge_limit(self, discharge_window, discharge_limits, best):
discharge_end_str = "undefined"
discharge_start_date = None
discharge_end_date = None
discharge_average = None

if discharge_window and (discharge_window[0]["end"] < (24 * 60 + self.minutes_now)):
discharge_start_minutes = discharge_window[0]["start"]
discharge_end_minutes = discharge_window[0]["end"]
discharge_average = discharge_window[0].get("average", None)

time_format_time = "%H:%M:%S"
discharge_startt = self.midnight_utc + timedelta(minutes=discharge_start_minutes)
Expand All @@ -5760,6 +5762,7 @@ def publish_discharge_limit(self, discharge_window, discharge_limits, best):
state=discharge_limit_percent,
attributes={
"results": discharge_limit_time,
"rate" : discharge_average,
"friendly_name": "Predicted discharge limit best",
"state_class": "measurement",
"unit_of_measurement": "%",
Expand Down Expand Up @@ -5807,6 +5810,7 @@ def publish_discharge_limit(self, discharge_window, discharge_limits, best):
state=discharge_limit_percent,
attributes={
"results": discharge_limit_time,
"rate" : discharge_average,
"friendly_name": "Predicted discharge limit",
"state_class": "measurement",
"unit_of_measurement": "%",
Expand Down Expand Up @@ -5864,6 +5868,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent
if not SIMULATE:
charge_limit_first = 0
charge_limit_percent_first = 0
charge_average_first = None
charge_start_str = "undefined"
charge_end_str = "undefined"
charge_start_date = None
Expand All @@ -5876,6 +5881,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent
charge_limit_percent_first = charge_limit_percent[0]
charge_start_minutes = charge_window[0]["start"]
charge_end_minutes = charge_window[0]["end"]
charge_average_first = charge_window[0].get("average", None)

time_format_time = "%H:%M:%S"
charge_startt = self.midnight_utc + timedelta(minutes=charge_start_minutes)
Expand Down Expand Up @@ -5906,6 +5912,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent
"state_class": "measurement",
"unit_of_measurement": "%",
"icon": "mdi:battery-charging",
"rate" : charge_average_first,
},
)
self.dashboard_item(
Expand Down Expand Up @@ -5953,6 +5960,7 @@ def publish_charge_limit(self, charge_limit, charge_window, charge_limit_percent
"state_class": "measurement",
"unit_of_measurement": "%",
"icon": "mdi:battery-charging",
"rate" : charge_average_first,
},
)
self.dashboard_item(
Expand Down Expand Up @@ -8554,8 +8562,8 @@ def fetch_sensor_data(self):

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")
entity_id = entity_id.replace("binary_sensor.", "event.").replace("_sessions", "_session_events")
joined_events = self.get_state(entity_id=entity_id, attribute="joined_events")

available_events = self.get_state(entity_id=entity_id, attribute="available_events")
if available_events:
Expand All @@ -8566,7 +8574,7 @@ def fetch_sensor_data(self):
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)
self.call_service("octopus_energy/join_octoplus_saving_session_event", event_code = code, entity_id = entity_id)

if joined_events:
for event in joined_events:
Expand Down Expand Up @@ -9289,6 +9297,9 @@ def load_user_config(self, quiet=True, register=False):
if name == "expert_mode":
if new_install:
item["default"] = False
elif name == "mode":
if new_install:
item["default"] = PREDBAT_MODE_OPTIONS[PREDBAT_MODE_MONITOR]

# Find values and monitor config
for item in CONFIG_ITEMS:
Expand Down Expand Up @@ -9569,4 +9580,4 @@ def run_time_loop_balance(self, cb_args):
except Exception as e:
self.log("ERROR: Exception raised {}".format(e))
self.record_status("ERROR: Exception raised {}".format(e))
raise e
raise e
Loading