feat: discover Symcon room utility meters and sum floor consumption
This commit is contained in:
1 parent
18e73194e0
commit
a804fc8e15
27 files changed
+2504
-1874
No files matched your search
@@ -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
|
||||
|
||||
@@ -10,6 +10,8 @@ import { pluginRoomSections } from "../plugins/registry.ts";
|
||||
import { canAnnounce, roomHasSpeaker } from "../live/announce.ts";
|
||||
import { isSymcon, nativeText } from "../entities/symcon-values.ts";
|
||||
import "./room-hvac.ts";
|
||||
import "./utility-report.ts";
|
||||
import { roomUtilityReadings } from "../utilities.ts";
|
||||
import type { Building, Floor, LightMood, LightSetting, Room } from "../model.ts";
|
||||
import { roomPower, roomPowerSensors } from "../heatmap.ts";
|
||||
import { energyCost, loadRoomEnergy, type RoomEnergy } from "../live/room-energy.ts";
|
||||
@@ -209,6 +211,7 @@ export class NfRoomPanel extends LitElement {
|
||||
|
||||
private async loadEnergy(room: Room): Promise<void> {
|
||||
if (!this.floor || !this.building) return;
|
||||
if (isSymcon(this.hass)) { this._energy = null; return; }
|
||||
const ids = roomPowerSensors(this.hass, this.building, this.floor, room);
|
||||
try {
|
||||
const energy = await loadRoomEnergy(this.hass, ids);
|
||||
@@ -482,6 +485,7 @@ export class NfRoomPanel extends LitElement {
|
||||
</button>
|
||||
</header>
|
||||
<div class="nf-rp-body" ?hidden=${this._folded}>
|
||||
<nf-utility-report .hass=${this.hass} .readings=${roomUtilityReadings(this.hass, room, this.building?.floors.flatMap((f) => f.rooms))}></nf-utility-report>
|
||||
${this.renderAllOff([...lights, ...media, ...switches])}
|
||||
${this.renderClean(room)}
|
||||
${!room.area_id && !outside && !(isSymcon(this.hass) && hvacRefs.length)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { UTILITY_KINDS } from "../model.ts";
|
||||
import type { HomeAssistant } from "../types.ts";
|
||||
import { UTILITY_ICONS, UTILITY_LABELS, utilityMetricLabel, utilityText, type UtilityReading } from "../utilities.ts";
|
||||
|
||||
/** The same metered readings in the room panel and the floor overview. */
|
||||
class NfUtilityReport extends LitElement {
|
||||
static properties = { hass: { attribute: false }, readings: { attribute: false } };
|
||||
declare hass: HomeAssistant;
|
||||
declare readings: UtilityReading[];
|
||||
|
||||
constructor() { super(); this.readings = []; }
|
||||
|
||||
render() {
|
||||
return html`${UTILITY_KINDS.filter((kind) => this.readings.some((r) => r.kind === kind)).map((kind) => html`<section aria-label=${UTILITY_LABELS[kind]}>
|
||||
<h4>${UTILITY_ICONS[kind]} ${UTILITY_LABELS[kind]}</h4>
|
||||
${this.readings.filter((r) => r.kind === kind).map((r) => html`<div class="reading" title=${`${r.manual ? "Stockwerkszähler" : "Bereichszähler"}${r.incomplete ? " · Wert nicht verfügbar" : ""}\n${r.sources.map((id) => this.hass.states[id]?.attributes.symcon_path || this.hass.states[id]?.attributes.friendly_name || id).join("\n")}`}>
|
||||
<span>${utilityMetricLabel(r)}${r.manual ? html` <small>· Zähler</small>` : ""}</span><b>${utilityText(this.hass, r)}</b>
|
||||
</div>`)}
|
||||
</section>`)}`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host { display:block; color:var(--nf-text); font:inherit; }
|
||||
section { padding:10px 0; border-bottom:1px solid var(--nf-line,#ffffff20); }
|
||||
section:last-child { border:0; }
|
||||
h4 { font:inherit; font-weight:600; margin:0 0 6px; }
|
||||
.reading { display:flex; justify-content:space-between; gap:16px; margin:4px 0; }
|
||||
.reading span { color:var(--nf-muted,#aaa); }
|
||||
b { white-space:nowrap; font-variant-numeric:tabular-nums; }
|
||||
small { font-size:.85em; }
|
||||
`;
|
||||
}
|
||||
if (!customElements.get("nf-utility-report")) customElements.define("nf-utility-report", NfUtilityReport);
|
||||
@@ -52,6 +52,8 @@ import { fixtureGlow } from "../entities/kinds.ts";
|
||||
import { coverTiltEntity } from "../entities/covers.ts";
|
||||
import { isSymcon, isSymconVariable, nativeBool, nativeText } from "../entities/symcon-values.ts";
|
||||
import { WEATHER_VARIABLE_LABELS } from "../symcon-weather.ts";
|
||||
import { floorUtilityReadings } from "../utilities.ts";
|
||||
import "./utility-report.ts";
|
||||
import { deviceValuesText } from "../entities/device-values.ts";
|
||||
import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts";
|
||||
import { pictureUrl } from "../entities/pictures.ts";
|
||||
@@ -2598,7 +2600,7 @@ export class NfView3d extends LitElement {
|
||||
const hass = this.hass;
|
||||
const rows: { icon: string; label: string; value: string }[] = [];
|
||||
const floor = this.floorId ? b.floors.find((f) => f.id === this.floorId) : undefined;
|
||||
const floorPower = floor?.power_entity ? readPower(hass?.states[floor.power_entity]) : null;
|
||||
const floorPower = floor && isSymcon(hass) ? floorUtilityReadings(hass, floor, b.floors.flatMap((f) => f.rooms)).find((r) => r.kind === "electricity" && r.metric === "power" && r.unit === "W")?.value ?? null : floor?.power_entity ? readPower(hass?.states[floor.power_entity]) : null;
|
||||
if (floor && floorPower !== null) {
|
||||
const share = consumption && consumption > 0 ? ` · ${translate(hass, "floor_power_share", { n: Math.round((Math.max(0, floorPower) / consumption) * 100) })}` : "";
|
||||
rows.push({ icon: "⚡", label: floor.name, value: `${powerText(hass, floorPower)}${share}` });
|
||||
@@ -2749,7 +2751,10 @@ export class NfView3d extends LitElement {
|
||||
if (isSymcon(this.hass) && this.building?.settings.rain_sensor && this.building.settings.rain_sensor !== "none") weather.push(["Regensensor", this.building.settings.rain_sensor]);
|
||||
const weatherValues = weather.length ? html`<button class="nf-energy-item nf-flow-toggle nf-weather-values" aria-label="Wetterwerte anzeigen" title="Wetterwerte anzeigen" aria-haspopup="dialog" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-weather-dialog")?.showModal()}><span>Wetter</span><b aria-hidden="true">⛅</b></button>
|
||||
<dialog class="nf-weather-dialog" aria-label="Wetterwerte" @keydown=${(event: KeyboardEvent) => event.stopPropagation()}><header><b>Wetter</b><button type="button" class="nf-chip" aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-weather-dialog")?.close()}>×</button></header>${weather.map(([label, id]) => html`<p><span>${label}</span><b>${nativeText(this.hass.states[id])}</b></p>`)}</dialog>` : nothing;
|
||||
return [...people, weatherValues, ...ids
|
||||
const floors = isSymcon(this.hass) ? (this.building?.floors ?? []).filter((f) => !this.floorId || f.id === this.floorId).map((f) => ({ floor: f, readings: floorUtilityReadings(this.hass, f, this.building?.floors.flatMap((x) => x.rooms)) })).filter((f) => f.readings.length) : [];
|
||||
const utilities = floors.length ? html`<button class="nf-energy-item nf-flow-toggle nf-utility-toggle" aria-label="Stockwerkszähler anzeigen" title="Stockwerkszähler anzeigen" aria-haspopup="dialog" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-utility-dialog")?.showModal()}><span>Stockwerkszähler</span><b aria-hidden="true">⚡ 💧</b></button>
|
||||
<dialog class="nf-weather-dialog nf-utility-dialog" aria-label="Stockwerkszähler" @keydown=${(event: KeyboardEvent) => event.stopPropagation()}><header><b>Stockwerkszähler</b><button type="button" class="nf-chip" aria-label="Schließen" @click=${() => this.renderRoot.querySelector<HTMLDialogElement>(".nf-utility-dialog")?.close()}>×</button></header>${floors.map(({ floor, readings }) => html`<h3>${floor.name}</h3><nf-utility-report .hass=${this.hass} .readings=${readings}></nf-utility-report>`)}</dialog>` : nothing;
|
||||
return [...people, weatherValues, utilities, ...ids
|
||||
.filter((id) => this.hass.states[id])
|
||||
.map(
|
||||
(id) => html`<button class="nf-energy-item nf-own-sensor" title=${entityName(this.hass, id)} @click=${() => openMoreInfo(this, id)}>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { parkingEntities } from "../../parking.ts";
|
||||
import { pluginWatched } from "../../plugins/registry.ts";
|
||||
import type { HomeAssistant } from "../../types.ts";
|
||||
import { weatherEntity } from "../../weather.ts";
|
||||
import { utilityWatched } from "../../utilities.ts";
|
||||
|
||||
export interface WatchInputs {
|
||||
hass: HomeAssistant;
|
||||
@@ -64,6 +65,7 @@ export function watchedEntities(inputs: WatchInputs): string[] {
|
||||
: []));
|
||||
const ids: MaybeId[] = [
|
||||
...placed,
|
||||
...utilityWatched(hass, b.floors),
|
||||
...b.floors.flatMap((f) => f.placements.flatMap((p) => [p.cover_tilt, p.position, ...(p.values ?? []).map((v) => v.entity)])),
|
||||
...openingIds(inputs.openingLinks),
|
||||
...placed.map((id) => powerSensorFor(hass, id)),
|
||||
|
||||
Reference in new issue
Block a user