From aaf3f3a5ba02c236b7cd3ffd907abf559b20651d Mon Sep 17 00:00:00 2001 From: fabianhu Date: Sun, 24 Dec 2023 00:28:39 +0100 Subject: [PATCH] Update Tesla API and minor stuff Improved tibber charge decision really minor logging changes --- efb_main.py | 18 ++++++++++-------- lib/intervaltask/intervaltask.py | 2 +- lib/tesla_api | 2 +- lib/tibber/tibber.py | 8 ++++++-- task_tibber.py | 4 ++-- tesla_interface.py | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/efb_main.py b/efb_main.py index 541ed09..12ff9a7 100644 --- a/efb_main.py +++ b/efb_main.py @@ -424,28 +424,30 @@ def do_display_update(self): def do_tesla_tibber_planning(self): from task_tibber import myTibber - TIBBER_CAR_CHARGE_CURRENT = 16 # todo parameter + TIBBER_CAR_CHARGE_CURRENT = 16 # todo parameter - must be the same value as the decision, if solar overflow charging!! now = datetime.now() #fixme take into account the time of last connection? - if now-self.last_tibber_schedule > timedelta(hours=12) and self.myTesla.is_here_and_connected(): - + if now-self.last_tibber_schedule > timedelta(hours=2) and self.myTesla.is_here_and_connected(): soc = self.myTesla.car_db_data.get_value("CAR_battery_level") soclim = self.myTesla.car_db_data.get_value("CAR_charge_limit_soc") charge_current_request = self.myTesla.car_db_data.get_value("CAR_charge_current_request") + + if charge_current_request != TIBBER_CAR_CHARGE_CURRENT: + logger.info(f"Tibber charging cancelled due to requested {charge_current_request} A instead of {TIBBER_CAR_CHARGE_CURRENT} A.") + self.myTesla.tesla_api.cmd_charge_cancel_schedule(self.myTesla.vin) + return + if soc is None or soclim is None: logger.error("Tibber Charge Plan no info from Tesla") return + mins = lib.tibber.tibber.datetime_to_minutes_after_midnight(myTibber.cheapest_charging_time(soc,soclim)) if mins is None: logger.error(f"Tibber we had no result from {myTibber.prices}") return + self.myTesla.tesla_api.cmd_charge_set_schedule(self.myTesla.vin, mins) - # fixme check and set charge current to 16A / 13A whatever is possible - if charge_current_request != TIBBER_CAR_CHARGE_CURRENT: - pass - # fixme might not be smart, as we could be solar-charging with low current right now. Check, if we can constrict the planning after sunset? - # self.myTesla.tesla_api.cmd_charge_set_amps(self.myTesla.vin, TIBBER_CAR_CHARGE_CURRENT) self.last_tibber_schedule = now logger.debug(f"Tibbering {mins/60} h") diff --git a/lib/intervaltask/intervaltask.py b/lib/intervaltask/intervaltask.py index e707e90..173b923 100644 --- a/lib/intervaltask/intervaltask.py +++ b/lib/intervaltask/intervaltask.py @@ -69,7 +69,7 @@ def _restart_task(self, name): logger.log(f"Watchdog activated for task {name}.") task_data = self.tasks[name] if self.is_task_running(name): # check if task is still running - logger.log(f"Task {name} is still running and the timeout of {self.tasks[name]['watchdog_timeout']}s is over") + logger.error(f"Task {name} is still running and the timeout of {self.tasks[name]['watchdog_timeout']}s is over") # fixme we did not kill it! raise Exception(f"Task {name} is hanging") else: diff --git a/lib/tesla_api b/lib/tesla_api index 64c77d1..a414bb5 160000 --- a/lib/tesla_api +++ b/lib/tesla_api @@ -1 +1 @@ -Subproject commit 64c77d13b498dd7a1efebed22df899347186e035 +Subproject commit a414bb5979153dab991b50f29b9d50912961d94a diff --git a/lib/tibber/tibber.py b/lib/tibber/tibber.py index 771e25e..cfc1b72 100644 --- a/lib/tibber/tibber.py +++ b/lib/tibber/tibber.py @@ -254,10 +254,12 @@ def cheapest_charging_time(self, _current_soc, _target_soc, capacity_kWh=77, max # Check if end time exceeds the maximum time in the dictionary if i == len(sorted_keys) - 1 or end_time > sorted_keys[-1]: + logger.info(f"Amount of remaining time shards not sufficient: Last time interval: {sorted_keys[-1]}") break # Stop if the remaining time intervals are not sufficient # Check, if charging after next morning if end_time > latest_end: + logger.info(f"Charging would not be finished until {target_hour} h") break # Stop if end would be too late # Sum values within the time interval @@ -268,8 +270,10 @@ def cheapest_charging_time(self, _current_soc, _target_soc, capacity_kWh=77, max min_interval_sum = interval_sum min_interval_start = start_time - # Example output - logger.debug(f"Start time of the minimal interval: {min_interval_start}") + if min_interval_start is None: + logger.error("No interval could be found") + else: + logger.debug(f"Start time of the minimal interval: {min_interval_start}") return min_interval_start diff --git a/task_tibber.py b/task_tibber.py index c1541cd..61b0364 100644 --- a/task_tibber.py +++ b/task_tibber.py @@ -7,7 +7,7 @@ from datetime import datetime, timedelta from lib.logger import Logger import logging -logger = Logger(logging.INFO, "tibber.log") +logger = Logger(logging.DEBUG, "tibber.log") from lib.tibber.tibber import tibber_time_to_datetime from lib.measurementlist import MeasurementList @@ -132,4 +132,4 @@ def check_battery(_house_soc): soclim = 80 #dt = myTibber.cheapest_charging_time(soc, soclim) - #print( dt) \ No newline at end of file + #print( dt) diff --git a/tesla_interface.py b/tesla_interface.py index 52e7858..6ebdc31 100644 --- a/tesla_interface.py +++ b/tesla_interface.py @@ -17,7 +17,7 @@ from lib.tesla_api import tesla_api_2024 logToFile = False -APIVERSION = 69 +APIVERSION = 71 # extract the value from a multi index