feat: improve Symcon designer controls and KNX temperature selection
This commit is contained in:
1 parent
804f2d0494
commit
b934f78b9a
24 files changed
+908
-562
No files matched your search
@@ -209,6 +209,17 @@ export const primaryEntities = (hass: HomeAssistant, ids: readonly string[]): st
|
||||
export const CLIMATE_CLASSES = { temperature: "temperature", humidity: "humidity", co2: "carbon_dioxide" } as const;
|
||||
export type ClimateKey = keyof typeof CLIMATE_CLASSES;
|
||||
|
||||
/** Numeric room values, including Symcon readings whose legacy domain was inferred from a parent name. */
|
||||
export function isClimateValueSensor(hass: HomeAssistant, id: string, key: ClimateKey): boolean {
|
||||
const a = hass.states[id]?.attributes;
|
||||
if (!a) return false;
|
||||
const symconNumber = (a.symcon_variable_type === 1 || a.symcon_variable_type === 2) && typeof a.symcon_id === "number";
|
||||
if (!symconNumber && !/^(sensor|input_number|number)\./.test(id)) return false;
|
||||
const unit = String(a.unit_of_measurement ?? "").replace(/\s/g, "").toLowerCase();
|
||||
if (key === "temperature" && ["°c", "°f", "℃", "℉", "k"].includes(unit)) return true;
|
||||
return a.device_class === CLIMATE_CLASSES[key];
|
||||
}
|
||||
|
||||
/** A device with one of these domains is not a room sensor: a heat pump, a printer, a TV. */
|
||||
const APPLIANCE_DOMAINS = new Set(["climate", "water_heater", "switch", "button", "camera", "media_player", "vacuum", "light", "fan", "lawn_mower"]);
|
||||
/** Words in a name (English and German) that mark a temperature that is not the room's: pipes, printers, chips, outdoors, cold appliances. */
|
||||
@@ -245,14 +256,15 @@ export function roomClimateSensors(hass: HomeAssistant, floor: Floor | null, roo
|
||||
const inside = placedSensors.filter((p) => pointInPolygon([p.x, p.z], room.points)).map((p) => p.entity_id);
|
||||
const insideElsewhere = new Set(placedSensors.filter((p) => !pointInPolygon([p.x, p.z], room.points)).map((p) => p.entity_id));
|
||||
const candidates = new Set([...roomEntities(hass, room).filter((id) => !insideElsewhere.has(id)), ...inside]);
|
||||
return [...candidates].filter((id) => id.startsWith("sensor.") && hass.states[id]?.attributes.device_class === CLIMATE_CLASSES[key] && isRoomClimateSensor(hass, id));
|
||||
return [...candidates].filter((id) => id.startsWith("sensor.") && isClimateValueSensor(hass, id, key) && isRoomClimateSensor(hass, id));
|
||||
}
|
||||
|
||||
/** The average of the room's sensors, or null when none reports. Temperatures are always °C, whatever the sensor's unit. */
|
||||
export function roomClimateValue(hass: HomeAssistant, floor: Floor | null, room: Room, key: ClimateKey): number | null {
|
||||
const readings = roomClimateSensors(hass, floor, room, key)
|
||||
.map((id) => {
|
||||
const reading = Number(hass.states[id]?.state);
|
||||
const state = hass.states[id];
|
||||
const reading = Number(state?.attributes.symcon_numeric_value ?? state?.state);
|
||||
return key === "temperature" ? toCelsius(reading, hass.states[id]?.attributes.unit_of_measurement) : reading;
|
||||
})
|
||||
.filter(Number.isFinite);
|
||||
|
||||
Reference in new issue
Block a user