From 36e48ced729a37b65c81ff77b42180401fcc89d6 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Wed, 29 Nov 2023 08:47:27 +0000 Subject: [PATCH] Pick saving session rates from Octopus add-in v9.1.0 (#388) --- apps/predbat/predbat.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 23fa1a23..8b3215c3 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.17" +THIS_VERSION = "v7.13.18" 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" @@ -8275,25 +8275,25 @@ def fetch_sensor_data(self): entity_id = self.get_arg("octopus_saving_session", indirect=False) if entity_id: saving_rate = self.get_arg("metric_octopus_saving_rate") - if saving_rate > 0: - 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") - if joined_events: - for event in joined_events: - start = event.get('start', None) - end = event.get('end', None) - if start and end: - octopus_saving_slot = {} - octopus_saving_slot["start"] = start - octopus_saving_slot["end"] = end - octopus_saving_slot["rate"] = saving_rate - octopus_saving_slot["state"] = state - octopus_saving_slots.append(octopus_saving_slot) - self.log("Joined Octopus saving session: {} - {} at assumed rate {} state {}".format(start, end, saving_rate, state)) + 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") + 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 + if start and end and saving_rate > 0: + octopus_saving_slot = {} + octopus_saving_slot["start"] = start + octopus_saving_slot["end"] = end + octopus_saving_slot["rate"] = saving_rate + octopus_saving_slot["state"] = state + octopus_saving_slots.append(octopus_saving_slot) + self.log("Joined Octopus saving session: {} - {} at rate {} state {}".format(start, end, saving_rate, state)) # In saving session that's not reported, assumed 30-minutes if state and not joined_events: