Bewaesserungs-Modal: Tagessummen aus WateringToday und LastWateringDay
Die Ventilsteuerung veroeffentlicht neuerdings je Steuerung zwei weitere Topics: WateringToday mit der heute schon gelaufenen Zeit je Ventil und LastWateringDay mit derselben Summe fuer den letzten Tag, an dem ueberhaupt bewaessert wurde. Beide tauchen als zweite Zeile in der Zonenkarte auf: "Heute 35m - Vortag 30m". WateringToday wird gegen das heutige Datum geprueft. Die Nachricht ist retained; nach einem Tageswechsel ohne Bewaesserung stuende sonst die Summe von gestern als heutige da. Passt der Tag nicht, zeigt die Karte "--" und nennt den Stand im Titel. Die Spalte heisst "Vortag" und nicht "Gestern", weil LastWateringDay einen eigenen wateringDay mitfuehrt - es ist der letzte Tag mit Bewaesserung, nicht zwangslaeufig der gestrige; das Datum steht im Titel. Geprueft: leeres Topic, Nutzlast mit 0 Sekunden, gefuellte Werte, veraltete Nutzlast, fehlendes Feld, kaputtes JSON, Datumsformat - zehn Faelle, keine Abweichung. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -129,7 +129,8 @@ foreach ($zonen as $zone) {
|
||||
<button type="button" class="btn btn-success px-4 ms-auto" data-watering-toggle data-watering-zone="$key">Ein</button>
|
||||
</div>
|
||||
<div class="small text-muted">
|
||||
Zuletzt <span data-watering-last="$key">--</span> · <span data-watering-duration="$key">--</span>
|
||||
Zuletzt <span data-watering-last="$key">--</span> · <span data-watering-duration="$key">--</span><br>
|
||||
Heute <span data-watering-today="$key">--</span> · Vortag <span data-watering-prevday="$key">--</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+32
-1
@@ -31,9 +31,13 @@ const solarMQTT = {
|
||||
client.subscribe("Gartenwasser/vorn/status");
|
||||
client.subscribe("Gartenwasser/vorn/Timers");
|
||||
client.subscribe("Gartenwasser/vorn/LastWatering");
|
||||
client.subscribe("Gartenwasser/vorn/WateringToday");
|
||||
client.subscribe("Gartenwasser/vorn/LastWateringDay");
|
||||
client.subscribe("Gartenwasser/hinten/status");
|
||||
client.subscribe("Gartenwasser/hinten/Timers");
|
||||
client.subscribe("Gartenwasser/hinten/LastWatering");
|
||||
client.subscribe("Gartenwasser/hinten/WateringToday");
|
||||
client.subscribe("Gartenwasser/hinten/LastWateringDay");
|
||||
client.subscribe("Gartenwasser/AutoWatering/#");
|
||||
});
|
||||
client.on("error", function (error) {
|
||||
@@ -65,7 +69,8 @@ const solarMQTT = {
|
||||
if (topic === "Gartenwasser/vorn/Timers" || topic === "Gartenwasser/hinten/Timers") {
|
||||
wateringTimersLastSeen[topic] = Date.now();
|
||||
}
|
||||
if (topic.startsWith("Gartenwasser/") && (topic.endsWith("/status") || topic.endsWith("/Timers") || topic.endsWith("/LastWatering") || topic.endsWith("/RainStatus"))) {
|
||||
if (topic.startsWith("Gartenwasser/") && (topic.endsWith("/status") || topic.endsWith("/Timers") || topic.endsWith("/LastWatering") || topic.endsWith("/RainStatus")
|
||||
|| topic.endsWith("/WateringToday") || topic.endsWith("/LastWateringDay"))) {
|
||||
updateWateringStatus();
|
||||
}
|
||||
if (topic == "solarManager/P_Load") {
|
||||
@@ -818,6 +823,28 @@ var chartSettings = {
|
||||
};
|
||||
}
|
||||
|
||||
// Tagesdatum im Format der Ventilsteuerung ("29.08.26").
|
||||
function wateringDayStamp(date) {
|
||||
const zwei = (zahl) => String(zahl).padStart(2, "0");
|
||||
return zwei(date.getDate()) + "." + zwei(date.getMonth() + 1) + "." + zwei(date.getFullYear() % 100);
|
||||
}
|
||||
|
||||
// Tagessummen der Ventilsteuerung: WateringToday fuer den laufenden Tag,
|
||||
// LastWateringDay fuer den letzten Tag, an dem ueberhaupt bewaessert wurde.
|
||||
// Beide Nutzlasten tragen den zugehoerigen Tag als "wateringDay" mit. Bei
|
||||
// WateringToday wird der geprueft - die Nachricht ist retained, nach einem
|
||||
// Tageswechsel ohne Bewaesserung stuende sonst die Summe von gestern als
|
||||
// "heute" in der Karte.
|
||||
function wateringDayTotal(topic, subTopic, feld, valve, mussHeuteSein) {
|
||||
const data = wateringJson(topic + "/" + subTopic);
|
||||
if (!data) return { label: "--", day: "" };
|
||||
const tag = data.wateringDay || "";
|
||||
const sekunden = data[feld + valve];
|
||||
if (sekunden === undefined) return { label: "--", day: tag };
|
||||
if (mussHeuteSein && tag !== wateringDayStamp(new Date())) return { label: "--", day: tag };
|
||||
return { label: wateringTimeLabel(Number(sekunden)), day: tag };
|
||||
}
|
||||
|
||||
function wateringAutoActive(topic, mode) {
|
||||
const timers = wateringJson(topic + "/Timers");
|
||||
return !!(timers && timers.auto === mode);
|
||||
@@ -973,6 +1000,10 @@ var chartSettings = {
|
||||
const history = wateringHistory(zone.topic, zone.valve);
|
||||
setzeZelle(`[data-watering-last='${key}']`, history.dateTime);
|
||||
setzeZelle(`[data-watering-duration='${key}']`, history.duration);
|
||||
const heute = wateringDayTotal(zone.topic, "WateringToday", "wateringDurationTodaySecs", zone.valve, true);
|
||||
const vortag = wateringDayTotal(zone.topic, "LastWateringDay", "wateringDurationDaySecs", zone.valve, false);
|
||||
setzeZelle(`[data-watering-today='${key}']`, heute.label, heute.day && "Stand: " + heute.day);
|
||||
setzeZelle(`[data-watering-prevday='${key}']`, vortag.label, vortag.day && "Bewässerungstag: " + vortag.day);
|
||||
const plan = wateringPlanText(zone.auto);
|
||||
setzeZelle(`[data-watering-plan='${key}']`, plan.text, plan.titel);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user