Skip to content

Commit

Permalink
Update Tesla API and minor stuff
Browse files Browse the repository at this point in the history
Improved tibber charge decision
really minor logging changes
  • Loading branch information
fabianhu committed Dec 23, 2023
1 parent 20d1da5 commit aaf3f3a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
18 changes: 10 additions & 8 deletions efb_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lib/intervaltask/intervaltask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lib/tesla_api
Submodule tesla_api updated 3 files
+21 −0 LICENSE
+2 −0 README.md
+25 −14 tesla_api_2024.py
8 changes: 6 additions & 2 deletions lib/tibber/tibber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions task_tibber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,4 +132,4 @@ def check_battery(_house_soc):
soclim = 80

#dt = myTibber.cheapest_charging_time(soc, soclim)
#print( dt)
#print( dt)
2 changes: 1 addition & 1 deletion tesla_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aaf3f3a

Please sign in to comment.