springfall2008 / batpred

Home battery prediction and charging automation for Home Assistant, supporting many inverter types
https://springfall2008.github.io/batpred/
128 stars 45 forks source link

8.4.1: Crash in minute_data_load #1408

Closed onetoomany closed 2 months ago

onetoomany commented 2 months ago

Just upgraded to 8.4.1 from 8.3.x but cannot start due to a crash on minute_data_load

2024-08-30 09:45:00.034793 INFO pred_bat: --------------- PredBat - update at 2024-08-30 09:45:00+01:00 with clock skew 0 minutes, minutes now 585
2024-08-30 09:45:00.035475 INFO pred_bat: Saved current settings to /addon_configs/a0d7b954_appdaemon/predbat_config.json
2024-08-30 09:45:00.035915 INFO pred_bat: Using cached GITHub data for https://api.github.com/repos/springfall2008/batpred/releases age 0.8 minutes
2024-08-30 09:45:00.036339 INFO pred_bat: Predbat /homeassistant/appdaemon/apps/batpred/predbat.py version v8.4.1 currently running, latest version is v8.4.1 latest beta v8.4.1
2024-08-30 09:45:00.036791 INFO pred_bat: Autoupdate: Currently up to date
2024-08-30 09:45:00.051134 INFO pred_bat: Configuration: forecast_hours 48 num_cars 1 debug enable is False calculate_plan_every 10
2024-08-30 09:45:00.051958 INFO pred_bat: Cars 1 charging from battery False planned [False], charging_now [False] smart [False], max_price [0.0], plan_time ['07:00:00'], battery size [100.0], limit [100.0], rate [7.4], exclusive [False]
2024-08-30 09:45:00.052592 INFO pred_bat: Predbat mode is set to Control charge & discharge
2024-08-30 09:45:00.094936 INFO pred_bat: Warn: can not resolve load_today value sensor.givtcp_{geserial}_load_energy_today_kwh
2024-08-30 09:45:00.105262 INFO pred_bat: Info: record_status Warn: can not resolve load_today value sensor.givtcp_{geserial}_load_energy_today_kwh
2024-08-30 09:45:00.109738 INFO pred_bat: Error: Exception raised 0
2024-08-30 09:45:00.110388 INFO pred_bat: Error: Traceback (most recent call last):
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 11068, in run_time_loop
    self.update_pred(scheduled=True)
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 9843, in update_pred
    self.fetch_sensor_data()
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 8895, in fetch_sensor_data
    self.load_minutes, self.load_minutes_age = self.minute_data_load(self.now_utc, "load_today", self.max_days_previous, required_unit="kWh")
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 1029, in minute_data_load
    item = history[0][0]
           ~~~~~~~^^^
KeyError: 0

2024-08-30 09:45:00.122309 INFO pred_bat: Info: record_status Error: Exception raised 0

and in AppDaemon log:

2024-08-30 09:55:00.112351 WARNING pred_bat: ------------------------------------------------------------
2024-08-30 09:55:00.112443 WARNING pred_bat: Unexpected error in worker for App pred_bat:
2024-08-30 09:55:00.112517 WARNING pred_bat: Worker Ags: {'id': 'f8cbd234c9114ca4a2804927f350232e', 'name': 'pred_bat', 'objectid': '6e03c67175674636b00790090a40517c', 'type': 'scheduler', 'function': <bound method PredBat.run_time_loop of <predbat.PredBat object at 0x7f5dde932a50>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'interval': 300, 'random_start': 0, 'random_end': 0, '__thread_id': 'thread-0'}}
2024-08-30 09:55:00.112581 WARNING pred_bat: ------------------------------------------------------------
2024-08-30 09:55:00.113153 WARNING pred_bat: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker
    funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"]))
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 11073, in run_time_loop
    raise e
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 11068, in run_time_loop
    self.update_pred(scheduled=True)
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 9843, in update_pred
    self.fetch_sensor_data()
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 8895, in fetch_sensor_data
    self.load_minutes, self.load_minutes_age = self.minute_data_load(self.now_utc, "load_today", self.max_days_previous, required_unit="kWh")
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 1029, in minute_data_load
    item = history[0][0]
           ~~~~~~~^^^
KeyError: 0

2024-08-30 09:55:00.113243 WARNING pred_bat: ------------------------------------------------------------
onetoomany commented 2 months ago

just realised - issue is my apps.yaml was overwritten in the upgrade. restore and re-upgrade required!