Monitoring for the Refusol 020K inverters. The on-site poller POSTs each 60 s cycle to /api/readings; the dashboard answers first whether every inverter is operating and whether one is producing far less than its peers (string fuse / breaker problems). - Backend: FastAPI + SQLite. Parameters defined once in fields.py (columns auto-added on start); unknown poller keys are kept in `extra` since the parameter map is still being researched. Idempotent ingest, daily energy rollup in site-local days, history downsampling, 2-year retention. - Health: Offline vs Sleeping (sun elevation) vs No data (datalogger silent, detected via empty-batch heartbeats), Fault from error_code, underperformance vs fleet median (per kWp when sizes set), MPPT imbalance. - Frontend: mobile-first React + Tailwind, installable PWA, comparison bars, 24 h power / 30 day energy charts, detail page with all parameters. - Docker: backend + frontend + nginx on one port for NPM, as in bellsystems-cp; deploy-host.sh pulls main and rebuilds. - poller/backend_client.py: stdlib client with offline spool for refusol_poller.py; fake_poller.py simulates the site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.1 KiB
Python
58 lines
2.1 KiB
Python
from functools import lru_cache
|
|
|
|
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
|
|
|
# Shared secret the on-site poller sends in X-API-Key. Also guards the
|
|
# inverter metadata edits (name, kWp, ...).
|
|
api_key: str = "change-me"
|
|
|
|
db_path: str = "/app/data/solar.db"
|
|
|
|
# Local calendar of the installation — decides where "today" starts for
|
|
# the daily-energy rollup and the charts.
|
|
site_timezone: str = "Europe/Athens"
|
|
# Used to compute the sun's elevation so an inverter that went quiet at
|
|
# night shows as "sleeping" instead of raising an alarm. Leave empty to
|
|
# treat every silent inverter as offline.
|
|
site_latitude: float | None = None
|
|
site_longitude: float | None = None
|
|
# Below this sun elevation (degrees) inverters are expected to be off.
|
|
daylight_min_elevation: float = 5.0
|
|
|
|
# A reading newer than this marks an inverter as Online.
|
|
online_window_seconds: int = 300
|
|
retention_days: int = 730
|
|
|
|
# Underperformance check: an inverter is flagged when its output (per kWp
|
|
# if capacities are set, otherwise raw W) is below this fraction of the
|
|
# fleet median over the last few minutes.
|
|
underperform_ratio: float = 0.75
|
|
underperform_window_seconds: int = 600
|
|
# Skip the check while the fleet is barely producing (dawn, dusk, heavy
|
|
# overcast) — differences there are noise.
|
|
underperform_min_fleet_w_per_kwp: float = 50.0
|
|
underperform_min_fleet_w: float = 1000.0
|
|
|
|
# One MPPT producing under this fraction of the other is flagged (only
|
|
# for inverters with mppt_count = 2), once the stronger one exceeds
|
|
# mppt_min_power_w.
|
|
mppt_imbalance_ratio: float = 0.5
|
|
mppt_min_power_w: float = 1000.0
|
|
|
|
cors_origins: list[str] = ["*"]
|
|
|
|
@field_validator("site_latitude", "site_longitude", mode="before")
|
|
@classmethod
|
|
def blank_is_none(cls, v):
|
|
return None if isinstance(v, str) and not v.strip() else v
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|