feat: discover Symcon room utility meters and sum floor consumption

This commit is contained in:
jhartworks committed 2026-11-11 09:55:26 +01:00
1 parent 18e73194e0
commit a804fc8e15
27 files changed
+2504 -1874

No files matched your search

+21 -3
View File
@@ -1,7 +1,10 @@
// The side panel's floor part: the floors of the house as chips, and the form of the selected floor.
import { html, nothing, type TemplateResult } from "lit";
import { DEFAULT_PAINT_OUTSIDE, type Floor } from "../../../model.ts";
import { DEFAULT_PAINT_OUTSIDE, UTILITY_KINDS, type Floor } from "../../../model.ts";
import { isSymcon, isSymconVariable } from "../../../entities/symcon-values.ts";
import { floorMeter, floorUtilityReadings, UTILITY_ICONS, UTILITY_LABELS } from "../../../utilities.ts";
import "../../utility-report.ts";
import type { HassFloor } from "../../../types.ts";
import { checkField, colorField, entityField, hint, numberField, selectField, textField } from "../fields.ts";
import { entityOptions } from "../entities.ts";
@@ -93,6 +96,22 @@ function copyChoices(host: EditorHost, state: SideState, floorActions: FloorActi
</div>`;
}
function utilityMeters(host: EditorHost, floor: Floor): TemplateResult {
const options = entityOptions(host.hass, (id) => isSymconVariable(host.hass, id, [1, 2]));
return html`<details class="nf-wide nf-utility-meters"><summary>Stockwerkszähler</summary><div class="nf-form">
${hint("Ohne eigenen Stockwerkszähler werden die Bereichszähler der Räume summiert. In der verknüpften Bereichskategorie werden Kategorien oder Dummy-Module namens Elektro/Strom, Wasser, Gas, Heizen und Kühlen durchsucht. Darin werden Leistung bzw. Durchfluss und Verbrauch bzw. Energie erkannt. Ein eigener Stockwerkszähler ersetzt nur die zugehörige Raumsumme. × stellt die automatische Raumsumme wieder her. Einheiten und Verbrauchszeiträume werden getrennt ausgewertet.", "nf-wide")}
${UTILITY_KINDS.map((kind) => html`<b class="nf-wide">${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}</b>${(["power", "energy"] as const).map((metric) => html`<label class="nf-field nf-wide">${metric === "power" ? "Leistung / Durchfluss" : "Energie / Verbrauch"}
<nf-entity-picker .options=${options} .objectTree=${host.hass?.symconObjects} .fixed=${[{ id: "__auto", label: "Raumsumme (automatisch)" }]} .value=${floorMeter(host.hass!, floor, kind, metric) ?? "__auto"} ?disabled=${!host.admin}
@change=${(e: CustomEvent<{ value: string | null }>) => {
e.stopPropagation();
const value = e.detail.value;
host.change((_, f) => { f.utility_meters = { ...f.utility_meters, [kind]: { ...f.utility_meters?.[kind], [metric]: value && value !== "__auto" && value !== "none" ? value : null } }; });
}}></nf-entity-picker>
</label>`)}`)}
<nf-utility-report class="nf-wide" .hass=${host.hass} .readings=${floorUtilityReadings(host.hass!, floor, host.doc.floors.flatMap((f) => f.rooms))}></nf-utility-report>
</div></details>`;
}
function floorForm(host: EditorHost, state: SideState, floorActions: FloorActions, floor: Floor): TemplateResult {
const t = host.t;
const update = (patch: Partial<Floor>) => host.change((_, f) => Object.assign(f, patch));
@@ -106,8 +125,7 @@ function floorForm(host: EditorHost, state: SideState, floorActions: FloorAction
${numberField(host, t("height"), floor.height, (v) => update({ height: Math.max(1, v) }), 0.05, 1)}
${Object.keys(host.hass?.floors ?? {}).length > 0 ? selectField(host, t("ha_floor"), floor.ha_floor ?? "", haChoices, (v) => update({ ha_floor: v || null }), { wide: true }) : nothing}
${checkField(host, t("floor_layer"), !!floor.layer, (on) => update({ layer: on || undefined }), { title: t("floor_layer_hint") })}
${entityField(host, t("floor_power"), floor.power_entity ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("sensor.") && host.hass?.states[id]?.attributes.device_class === "power"), (v) => update({ power_entity: v && v !== "none" ? v : null }))}
${floor.power_entity ? hint(t("floor_power_hint"), "nf-wide") : nothing}
${isSymcon(host.hass) ? utilityMeters(host, floor) : html`${entityField(host, t("floor_power"), floor.power_entity ?? null, undefined, entityOptions(host.hass, (id) => id.startsWith("sensor.") && host.hass?.states[id]?.attributes.device_class === "power"), (v) => update({ power_entity: v && v !== "none" ? v : null }))}${floor.power_entity ? hint(t("floor_power_hint"), "nf-wide") : nothing}`}
${floor.layer ? nothing : colorField(host, t("wall_paint_floor"), floor.wall_paint_outside, host.doc.settings.wall_paint_outside ?? DEFAULT_PAINT_OUTSIDE, (v) => update({ wall_paint_outside: v }))}
${areaRow(host, floor, floorActions)}
${host.admin && lacking.length > 0