Switch PV curve to HA History API for full day data

This commit is contained in:
Joan
2026-03-20 13:30:38 +01:00
parent 0df6d57483
commit be3d23bb79
2 changed files with 56 additions and 11 deletions

View File

@@ -26,7 +26,7 @@ from weather_icons import draw_weather_icon
from home_assistant import (
get_weather, get_weather_description,
get_interior_weather, get_brightness, get_tesla_status,
get_solar_status
get_solar_status, get_solar_history
)
from netdata import get_hdd_temps
from mqtt_listener import MQTTListener
@@ -133,8 +133,8 @@ class Matrix64Display(SampleBase):
self.hdd_temps = None
self.tesla = None
self.solar = None
self.pv_history = [] # list of (timestamp, production_w) for today's curve
self.pv_history_date = None # track current day to reset history
self.pv_history = [] # list of (hour_float, watts) from HA history
self.last_pv_history_update = 0
# View state
self.current_view = 0
@@ -259,14 +259,6 @@ class Matrix64Display(SampleBase):
self.tesla = get_tesla_status()
self.solar = get_solar_status()
# Record PV history for today's curve
if self.solar and self.solar.get("production") is not None:
now = datetime.datetime.now()
today = now.date()
if self.pv_history_date != today:
self.pv_history = []
self.pv_history_date = today
self.pv_history.append((now.hour + now.minute / 60.0, self.solar["production"]))
except Exception as e:
print(f"Error updating data: {e}")
@@ -814,6 +806,14 @@ class Matrix64Display(SampleBase):
self.update_hdd_temps()
self.last_update = current_time
# Update PV history every 5 minutes
if current_time - self.last_pv_history_update >= 300:
try:
self.pv_history = get_solar_history()
except Exception as e:
print(f"Error updating PV history: {e}")
self.last_pv_history_update = current_time
if current_time - self.last_update >= 15:
self.update_brightness()