Quellcode durchsuchen

'allesbrauchtstrom.php' hinzufügen

initial commit
es vor 1 Woche
Ursprung
Commit
964f31f2d7
1 geänderte Dateien mit 176 neuen und 0 gelöschten Zeilen
  1. 176 0
      allesbrauchtstrom.php

+ 176 - 0
allesbrauchtstrom.php

@@ -0,0 +1,176 @@
+<?php
+// index.php
+$default_power_w = 90;
+$default_price = 0.32;
+$default_solar_hours = 10;
+$default_run_hours = 24;
+$power_w = isset($_GET['power_w']) ? floatval($_GET['power_w']) : $default_power_w;
+$price = isset($_GET['price']) ? floatval($_GET['price']) : $default_price;
+$solar_hours = isset($_GET['solar_hours']) ? floatval($_GET['solar_hours']) : $default_solar_hours;
+$run_hours = isset($_GET['run_hours']) ? floatval($_GET['run_hours']) : $default_run_hours;
+$year_hours = 8760;
+$day_hours = 24;
+
+// ensure sane bounds
+if ($solar_hours < 0) $solar_hours = 0;
+if ($solar_hours > 24) $solar_hours = 24;
+if ($run_hours < 0) $run_hours = 0;
+if ($run_hours > 24) $run_hours = 24;
+
+$active_hours_per_year = $run_hours * 365.0;
+$annual_kwh = $power_w * $active_hours_per_year / 1000.0;
+
+// Netzbezug: nur die Stunden, in denen das System läuft UND keine Solarversorgung besteht.
+// Pro Tag: Netzstunden = max(0, run_hours - solar_hours)
+$net_hours_per_day = max(0.0, $run_hours - $solar_hours);
+$net_hours_per_year = $net_hours_per_day * 365.0;
+$net_kwh = $power_w * $net_hours_per_year / 1000.0;
+
+$daily_cost = ($power_w * $net_hours_per_day / 1000.0) * $price;
+$annual_cost = $net_kwh * $price;
+?>
+<!doctype html>
+<html lang="de">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<title>Stromkosten-Rechner (Solar Direktverbrauch)</title>
+<style>
+  body { font-family: Arial, sans-serif; margin: 24px; color: #111; }
+  .card { max-width: 760px; margin: auto; padding: 18px; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.03); }
+  h1 { font-size: 20px; margin-bottom: 8px; }
+  .control { margin:14px 0; }
+  label { display:block; font-size:13px; margin-bottom:6px; color:#333; }
+  input[type="range"] { width:100%; }
+  .muted { color:#666; font-size:13px; }
+  .value { font-weight:700; margin-left:6px; }
+  .results { margin-top:18px; display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
+  .result { padding:12px; border-radius:6px; background:#f9f9f9; border:1px solid #eee; }
+  .footer { margin-top:14px; font-size:13px; color:#444; }
+  @media (max-width:600px){ .results{grid-template-columns:1fr;} }
+</style>
+</head>
+<body>
+<div class="card">
+  <h1>Stromkosten-Rechner mit Solar Direktverbrauch</h1>
+
+  <div class="control">
+    <label for="power">Leistung (W)
+      <span class="muted"> Aktuell: <span id="power_val" class="value"><?php echo htmlspecialchars($power_w); ?></span> W</span>
+    </label>
+    <input id="power" type="range" min="1" max="500" step="1" value="<?php echo htmlspecialchars($power_w); ?>">
+  </div>
+
+  <div class="control">
+    <label for="price">Strompreis (€/kWh)
+      <span class="muted"> Aktuell: <span id="price_val" class="value"><?php echo number_format($price,2); ?></span> €/kWh</span>
+    </label>
+    <input id="price" type="range" min="0.01" max="1.00" step="0.01" value="<?php echo htmlspecialchars($price); ?>">
+  </div>
+
+  <div class="control">
+    <label for="solar">Sonnenstunden/Tag (Solarversorgung)
+      <span class="muted"> Aktuell: <span id="solar_val" class="value"><?php echo htmlspecialchars($solar_hours); ?></span> h/Tag</span>
+    </label>
+    <input id="solar" type="range" min="0" max="24" step="0.5" value="<?php echo htmlspecialchars($solar_hours); ?>">
+  </div>
+
+  <div class="control">
+    <label for="run">Betriebsstunden/Tag (System läuft)
+      <span class="muted"> Aktuell: <span id="run_val" class="value"><?php echo htmlspecialchars($run_hours); ?></span> h/Tag</span>
+    </label>
+    <input id="run" type="range" min="0" max="24" step="0.25" value="<?php echo htmlspecialchars($run_hours); ?>">
+  </div>
+
+  <div class="results" id="results">
+    <div class="result">
+      <div class="muted">Jahresenergiebedarf (nur Laufzeit)</div>
+      <div style="font-size:18px; font-weight:700" id="annual_kwh"><?php echo number_format($annual_kwh,1); ?></div>
+      <div class="muted">kWh / Jahr</div>
+    </div>
+
+    <div class="result">
+      <div class="muted">Netzbezug (Jahr)</div>
+      <div style="font-size:18px; font-weight:700" id="net_kwh"><?php echo number_format($net_kwh,1); ?></div>
+      <div class="muted">kWh / Jahr (bei <?php echo htmlspecialchars($solar_hours); ?> h Solar/Tag)</div>
+    </div>
+
+    <div class="result">
+      <div class="muted">Tägliche Kosten (Netz)</div>
+      <div style="font-size:18px; font-weight:700" id="daily_cost"><?php echo number_format($daily_cost,3); ?></div>
+      <div class="muted">€ / Tag</div>
+    </div>
+
+    <div class="result">
+      <div class="muted">Jährliche Kosten (Netz)</div>
+      <div style="font-size:18px; font-weight:700" id="annual_cost"><?php echo number_format($annual_cost,2); ?></div>
+      <div class="muted">€ / Jahr</div>
+    </div>
+  </div>
+
+ <div class="footer">
+   <div class="muted">Kurze Hinweise:</div>
+   <ul class="muted">
+     <li>Die angegebenen Betriebsstunden/Tag steuern, wie lange das System täglich läuft.</li>
+     <li>Solar deckt die eingegebene Anzahl Stunden/Tag vollständig; nur während laufender, nicht-solarer Stunden wird Netzstrom bezogen.</li>
+     <li>Berechnungen gehen von 365 Tagen/Jahr aus; Monats- oder saisonale Schwankungen sind nicht berücksichtigt.</li>
+     <li>Alle Werte sind Näherungswerte zur Orientierung: echte Messungen sind genauer.</li>
+   </ul>
+ </div>
+</div>
+
+<script>
+(function(){
+  const yearDays = 365.0;
+  const power = document.getElementById('power');
+  const price = document.getElementById('price');
+  const solar = document.getElementById('solar');
+  const run = document.getElementById('run');
+  const power_val = document.getElementById('power_val');
+  const price_val = document.getElementById('price_val');
+  const solar_val = document.getElementById('solar_val');
+  const run_val = document.getElementById('run_val');
+  const annual_kwh_el = document.getElementById('annual_kwh');
+  const net_kwh_el = document.getElementById('net_kwh');
+  const daily_cost_el = document.getElementById('daily_cost');
+  const annual_cost_el = document.getElementById('annual_cost');
+
+  const fmt = (v,dec=1) => Number(v).toLocaleString('de-DE', {minimumFractionDigits:dec, maximumFractionDigits:dec});
+  const fmtPrice = (v,dec=2) => Number(v).toLocaleString('de-DE', {minimumFractionDigits:dec, maximumFractionDigits:dec});
+
+  function recalc(){
+    const p = parseFloat(power.value);       // W
+    const pr = parseFloat(price.value);      // €/kWh
+    const sh = parseFloat(solar.value);      // h/day solar
+    const rh = parseFloat(run.value);        // h/day running
+    const activeHoursYear = rh * yearDays;
+    const annualKwh = p * activeHoursYear / 1000.0;
+
+    // Netzstunden pro Tag = Betriebsstunden minus Solarstunden (clamp >=0)
+    const netHoursPerDay = Math.max(0, rh - sh);
+    const netHoursYear = netHoursPerDay * yearDays;
+    const netKwh = p * netHoursYear / 1000.0;
+
+    const dailyCost = (p * netHoursPerDay / 1000.0) * pr;
+    const annualCost = netKwh * pr;
+
+    power_val.textContent = Math.round(p);
+    price_val.textContent = fmtPrice(pr,2);
+    solar_val.textContent = (sh % 1 === 0) ? sh.toFixed(0) : sh.toFixed(1);
+    run_val.textContent = (rh % 1 === 0) ? rh.toFixed(0) : rh.toFixed(2);
+
+    annual_kwh_el.textContent = fmt(annualKwh,1);
+    net_kwh_el.textContent = fmt(netKwh,1);
+    daily_cost_el.textContent = fmt(dailyCost,3) + ' €';
+    annual_cost_el.textContent = fmtPrice(annualCost,2) + ' €';
+  }
+
+  power.addEventListener('input', recalc);
+  price.addEventListener('input', recalc);
+  solar.addEventListener('input', recalc);
+  run.addEventListener('input', recalc);
+  recalc();
+})();
+</script>
+</body>
+</html>