"Konnte die Anfrage nicht lesen."], 400); } try { switch ($action) { case "save": $id = saveAutomation($body); jsonAntwort(["id" => $id]); case "delete": deleteAutomation(intval($body["id"] ?? 0)); jsonAntwort(["ok" => true]); case "toggle": jsonAntwort(["enabled" => toggleAutomation(intval($body["id"] ?? 0))]); default: jsonAntwort(["error" => "Unbekannte Aktion."], 400); } } catch (InvalidArgumentException $e) { jsonAntwort(["error" => $e->getMessage()], 400); } catch (Throwable $e) { jsonAntwort(["error" => "Speichern fehlgeschlagen: " . $e->getMessage()], 500); } } // --- Uebersichtstabelle -------------------------------------------------- if ($action === "list") { $tage = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]; $list = listAutomations($floor); if (!$list) { echo "

Für diese Etage ist noch nichts eingerichtet.

"; } else { echo "
"; // Je schmaler der Schirm, desto weniger Spalten: auf dem Handy bleiben // Name, Ausloeser und die Knoepfe. Sonst muss man seitwaerts scrollen, // um eine Automatik ueberhaupt pausieren zu koennen. echo "" . "" . "" . ""; foreach ($list as $a) { // Nur die aktiven Tage nennen. Sieben Haekchen untereinander // haben die Zeile frueher unnoetig hoch gemacht. $aktiveTage = []; for ($i = 0; $i < 7; $i++) { if ($a["weekdays"] & (1 << $i)) { $aktiveTage[] = $tage[$i]; } } $wann = count($aktiveTage) === 7 ? "täglich" : implode(" ", $aktiveTage); if ($a["window_from"] !== "00:00" || $a["window_to"] !== "23:59") { $wann .= ", " . $a["window_from"] . "–" . $a["window_to"]; } if (!$a["on_holiday"]) { $wann .= ", nicht an Feiertagen"; } if (!$a["on_vacation"]) { $wann .= ", nicht in den Ferien"; } $zuletzt = $a["last_run"] ? date("d.m. H:i", strtotime($a["last_run"])) : "–"; $klasse = $a["enabled"] ? "" : " class='opacity-50'"; $pause = $a["enabled"] ? "bi-pause-fill" : "bi-play-fill"; $titel = $a["enabled"] ? "Pausieren" : "Fortsetzen"; $id = intval($a["id"]); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
NameAuslöserAktionWannZuletzt
" . htmlspecialchars($a["name"]) . "" . htmlspecialchars($a["conditionText"]) . "" . htmlspecialchars($a["actionText"]) . "" . htmlspecialchars($wann) . "" . $zuletzt . "" . " " . " " . "" . "
"; } exit; } // --- Editor -------------------------------------------------------------- $id = intval($_GET["id"] ?? 0); $auto = $id > 0 ? loadAutomation($id) : null; if (!$auto) { $auto = emptyAutomation($floor); } // Geraetekatalog und Datensatz reisen im selben Dokument mit. Frueher holte // der Editor die Geraeteliste und je Zeile noch einmal deren Details nach - // zwei zusaetzliche Anfragen pro Bedingung, und die Dropdowns fuellten sich // asynchron, weshalb ein gespeicherter Wert nicht zuverlaessig ankam. $nutzdaten = json_encode([ "automation" => $auto, "devices" => deviceCatalog(), ], JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>

Aktiver Zeitraum
Aktive Wochentage: