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
@@ -2,6 +2,7 @@
|
||||
|
||||
import { roomClimateValue } from "./devices.ts";
|
||||
import { powerSensorFor, readPower } from "./energy.ts";
|
||||
import { roomUtilityReadings } from "./utilities.ts";
|
||||
import { roomSun } from "./live/sun-hours.ts";
|
||||
import { comfortScore, isSummer, mouldRisk } from "./live/room-climate.ts";
|
||||
import { pointInPolygon, type Building, type Floor, type Room } from "./model.ts";
|
||||
@@ -93,7 +94,9 @@ export function heatColor(mode: HeatColorMode, value: number, summer = false): R
|
||||
* What the devices of a room draw now, in watts: the power sensors of its device pins and of its furniture (a piece's own power
|
||||
* sensor, else the one on its entity's device), each counted once. Null when the room has none. The house's meters stay out.
|
||||
*/
|
||||
export function roomPower(hass: HomeAssistant, building: Pick<Building, "energy">, floor: Floor, room: Room): number | null {
|
||||
export function roomPower(hass: HomeAssistant, building: Pick<Building, "energy"> & Partial<Pick<Building, "floors">>, floor: Floor, room: Room): number | null {
|
||||
const metered = roomUtilityReadings(hass, room, building.floors?.flatMap((f) => f.rooms) ?? floor.rooms).filter((r) => r.kind === "electricity" && r.metric === "power");
|
||||
if (metered.length) return metered.find((r) => r.unit === "W")?.value ?? null;
|
||||
let sum: number | null = null;
|
||||
for (const s of roomPowerSensors(hass, building, floor, room)) {
|
||||
const w = readPower(hass.states[s]);
|
||||
@@ -103,7 +106,9 @@ export function roomPower(hass: HomeAssistant, building: Pick<Building, "energy"
|
||||
}
|
||||
|
||||
/** The power sensors of a room's device pins and furniture, each once, without the house's meters. */
|
||||
export function roomPowerSensors(hass: HomeAssistant, building: Pick<Building, "energy">, floor: Floor, room: Room): string[] {
|
||||
export function roomPowerSensors(hass: HomeAssistant, building: Pick<Building, "energy"> & Partial<Pick<Building, "floors">>, floor: Floor, room: Room): string[] {
|
||||
const metered = roomUtilityReadings(hass, room, building.floors?.flatMap((f) => f.rooms) ?? floor.rooms).filter((r) => r.kind === "electricity" && r.metric === "power");
|
||||
if (metered.length) return metered.filter((r) => r.unit === "W").flatMap((r) => r.sources);
|
||||
const { grid, solar, battery } = building.energy;
|
||||
const meters = new Set([grid, solar, battery].filter(Boolean));
|
||||
const sensors = new Set<string>();
|
||||
|
||||
Reference in new issue
Block a user