allesbrauchtstrom.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. // index.php
  3. $default_power_w = 90;
  4. $default_price = 0.32;
  5. $default_solar_hours = 10;
  6. $default_run_hours = 24;
  7. $power_w = isset($_GET['power_w']) ? floatval($_GET['power_w']) : $default_power_w;
  8. $price = isset($_GET['price']) ? floatval($_GET['price']) : $default_price;
  9. $solar_hours = isset($_GET['solar_hours']) ? floatval($_GET['solar_hours']) : $default_solar_hours;
  10. $run_hours = isset($_GET['run_hours']) ? floatval($_GET['run_hours']) : $default_run_hours;
  11. $year_hours = 8760;
  12. $day_hours = 24;
  13. // ensure sane bounds
  14. if ($solar_hours < 0) $solar_hours = 0;
  15. if ($solar_hours > 24) $solar_hours = 24;
  16. if ($run_hours < 0) $run_hours = 0;
  17. if ($run_hours > 24) $run_hours = 24;
  18. $active_hours_per_year = $run_hours * 365.0;
  19. $annual_kwh = $power_w * $active_hours_per_year / 1000.0;
  20. // Netzbezug: nur die Stunden, in denen das System läuft UND keine Solarversorgung besteht.
  21. // Pro Tag: Netzstunden = max(0, run_hours - solar_hours)
  22. $net_hours_per_day = max(0.0, $run_hours - $solar_hours);
  23. $net_hours_per_year = $net_hours_per_day * 365.0;
  24. $net_kwh = $power_w * $net_hours_per_year / 1000.0;
  25. $daily_cost = ($power_w * $net_hours_per_day / 1000.0) * $price;
  26. $annual_cost = $net_kwh * $price;
  27. ?>
  28. <!doctype html>
  29. <html lang="de">
  30. <head>
  31. <meta charset="utf-8">
  32. <meta name="viewport" content="width=device-width,initial-scale=1">
  33. <title>Stromkosten-Rechner (Solar Direktverbrauch)</title>
  34. <style>
  35. body { font-family: Arial, sans-serif; margin: 24px; color: #111; }
  36. .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); }
  37. h1 { font-size: 20px; margin-bottom: 8px; }
  38. .control { margin:14px 0; }
  39. label { display:block; font-size:13px; margin-bottom:6px; color:#333; }
  40. input[type="range"] { width:100%; }
  41. .muted { color:#666; font-size:13px; }
  42. .value { font-weight:700; margin-left:6px; }
  43. .results { margin-top:18px; display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
  44. .result { padding:12px; border-radius:6px; background:#f9f9f9; border:1px solid #eee; }
  45. .footer { margin-top:14px; font-size:13px; color:#444; }
  46. @media (max-width:600px){ .results{grid-template-columns:1fr;} }
  47. </style>
  48. </head>
  49. <body>
  50. <div class="card">
  51. <h1>Stromkosten-Rechner mit Solar Direktverbrauch</h1>
  52. <div class="control">
  53. <label for="power">Leistung (W)
  54. <span class="muted"> Aktuell: <span id="power_val" class="value"><?php echo htmlspecialchars($power_w); ?></span> W</span>
  55. </label>
  56. <input id="power" type="range" min="1" max="500" step="1" value="<?php echo htmlspecialchars($power_w); ?>">
  57. </div>
  58. <div class="control">
  59. <label for="price">Strompreis (€/kWh)
  60. <span class="muted"> Aktuell: <span id="price_val" class="value"><?php echo number_format($price,2); ?></span> €/kWh</span>
  61. </label>
  62. <input id="price" type="range" min="0.01" max="1.00" step="0.01" value="<?php echo htmlspecialchars($price); ?>">
  63. </div>
  64. <div class="control">
  65. <label for="solar">Sonnenstunden/Tag (Solarversorgung)
  66. <span class="muted"> Aktuell: <span id="solar_val" class="value"><?php echo htmlspecialchars($solar_hours); ?></span> h/Tag</span>
  67. </label>
  68. <input id="solar" type="range" min="0" max="24" step="0.5" value="<?php echo htmlspecialchars($solar_hours); ?>">
  69. </div>
  70. <div class="control">
  71. <label for="run">Betriebsstunden/Tag (System läuft)
  72. <span class="muted"> Aktuell: <span id="run_val" class="value"><?php echo htmlspecialchars($run_hours); ?></span> h/Tag</span>
  73. </label>
  74. <input id="run" type="range" min="0" max="24" step="0.25" value="<?php echo htmlspecialchars($run_hours); ?>">
  75. </div>
  76. <div class="results" id="results">
  77. <div class="result">
  78. <div class="muted">Jahresenergiebedarf (nur Laufzeit)</div>
  79. <div style="font-size:18px; font-weight:700" id="annual_kwh"><?php echo number_format($annual_kwh,1); ?></div>
  80. <div class="muted">kWh / Jahr</div>
  81. </div>
  82. <div class="result">
  83. <div class="muted">Netzbezug (Jahr)</div>
  84. <div style="font-size:18px; font-weight:700" id="net_kwh"><?php echo number_format($net_kwh,1); ?></div>
  85. <div class="muted">kWh / Jahr (bei <?php echo htmlspecialchars($solar_hours); ?> h Solar/Tag)</div>
  86. </div>
  87. <div class="result">
  88. <div class="muted">Tägliche Kosten (Netz)</div>
  89. <div style="font-size:18px; font-weight:700" id="daily_cost"><?php echo number_format($daily_cost,3); ?></div>
  90. <div class="muted">€ / Tag</div>
  91. </div>
  92. <div class="result">
  93. <div class="muted">Jährliche Kosten (Netz)</div>
  94. <div style="font-size:18px; font-weight:700" id="annual_cost"><?php echo number_format($annual_cost,2); ?></div>
  95. <div class="muted">€ / Jahr</div>
  96. </div>
  97. </div>
  98. <div class="footer">
  99. <div class="muted">Kurze Hinweise:</div>
  100. <ul class="muted">
  101. <li>Die angegebenen Betriebsstunden/Tag steuern, wie lange das System täglich läuft.</li>
  102. <li>Solar deckt die eingegebene Anzahl Stunden/Tag vollständig; nur während laufender, nicht-solarer Stunden wird Netzstrom bezogen.</li>
  103. <li>Berechnungen gehen von 365 Tagen/Jahr aus; Monats- oder saisonale Schwankungen sind nicht berücksichtigt.</li>
  104. <li>Alle Werte sind Näherungswerte zur Orientierung: echte Messungen sind genauer.</li>
  105. </ul>
  106. </div>
  107. </div>
  108. <script>
  109. (function(){
  110. const yearDays = 365.0;
  111. const power = document.getElementById('power');
  112. const price = document.getElementById('price');
  113. const solar = document.getElementById('solar');
  114. const run = document.getElementById('run');
  115. const power_val = document.getElementById('power_val');
  116. const price_val = document.getElementById('price_val');
  117. const solar_val = document.getElementById('solar_val');
  118. const run_val = document.getElementById('run_val');
  119. const annual_kwh_el = document.getElementById('annual_kwh');
  120. const net_kwh_el = document.getElementById('net_kwh');
  121. const daily_cost_el = document.getElementById('daily_cost');
  122. const annual_cost_el = document.getElementById('annual_cost');
  123. const fmt = (v,dec=1) => Number(v).toLocaleString('de-DE', {minimumFractionDigits:dec, maximumFractionDigits:dec});
  124. const fmtPrice = (v,dec=2) => Number(v).toLocaleString('de-DE', {minimumFractionDigits:dec, maximumFractionDigits:dec});
  125. function recalc(){
  126. const p = parseFloat(power.value); // W
  127. const pr = parseFloat(price.value); // €/kWh
  128. const sh = parseFloat(solar.value); // h/day solar
  129. const rh = parseFloat(run.value); // h/day running
  130. const activeHoursYear = rh * yearDays;
  131. const annualKwh = p * activeHoursYear / 1000.0;
  132. // Netzstunden pro Tag = Betriebsstunden minus Solarstunden (clamp >=0)
  133. const netHoursPerDay = Math.max(0, rh - sh);
  134. const netHoursYear = netHoursPerDay * yearDays;
  135. const netKwh = p * netHoursYear / 1000.0;
  136. const dailyCost = (p * netHoursPerDay / 1000.0) * pr;
  137. const annualCost = netKwh * pr;
  138. power_val.textContent = Math.round(p);
  139. price_val.textContent = fmtPrice(pr,2);
  140. solar_val.textContent = (sh % 1 === 0) ? sh.toFixed(0) : sh.toFixed(1);
  141. run_val.textContent = (rh % 1 === 0) ? rh.toFixed(0) : rh.toFixed(2);
  142. annual_kwh_el.textContent = fmt(annualKwh,1);
  143. net_kwh_el.textContent = fmt(netKwh,1);
  144. daily_cost_el.textContent = fmt(dailyCost,3) + ' €';
  145. annual_cost_el.textContent = fmtPrice(annualCost,2) + ' €';
  146. }
  147. power.addEventListener('input', recalc);
  148. price.addEventListener('input', recalc);
  149. solar.addEventListener('input', recalc);
  150. run.addEventListener('input', recalc);
  151. recalc();
  152. })();
  153. </script>
  154. </body>
  155. </html>