"Konnte die Anfrage nicht lesen."], 400); } try { if (($_GET["action"] ?? "") === "command") { $text = executeCommand(intval($body["command_id"] ?? 0), is_array($body["params"] ?? null) ? $body["params"] : [], !empty($body["probe"])); raumAntwort(["ok" => $text]); } if (($_GET["action"] ?? "") === "temp") { // Bewusst derselbe Weg wie im alten Thermostat-Modal: das Topic // Raumtemp///changeSetTemp. $raum = preg_replace('/[^A-Za-z0-9_]/', '', strval($body["room"] ?? "")); $temp = intval($body["temp"] ?? 0); if ($temp < 10 || $temp > 30) { raumAntwort(["error" => "Temperatur außerhalb 10–30 °C."], 400); } $mqtt = new Bluerhinos\phpMQTT(MQTT_BROKER, MQTT_PORT, "RoomTempSetter_" . getmypid()); if (!$mqtt->connect(true, null, "", "")) { raumAntwort(["error" => "Keine Verbindung zum MQTT-Broker."], 500); } $mqtt->publish("Raumtemp/" . str_replace("_", "/", $raum) . "/changeSetTemp", strval($temp), 0, false); $mqtt->close(); raumAntwort(["ok" => "Solltemperatur " . $temp . " °C"]); } raumAntwort(["error" => "Unbekannte Aktion."], 400); } catch (InvalidArgumentException $e) { raumAntwort(["error" => $e->getMessage()], 400); } catch (Throwable $e) { raumAntwort(["error" => $e->getMessage()], 500); } } // --- Inhalt des Modals ---------------------------------------------------- $schluessel = preg_replace('/[^A-Za-z0-9_]/', '', strval($_GET["room"] ?? "")); $teile = explode("_", $schluessel, 2); $etage = $teile[0] ?? ""; $name = $teile[1] ?? ""; $raumKey = $etage . "/" . $name; // Hat der Raum ein Thermostat? Nur dann gibt es etwas zu heizen. $hatThermostat = false; foreach (allRooms() as $raum) { if ($raum["floor"] === $etage && $raum["mqtt"] === $name) { $hatThermostat = isset($raum["x"]); // Kachel = Thermostat vorhanden } } $katalog = deviceCatalog(); $geraete = array_values(array_filter($katalog, function ($d) use ($raumKey) { return $d["room"] === $raumKey && count($d["commands"]) > 0; })); $messwerte = array_values(array_filter($katalog, function ($d) use ($raumKey) { return $d["room"] === $raumKey && count($d["states"]) > 0 && count($d["commands"]) === 0; })); echo "
"; if ($hatThermostat) { echo "
"; echo ""; echo ""; echo "
" . "10 °C30 °C
"; echo "
"; } if (!$geraete && !$messwerte && !$hatThermostat) { echo "

Diesem Raum ist noch nichts zugeordnet. " . "Das geht über das Haus-Symbol in der Karte „Automatismen“.

"; } foreach ($geraete as $d) { echo "
"; echo "
" . htmlspecialchars($d["label"]) . " " . htmlspecialchars($d["type"]) . "
"; // Kommandos ohne Parameter werden Knoepfe nebeneinander - "Auf", "Zu", // "Stop" will man antippen und nicht erst einstellen. Die Reihenfolge in // der Datenbank ist die des Geraete-Suchlaufs und damit Zufall; die // haeufig gebrauchten kommen deshalb nach vorne. $knoepfe = array_values(array_filter($d["commands"], function ($c) { return !count($c["params"]); })); $vorne = ["Auf", "Zu", "Stop", "An", "Aus", "turn_on", "turn_off", "toggle"]; usort($knoepfe, function ($a, $b) use ($vorne) { $ia = array_search($a["name"], $vorne, true); $ib = array_search($b["name"], $vorne, true); $ia = $ia === false ? 99 : $ia; $ib = $ib === false ? 99 : $ib; return $ia === $ib ? strcoll($a["name"], $b["name"]) : $ia - $ib; }); if ($knoepfe) { echo "
"; foreach ($knoepfe as $c) { echo ""; } echo "
"; } foreach ($d["commands"] as $c) { if (!count($c["params"])) { continue; } echo "
"; echo "" . htmlspecialchars($c["name"]) . ""; foreach ($c["params"] as $p) { if (count($c["params"]) > 1) { echo "" . htmlspecialchars($p["name"]) . ""; } if ($p["options"]) { echo ""; } else { echo ""; } } echo ""; echo "
"; } echo "
"; } // Geraete ohne Kommandos: nur anzeigen, was sie melden. foreach ($messwerte as $d) { echo "
"; echo "
" . htmlspecialchars($d["label"]) . " " . htmlspecialchars($d["type"]) . "
"; echo "
"; $teile = []; foreach (array_slice($d["states"], 0, 8) as $s) { $teile[] = htmlspecialchars($s["name"]) . ": " . htmlspecialchars(strval($s["value"])) . ($s["unit"] ? " " . htmlspecialchars($s["unit"]) : ""); } echo implode(" · ", $teile); if (count($d["states"]) > 8) { echo " · … " . (count($d["states"]) - 8) . " weitere"; } echo "
"; } echo "
"; echo "
";