- ${escapeHtml(value.toFixed(2))} kWh
+
+ ${escapeHtml(percent.toFixed(1))}%
-
- ${escapeHtml(label)}
+
+ ${escapeHtml(title)}
-
- ${(share*100).toFixed(1)}%
+
+ ${escapeHtml(subtitle)}
@@ -130,33 +130,38 @@
}
function render(values, meta) {
- const prod = toNum(values?.Produktion);
- const feed = toNum(values?.Einspeisung);
- const grid = toNum(values?.Netz);
- const house = toNum(values?.Hausverbrauch);
+ const prod = toNum(values?.Produktion);
+ const cons = toNum(values?.Hausverbrauch); // Verbrauch
+ const grid = toNum(values?.Netz); // Netzbezug
- const order = [
- { key: 'Produktion', val: prod, color: '#63B3FF' }, // blau
- { key: 'Konsum', val: house, color: '#A855F7' }, // lila (wie Screenshot)
- { key: 'Einspeisung', val: feed, color: '#F59E0B' }, // orange
- { key: 'Netz', val: grid, color: '#34D399' } // grün
- ];
+ const eigen = cons - grid; // Eigenverbrauch
+ const eigenClamped = eigen < 0 ? 0 : eigen;
- const sum = order.reduce((a, x) => a + x.val, 0);
+ const evq = (prod > 0) ? (eigenClamped / prod * 100) : 0;
+ const autark = (cons > 0) ? (eigenClamped / cons * 100) : 0;
- // Hinweis
+ // Hinweise
if (meta?.hasData === false) {
elHint.textContent = 'Keine Logdaten für den gewählten Zeitraum.';
} else {
- elHint.textContent = sum > 0 ? `Summe (zur Prozent-Berechnung): ${formatKwh(sum)}` : 'Summe: 0.00 kWh';
+ elHint.textContent =
+ `Produktion: ${prod.toFixed(2)} kWh · Verbrauch: ${cons.toFixed(2)} kWh · Netzbezug: ${grid.toFixed(2)} kWh · Eigenverbrauch: ${eigenClamped.toFixed(2)} kWh`;
}
- elGrid.innerHTML = order.map(x => donutCard({
- label: x.key,
- value: x.val,
- share: sum > 0 ? (x.val / sum) : 0,
- color: x.color
- })).join('');
+ elGrid.innerHTML = [
+ donutCard({
+ title: 'EVQ',
+ percent: clamp01(evq / 100) * 100,
+ subtitle: 'Eigenverbrauch / Produktion',
+ color: '#63B3FF' // blau
+ }),
+ donutCard({
+ title: 'Autarkiegrad',
+ percent: clamp01(autark / 100) * 100,
+ subtitle: 'Eigenverbrauch / Verbrauch',
+ color: '#A855F7' // lila
+ })
+ ].join('');
}
// Symcon -> Tile
@@ -186,7 +191,6 @@
elPeriod.textContent = '';
}
- // Charts
render(data.values || {}, { hasData: data.hasData });
};