import { ALL_TOPOLOGY, floorSelection, topologyFloors, topologyItems, type TopologySelection } from "../topology.ts"; import { topologyNavigation } from "./view3d/topology-navigation.ts"; // Lit wrapper around the lazily loaded 3D viewer. import { changeMoments, hassAt, loadHistory, replayable, type History } from "../live/time-travel.ts"; import { canControl } from "../access.ts"; import { sunPosition, todayAt } from "../sun-position.ts"; import { dayCurves, statesRead, type DayCurves } from "../live/day-curves.ts"; import { backdropStyle } from "../backdrop.ts"; import { css, html, LitElement, nothing, svg, type PropertyValues } from "lit"; import { type CarState, roomClimateValue, entityName, furnitureEntities, isActive, isCooling, isMotionSensor, coverReaches, deviceSiblings, hasPost, minutesText, pickupDays, plantThirst, remainingMinutes, gangGlows, gangEntities, isUnavailable, kindOf, markerKind, type MarkerKind, lightGlow, openingEntities, openingState, isUnlocked, TOGGLE_KINDS, type FurnitureLinks, type OpeningEntities, confirmEntities, coolingTemps, deviceTempOf, DEVICE_HOT, fridgeDoors, hasScreen, fromCelsius, toCelsius, tempUnit, robotRoom, robotRoomSensor, isStatusSensor, floorControls, favoriteCall, runButton, ownButtonOn, roomEntities } from "../devices.ts"; import { liveScreens, liveSprays, readSun, roofWindowStates, skyLightness } from "./view3d/live-inputs.ts"; import { watchedEntities } from "./view3d/watch-list.ts"; import { roomToggleLights, roomToggleMode, type RoomToggle } from "./view3d/room-toggle.ts"; import { ownTaps } from "./view3d/own-taps.ts"; import { lightAnimation, lightEffectSource } from "../light-effects.ts"; import type { PlacementInfo } from "../plugins/api.ts"; import { onPluginsChanged, pluginTap } from "../plugins/registry.ts"; import { alertColor, alertSources, alertText, contactsPending, findAlerts, QUIET_ALERTS, type Alert, type AlertSources } from "../alerts.ts"; import { iconPath, iconSvg, mdiIcon } from "../icons.ts"; import { deviceSensors, energySummary, findConsumers, powerSensorFor, readPower, subMeterIds, subMeterLabel, type Consumer, type EnergySummary } from "../energy.ts"; import { mapCredit, mapShown } from "../map-geo.ts"; import { type CustomButton, type EntityRef } from "../model.ts"; import { STAGE, type Theme } from "../themes.ts"; import { heatColor, heatGradient, roomValues, scaleOf, type HeatMode } from "../heatmap.ts"; import { airingNeed, isSummer, mouldRisk } from "../live/room-climate.ts"; import { furnitureName } from "../furniture-names.ts"; import { formatNumber, translate, type I18nKey } from "../i18n.ts"; import { getPacks, hasMovingParts, householdKind, mountBase, packItem, packsVersion } from "../packs.ts"; import { parkedVehicle, parkedVehicles, vehicleFurniture } from "../parking.ts"; import { gateStates } from "../entities/gates.ts"; import { weatherEntity } from "../weather.ts"; import { chosenEffects, readSkyWeather, withDensity } from "../live/sky-weather.ts"; import { energyPicture, houseHub, type EnergyPicture } from "../live/energy-flow.ts"; import { roomClimateCards } from "../live/room-climate-card.ts"; import { furniturePowerCards } from "../live/furniture-power-card.ts"; import { isHydronic } from "../hydronic-model.ts"; import { loadHydronics } from "../load-hydronics.ts"; import { loadWeek, type WeekBars } from "../live/week-bars.ts"; import { binsDue, loadToday, sortDay, type TodayItem } from "../live/today.ts"; import { forecastDays, loadForecast } from "../live/forecast.ts"; import { isPrinter3d, readPrinter, type PrinterInfo } from "../live/printer.ts"; import { isHeatPump, readHeatPump, type HeatPumpInfo } from "../live/heat-pump.ts"; import { coverageColor, isAccessPoint, networkHealth, readAccessPoint } from "../live/wifi.ts"; import type { FurnitureColors } from "../furniture-colors.ts"; import { renderLhCards, liveCardStyles, unstackLhCards, type LiveCard } from "../live/cards.ts"; import { cardDetail, cardVisibleAtZoom } from "../live/card-visibility.ts"; import { readCar, type CarInfo } from "../live/car.ts"; import { mediaNow, multiroom, type MediaNow } from "../live/media.ts"; import { SHOW_PRESENCE } from "../flags.ts"; import { searchIndex, searchItems, type SearchItem } from "../search.ts"; import { coverPositionable, lightAbilities } from "./quick-menu.ts"; import "./quick-menu.ts"; import { load3d } from "../load3d.ts"; import { scaleGlow, buildMarkers, openMoreInfo, stateText, toggleEntity, withPluginPatch } from "../markers.ts"; import { fanSpin } from "../entities/fans.ts"; 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 { floorUtilityAreas, floorUtilityReadings, utilityText } from "../utilities.ts"; import "./utility-report.ts"; import "./utility-overview.ts"; import { trendButton } from "./trend-button.ts"; import { deviceValuesText } from "../entities/device-values.ts"; import { furnitureShown, hiddenFurniture, withoutHidden } from "../entities/visibility.ts"; import { pictureUrl } from "../entities/pictures.ts"; import { fetchImage } from "../api.ts"; import { ceilingOf, centroid, furnitureFootprint, groundLevel, isLamp, LAMP_MODEL, outdoorGround, outdoorTopAt, pointInPolygon, polygonArea, surfaceHeight, type Building, type Furniture, type Placement, type StartView } from "../model.ts"; import { floorCounts, floorInfoText, personsInRooms, powerText } from "../presence.ts"; import { controls, tokens } from "../styles.ts"; import type { HassEntity, HomeAssistant } from "../types.ts"; import { claim, forThisScreen, playAnnouncement, showFor, subscribeAnnouncements, type Announcement } from "../live/announce.ts"; import { mapCamera, readVacuum } from "../live/vacuum-map.ts"; import type { DeviceMarker, LivePictureInput, NextFloorViewer, FloorStack, RobotInfo, Quality, ScreenState, SurfaceGrab, ViewerStats, WallMode } from "../viewer/viewer3d.ts"; /** Which HTML markers are shown: none, only what has no 3D object or shows a value, or all. */ export type MarkerMode = "none" | "important" | "all"; /** Where the clock sits in the view. */ export type ClockCorner = "top_left" | "top_right" | "bottom_left" | "bottom_right"; const LOCK_KEY = "nextfloor.lock3d"; /** Below this stage height (px) the floor pictures get small and stop above the buttons at the bottom. */ const SHORT_STAGE = 520; export class NfView3d extends LitElement { static properties = { hass: { attribute: false }, building: { attribute: false }, floorId: { attribute: false }, roomId: { attribute: false }, wallMode: { attribute: false }, solidWalls: { attribute: false }, glassWalls: { attribute: false }, explode: { type: Boolean }, keepRoof: { attribute: false }, markerMode: { attribute: false }, markerNames: { attribute: false }, markersOutside: { attribute: false }, tapInRoom: { type: Boolean }, roomDoubleTap: { attribute: false }, heatMode: { attribute: false }, theme: { attribute: false }, accent: { attribute: false }, furnitureColors: { attribute: false }, packs: { attribute: false }, showEnergy: { attribute: false }, flows: { attribute: false }, holograms: { attribute: false }, furnish: { type: Boolean }, surfaceGrab: { attribute: false }, furnishTypes: { attribute: false }, weather: { type: Boolean }, weatherEntityId: { attribute: false }, weatherDensity: { attribute: false }, timeOfDay: { attribute: false }, selectedFurniture: { attribute: false }, selectedDevice: { attribute: false }, _sky: { state: true }, quality: { attribute: false }, showStats: { type: Boolean }, _stats: { state: true }, _error: { state: true }, _energy: { state: true }, _flows: { state: true }, _liveEnergy: { state: true }, _liveCards: { state: true }, _liveCardOn: { state: true }, _houseFolded: { state: true }, _utilityOverviewVisible: { state: true }, _swipe: { state: true }, _menu: { state: true }, _pluginWindow: { state: true }, _plate: { state: true }, _blend: { state: true }, _wallBig: { state: true }, _find: { state: true }, _central: { state: true }, _thumbsCompact: { state: true }, _armed: { state: true }, central: { attribute: false }, centralOpen: { attribute: false }, keepCamera: { attribute: false }, plain: { attribute: false }, rightBack: { attribute: false }, templateName: { attribute: false }, readable: { type: Boolean, reflect: true }, today: { attribute: false }, _todayOpen: { state: true }, _todayItems: { state: true }, _forecast: { state: true }, zoom: { attribute: false }, buttons: { attribute: false }, _thumbs: { state: true }, floorThumbs: { attribute: false }, topologySelection: { attribute: false }, clean: { attribute: false }, cleanButton: { attribute: false }, clock: { attribute: false }, lockButton: { attribute: false }, walkButton: { attribute: false }, travelButton: { attribute: false }, _travel: { state: true }, _walking: { state: true }, _stick: { state: true }, _locked: { state: true }, _now: { state: true }, roomLabels: { attribute: false }, roomNamesButton: { attribute: false }, floorStack: { attribute: false }, panelOpen: { attribute: false }, alerts: { attribute: false }, alertJump: { attribute: false }, scenes: { attribute: false }, announcements: { attribute: false }, sensorBar: { attribute: false }, screenName: { attribute: false }, _announcement: { state: true }, dimmed: { attribute: false }, autoOrbit: { attribute: false }, startView: { attribute: false }, outsideOpen: { attribute: false }, _low: { state: true }, _narrowStage: { state: true }, _shortStage: { state: true }, _phoneStage: { state: true }, _alerts: { state: true }, _sceneFired: { state: true }, }; declare hass: HomeAssistant; /** This view is a screen announcements show and speak on (the panel's 3D view and cards, not the editor's). */ declare announcements: boolean; /** The plan's own sensors at the top (cards can switch them off). */ declare sensorBar: boolean; /** The name of this screen, for announcements meant for some screens only. */ declare screenName: string | null; /** The announcement on screen now, and when it goes. */ private declare _announcement: { message: string; until: number } | null; private stopAnnouncements: (() => void) | null = null; private announceTimer: ReturnType | undefined; declare building: Building | null; declare floorId: string | null; declare roomId: string | null; declare wallMode: WallMode; /** Solid walls in their paint instead of glass. */ declare solidWalls: boolean; /** How opaque the see-through walls are in % (null: the usual 20 %). */ declare glassWalls: number | null; declare explode: boolean; /** The roof stays while zooming in (no lift, no fade). */ declare keepRoof: boolean; declare markerMode: MarkerMode; /** Card option marker_names: every device with an own name shows it under its pin. */ declare markerNames: boolean; /** Card option markers_outside: outside the opened room only these kinds of markers show (null: as in the room). */ declare markersOutside: MarkerKind[] | null; /** Card option tap_in_room: a tap switches a device only in the opened room, elsewhere it opens the floor or room. */ declare tapInRoom: boolean; /** Card option room_double_tap: what a double tap on a room switches (auto = the plan setting). */ declare roomDoubleTap: RoomToggle | "auto"; declare heatMode: HeatMode; /** Imported furniture packs (a new list rebuilds pack furniture). */ declare packs: unknown; declare theme: Theme; /** Accent colour for the neon look ("#rrggbb"), null for the stock cyan. */ declare accent: string | null; /** The card's own furniture colours, on top of the house-wide ones (#82). */ declare furnitureColors: FurnitureColors | null; /** Show the energy values at the top (cards can switch them off). */ declare showEnergy: boolean; /** Power flow lines fixed on or off (cards); null: the viewer's own toggle decides. */ declare flows: boolean | null; /** The live cards (house, car, media) always on or off (card option "holograms"); null = the bar's own switch. */ declare holograms: boolean | null; private get liveCardsOn(): boolean { return this.holograms ?? this._liveCardOn; } /** Furnishing: furniture and lamps are dragged in 3D (admins, panel only). */ declare furnish: boolean; /** Editor: moves solar fields and roof windows with rays from the camera (null: none). */ declare surfaceGrab: SurfaceGrab | null; /** Editor: only these furniture types can be moved in 3D (null: all). */ declare furnishTypes: readonly string[] | null; /** Weather outside: rain, snow, fog and clouds from a weather entity, sun and moon from sun.sun. */ declare weather: boolean; /** The weather entity to use (null: the first one). */ declare weatherEntityId: string | null; /** How much of the rain, hail and snow falls (1: all of it). */ declare weatherDensity: number; /** Hours of today whose sun the view shows instead of the real one (the time-of-day slider); null: the real sun. */ declare timeOfDay: number | null; /** A lightning flash lights the stage for a moment. */ private cloud = 0; /** Entities that ask before a tap switches them. */ private confirmSet = new Set(); declare selectedFurniture: string | null; declare selectedDevice: string | null; /** How much daylight there is (0 = night, 1 = day), from sun.sun. */ private declare _sky: number; declare quality: Quality; declare showStats: boolean; private declare _stats: ViewerStats | null; private declare _error: string | null; private declare _energy: EnergySummary | null; /** The start view last handed to the viewer (JSON), to notice a new one. */ private shownStartView: string | undefined; /** A running swipe on a lamp or blind: the value shown next to the finger. */ private declare _swipe: { entity: string; kind: "light" | "cover" | "fan"; start: number; value: number; x: number; y: number } | null; /** Quick menu at a device (long press). */ private declare _menu: { entity: string; x: number; y: number; car?: CarState } | null; /** A window a plugin opened in the lower right corner (a camera's live picture). */ private declare _pluginWindow: { node: Node; title: string } | null; /** Where each placed device stands, for plugins that handle its taps. */ private placementInfo = new Map(); /** The buttons of a tapped switch plate or socket to pick from. */ private declare _plate: { ids: string[]; x: number; y: number } | null; /** Looking through a camera: its live picture lies over the 3D view; `back` is the view to return to. */ /** Camera wall: the camera shown big (null: all tiles). */ private declare _wallBig: string | null; /** The look-through was started from the camera wall: going back reopens the wall. */ /** Camera wall, big picture: Home Assistant's own stream player (a picture-entity card in live view), one at a time. */ private live: { id: string; el: (HTMLElement & { hass?: unknown }) | null; failed: boolean } | null = null; /** How strongly the camera picture covers the 3D view (0 = only 3D, 1 = only the picture). */ private declare _blend: number; /** Floor switcher with small pictures of the floors (panel and card; off with a fixed floor). */ declare floorThumbs: boolean; declare topologySelection: TopologySelection | null; private topologyImages = new Map(); private scopedFor: {source:Building;key:string;plan:Building}|null=null; /** Clean view: only the stage – no energy values, thumbnails, legend, scene chips or search (the host hides its own bars). */ declare clean: boolean; /** Show the eye button that toggles the clean view (the host listens for "clean-toggle"). */ declare cleanButton: boolean; /** A clock in a corner of the view (null: none). */ declare clock: ClockCorner | null; /** Show the 🔒 button that locks the camera (a wall tablet nobody should turn by accident). */ declare lockButton: boolean; /** Show the 🚶 button that walks through the house at eye level. */ declare walkButton: boolean; /** Show the ⏪ button that replays the last day or week. */ declare travelButton: boolean; /** Time travel: the loaded history, its span, the moment shown, and whether it plays (null: live). */ private declare _travel: { history: History; from: number; to: number; t: number; playing: boolean; speed: number; hours: number; moments: number[]; loading: boolean } | null; private travelTimer: ReturnType | undefined; /** The house card's day curves and when they were last loaded. */ private dayCurves: DayCurves | null = null; private curvesAt = 0; private declare _walking: boolean; /** Where the touch stick's knob is (-1 … 1 each way) while a finger holds it. */ private declare _stick: [number, number] | null; /** The camera is locked on this device. */ private declare _locked: boolean; /** The time the clock shows, refreshed every few seconds while a clock is shown. */ private declare _now: number; private clockTimer: ReturnType | undefined; /** Room names in 3D (cards can switch them off). */ declare roomLabels: boolean; /** Cards expose the room-name switch in their own 3D top bar. The designer has its toolbar switch. */ declare roomNamesButton: boolean; /** Floors below an opened floor: dimmed, stacked (the house up to it) or hidden. */ declare floorStack: FloorStack; private declare _thumbs: { floorId: string; url: string }[]; /** The viewer runs at the tablet level: heavy CSS effects are left out as well. */ private declare _low: boolean; /** A room panel (or sheet) is open next to the view: on small screens the view's own controls hide. */ declare panelOpen: boolean; /** The stage is narrower than 700 px (smaller floor pictures, phone layout). */ private declare _narrowStage: boolean; /** The stage is low (a small card): the floor pictures leave room for the buttons below them. */ private declare _shortStage: boolean; /** The stage is as narrow as a phone held upright: the floor pictures step aside, the floor tabs above do the job (#70). */ private declare _phoneStage: boolean; private stopPlugins: (() => void) | null = null; private pluginsDirty = false; private resizeObs: ResizeObserver | null = null; /** Warnings (smoke, water, alarm, window in the rain): pulsing rooms and a banner; jump to new ones. */ declare alerts: boolean; declare alertJump: boolean; private declare _alerts: Alert[]; private alertSrc: AlertSources | null = null; private alertTimer: ReturnType | undefined; /** Looks again at contacts that went unavailable, until their grace time has passed. */ private contactTimer: ReturnType | undefined; private seenAlerts = new Set(); /** A room briefly lit up after a double tap switched its lights. */ private roomFlash: { roomId: string; until: number } | null = null; /** Scene and script chips of the selected room. */ declare scenes: boolean; private declare _sceneFired: string | null; /** Night (kiosk): no effects, cables or floor pictures. */ declare dimmed: boolean; /** Screensaver: the view turns slowly by itself. */ declare autoOrbit: boolean; /** A start view of the card's own (YAML `start_view`); else the one remembered in the editor. */ declare startView: StartView | null; /** Outside is open: the camera flies to Outside's own view, if the plan has one (#83). */ declare outsideOpen: boolean; /** Search index (rooms and devices), built when the search opens and reused while it is open. */ private findIndex: SearchItem[] | null = null; /** Room colours (heatmap) as last sent to the viewer. */ private tintSig = ""; private thumbTimer: ReturnType | undefined; /** What the floor pictures show of the devices (lamps, blinds): they are drawn again when it changes. */ private thumbSig = ""; private thumbsAt = 0; /** Search ("where is …?"): null = closed. */ private declare _find: string | null; /** Floor pictures folded to plain floor buttons (D177), remembered per device. */ private declare _thumbsCompact: boolean; /** The central menu (all lights / blinds of the floor or house, favourites) is open (#145). */ private declare _central: boolean; /** A house-wide action waiting for its second tap ("sure?"), with the time it was armed. */ private declare _armed: string | null; private armTimer: ReturnType | undefined; /** Show the star with the central menu (card option central; default on). */ declare central: boolean; /** The star menu stands open from the start, a size larger (a wall tablet whose main use are its favourites). */ declare centralOpen: boolean; /** Switching floors keeps the camera's side, height and distance. */ declare keepCamera: boolean; /** Only the floor plan: no furniture in 3D. */ declare plain: boolean; /** A short right click goes back one step. */ declare rightBack: boolean; /** The card template this card uses (for "reload the screens of this template"). */ declare templateName: string | null; /** Easy to read: the pins and labels in the 3D view a size larger. */ declare readable: boolean; /** The "Today" card top right: appointments of the plan's calendars and the bins due (default on). */ declare today: boolean; private declare _todayOpen: boolean; private declare _todayItems: TodayItem[]; /** The weather entity's daily forecast as Home Assistant answered it (see live/forecast.ts). */ private declare _forecast: unknown; private forecastAt = 0; private forecastKey = ""; private todayAt = 0; private todayDay = ""; /** How much closer the fitted views come (1 = fitted). */ declare zoom: number; /** Own buttons from the card's YAML (replace the house's buttons when set). */ declare buttons: CustomButton[] | null; private swipeSent = 0; private swipeTimer: ReturnType | undefined; /** Energy cables from the meter to the consumers (off unless switched on; kept per browser). */ private declare _flows: boolean; /** NextFloor's energy picture (flows, house balance) and the floating cards with their plan points. */ private declare _liveEnergy: EnergyPicture | null; private declare _liveCards: LiveCard[]; /** The floating cards show (the viewer's choice, kept in the browser). */ private declare _liveCardOn: boolean; /** The house card folded to its ring by the small corner button; remembered in this browser. */ private declare _houseFolded: boolean; /** Visibility of the right utility overview, remembered independently of the top totals. */ private declare _utilityOverviewVisible: boolean; private viewer: NextFloorViewer | null = null; private hydronicModule: Awaited> | null = null; private hydronicGeneration = 0; private starting = false; /** States of the placed entities as last sent to the viewer. */ private shownStates = new Map(); private shownPacks = -1; /** Entities of each door and window, and the registry they were matched with. */ private openingLinks: Map | null = null; private linkedRegistry: HomeAssistant["entities"] | undefined; /** Entities of electric furniture (TV, fridge, …). */ private furnitureLinks = new Map(); /** Pins of items with their own tap action (pin id → item id): a tap on them runs the action. */ private tapPins = new Map(); /** Room values of the current heatmap (for the legend). */ private heatValues = new Map(); /** Entities whose state changes redraw markers, cables, people and floor labels. */ private watched: string[] = []; /** Screens showing a camera: their snapshots are refreshed every few seconds (a changing query parameter). */ /** The look through a camera itself opens this floor: that floor change must not end it. */ constructor() { super(); this.building = null; this.floorId = null; this.roomId = null; this.wallMode = "auto"; this.solidWalls = false; this.glassWalls = null; this.explode = true; this.keepRoof = false; this.markerMode = "important"; this.markersOutside = null; this.tapInRoom = false; this.roomDoubleTap = "auto"; this.heatMode = "none"; this.theme = "neon"; this.accent = null; this.furnitureColors = null; this.furnish = false; this.weather = true; this.weatherEntityId = null; this.weatherDensity = 1; this.showEnergy = true; this.flows = null; this._liveEnergy = null; this._liveCards = []; this._liveCardOn = localStorage.getItem("nextfloor.cards") !== "0"; this._houseFolded = localStorage.getItem("nextfloor.house_card_folded") === "1"; try { this._utilityOverviewVisible = localStorage.getItem("nextfloor.utility_overview") !== "0"; } catch { this._utilityOverviewVisible = true; } this.selectedFurniture = null; this.selectedDevice = null; this._sky = 0; this.quality = "auto"; this.showStats = false; this._stats = null; this._error = null; this._energy = null; this._swipe = null; this._menu = null; this._pluginWindow = null; this._plate = null; this._wallBig = null; this._blend = 0.6; this._find = null; this._central = false; try { this._thumbsCompact = localStorage.getItem("nextfloor.thumbs_compact") === "1"; } catch { this._thumbsCompact = false; } this._armed = null; this.central = true; this.buttons = null; this._thumbs = []; this.floorThumbs = true; this.topologySelection=null; this.clean = false; this.cleanButton = false; this.clock = null; this.lockButton = false; this.walkButton = false; this.travelButton = false; this._travel = null; this._walking = false; this._stick = null; this._now = Date.now(); this._locked = (() => { try { return localStorage.getItem(LOCK_KEY) === "1"; } catch { return false; } })(); this.roomLabels = true; this.roomNamesButton = false; this.floorStack = "dim"; this._low = false; this.panelOpen = false; this._narrowStage = false; this._shortStage = false; this._phoneStage = false; this.alerts = true; this.alertJump = false; this.announcements = false; this.sensorBar = true; this.screenName = null; this._announcement = null; this._alerts = []; this.scenes = true; this._sceneFired = null; this.dimmed = false; this.autoOrbit = false; this.startView = null; this.outsideOpen = false; this.holograms = null; try { this._flows = localStorage.getItem("nextfloor.flows") === "1"; } catch { this._flows = false; } } connectedCallback(): void { super.connectedCallback(); // a plugin that registers later changes markers: rebuild them in the next update (through updated(), // like any other forced change), not only on the next state change this.stopPlugins = onPluginsChanged(() => { this.pluginsDirty = true; this.requestUpdate(); }); if (this.hasUpdated) { this.observeStage(); if (!this.viewer) void this.start(); } } disconnectedCallback(): void { super.disconnectedCallback(); this.hydronicGeneration++; this.hydronicModule?.closeHydronic(); this.stopPlugins?.(); this.stopPlugins = null; this.listenToAnnouncements(false); this.resizeObs?.disconnect(); this.resizeObs = null; clearInterval(this.alertTimer); this.alertTimer = undefined; clearInterval(this.contactTimer); this.contactTimer = undefined; clearInterval(this.clockTimer); this.clockTimer = undefined; clearInterval(this.travelTimer); this.travelTimer = undefined; this.live = null; this.viewer?.dispose(); this.viewer = null; } protected firstUpdated(): void { this.observeStage(); void this.start(); } /** Follows the stage's width: the floor pictures shrink on narrow screens. */ private observeStage(): void { const stage = this.renderRoot.querySelector(".nf-stage"); if (!stage || this.resizeObs || typeof ResizeObserver !== "function") return; this.resizeObs = new ResizeObserver((entries) => { const rect = entries[0]?.contentRect; const narrow = (rect?.width ?? 1000) < 700 || (rect?.height ?? 1000) < SHORT_STAGE; const short = (rect?.height ?? 1000) < SHORT_STAGE; if (short !== this._shortStage) this._shortStage = short; const phone = (rect?.width ?? 1000) < 520; if (phone !== this._phoneStage) this._phoneStage = phone; if (narrow === this._narrowStage) return; this._narrowStage = narrow; this.scheduleThumbs(); }); this.resizeObs.observe(stage); } private async start(): Promise { if (this.starting || this.viewer) return; this.starting = true; try { const mod = await load3d(); if (!this.isConnected) return; const host = this.renderRoot.querySelector(".nf-stage") as HTMLElement; // a tap into the 3D view closes the star menu, like any menu (#220) host.addEventListener("pointerdown", (e) => { if (this._central && !this.centralOpen && !(e.target as Element | null)?.closest?.(".nf-central, .nf-central-btn")) this._central = false; }); this.viewer = mod.createViewer(host, { quality: this.quality, explode: this.explode, onRoomTap: (floorId, roomId) => this.fire("room-tap", { floorId, roomId }), onFloorTap: (floorId) => this.fire("floor-tap", { floorId }), floorInfo: (floor) => floor.rooms.length === 1 ? translate(this.hass, "floor_rooms_one") : translate(this.hass, "floor_rooms", { n: floor.rooms.length }), onBack: () => this.fire("back", {}), onDeviceTap: (id, x, y) => this.onDeviceTap(id, x, y), onDeviceHold: (id, x, y) => this.onDeviceHold(id, x, y), onRoomDoubleTap: (floorId, roomId) => this.onRoomDoubleTap(floorId, roomId), onDeviceSwipe: (id, phase, dy, x, y) => this.onDeviceSwipe(id, phase, dy, x, y), onFurnitureSelect: (id) => this.fire("furniture-select", { id }), onFurnitureMove: (id, x, z) => this.fire("furniture-move", { id, x, z }), onDeviceSelect: (id) => this.fire("device-select", { id }), onDeviceMove: (id, x, z) => this.fire("device-move", { id, x, z }), // stats can be switched on at any time; they only cause updates while shown onStats: (s) => { if (this.showStats) this._stats = s; }, }); this.viewer.setWallMode(this.wallMode); this.viewer.setPaintedWalls(this.solidWalls); this.viewer.setGlassWalls((this.glassWalls ?? 20) / 100); this.viewer.setTheme(this.theme); this.viewer.setAccent(this.accent ?? null); this.viewer.setFurnitureColors(this.furnitureColors ?? null); this.viewer.setNotePhotos((photo) => (this.hass ? pictureUrl(this.hass, photo, (id) => this.storedPicture(this.hass!, id)) : null)); this.viewer.setNavigationLocked(this._locked); this.viewer.setFurnishMode(this.furnish); this.viewer.setTapInRoom(this.tapInRoom); this.viewer.setSurfaceGrab(this.surfaceGrab ?? null); this.viewer.setFurnishTypes(this.furnishTypes ?? null); this.viewer.setFloorStack(this.floorStack); this.viewer.setStats(this.showStats); this.viewer.setAutoOrbit(this.autoOrbit ? 0.06 : 0); this.viewer.setKeepRoof(this.keepRoof); this.viewer.setKeepCamera(!!this.keepCamera); this.viewer.setPlain(!!this.plain); this.viewer.setRightBack(!!this.rightBack); this.viewer.setZoom(this.zoom ?? 1); this._low = this.viewer.low; // owned 3D models (cars and the like) come from the user's Home Assistant, with the user's login this.viewer.setMeshSource((id) => this.hass?.fetchWithAuth ? this.hass.fetchWithAuth(`/api/nextfloor/mesh/${encodeURIComponent(id)}`).then((r) => (r.ok ? r.arrayBuffer() : null)) : Promise.resolve(null), ); this.viewer.setPacks([...getPacks()]); this.shownPacks = packsVersion(); if (this.building) { this.shownStartView = JSON.stringify(this.startViewOf()); this.viewer.setStartView(this.startViewOf()); this.viewer.setBuilding(this.shownBuilding(this.hass)); this.viewer.setMap(this.building.settings.map, this.building.settings.north ?? 0); } this.scheduleThumbs(); this.syncDevices(true); this.viewer.setFloor(this.floorId, false); if (this.roomId) this.viewer.selectRoom(this.roomId); } catch (err) { this._error = String(err); } finally { this.starting = false; } } protected updated(changed: PropertyValues): void { if (changed.has("announcements") || (changed.has("hass") && this.announcements && !this.stopAnnouncements)) this.listenToAnnouncements(this.announcements && !!this.hass && this.isConnected); if (changed.has("hass") && this.live?.el) this.live.el.hass = this.hass; // a plugin window's content (a Home Assistant card) gets every new hass const windowNode = this._pluginWindow?.node as (Node & { hass?: unknown }) | undefined; if (changed.has("hass") && windowNode && "hass" in windowNode) windowNode.hass = this.hass; // the star menu closes when a room or another floor is chosen (#220) if (this._central && !this.centralOpen && ((changed.has("roomId") && changed.get("roomId") !== undefined) || (changed.has("floorId") && changed.get("floorId") !== undefined))) this._central = false; if (changed.has("centralOpen") && this.centralOpen) this._central = true; // before the viewer exists: the card loads it late and `clock` does not change again, so the clock never ticked (#68) if (changed.has("clock")) { clearInterval(this.clockTimer); this.clockTimer = this.clock ? setInterval(() => (this._now = Date.now()), 10000) : undefined; } const v = this.viewer; if (!v) return; // packs arrive with the building (or after an import): the viewer rebuilds pack furniture if (this.shownPacks !== packsVersion()) { this.shownPacks = packsVersion(); v.setPacks([...getPacks()]); // vehicles in parking spots come from packs too: look them up again now that the packs are here if (this.hass && this.building) v.setParked(parkedVehicles(this.hass, this.building)); // a feature pack may have arrived with them (Energiefluss): the cables and modules follow this.syncDevices(true); } if (["building","topologySelection","floorId"].some((k)=>changed.has(k)) && this.building) { // a new start view (just remembered in the editor) shows right away in the house view const start = JSON.stringify(this.startViewOf()); const startChanged = this.shownStartView !== undefined && this.shownStartView !== start; this.shownStartView = start; v.setStartView(this.building.topology&&this.topologyFocus.kind!=="all"?null:this.startViewOf()); const previous=this.shownFor?.shown,shown=this.shownBuilding(this.hass);if(shown!==previous)v.setBuilding(shown); v.setMap(this.building?.settings.map, this.building?.settings.north ?? 0); if (startChanged && this.floorId === null) v.resetView(); } if (changed.has("startView") && changed.get("startView") !== undefined) { v.setStartView(this.startViewOf()); if (this.floorId === null) v.resetView(); } if (changed.has("building") || changed.has("theme") || changed.has("floorThumbs") || changed.has("packs") || changed.has("topologySelection") || changed.has("floorId") || changed.has("roomId")) this.scheduleThumbs(); // markers shown by kind outside the opened room change with the room const byRoom = this.markersOutside ? ["markersOutside", "floorId", "roomId"] : ["markersOutside"]; const forced = this.pluginsDirty || ["building", "topologySelection", "markerMode", "heatMode", "flows", "alerts", "dimmed", "holograms", "roomLabels", "floorId", "roomId", ...byRoom].some((k) => changed.has(k)); this.pluginsDirty = false; if (forced || changed.has("hass")) this.syncDevices(forced); if (changed.has("autoOrbit")) v.setAutoOrbit(this.autoOrbit ? 0.06 : 0); if (changed.has("_thumbs") || changed.has("_narrowStage") || changed.has("_phoneStage") || changed.has("building")) v.setLabelInset(this.building?.topology||(this._thumbs.length&&!this._phoneStage) ? (this.narrowThumbs ? 136 : 184) : 0); if (changed.has("floorId")) v.setFloor(this.floorId); if (changed.has("roomId") && (this.roomId || changed.get("roomId"))) v.selectRoom(this.roomId); if (changed.has("outsideOpen") && changed.get("outsideOpen") !== undefined) { const view = this.building?.settings.outside_view; if (this.outsideOpen && view) v.showView(view); else if (!this.outsideOpen && view && this.floorId === null && !this.roomId) v.resetView(); } if (changed.has("tapInRoom")) v.setTapInRoom(this.tapInRoom); if (changed.has("wallMode")) v.setWallMode(this.wallMode); if (changed.has("solidWalls")) v.setPaintedWalls(this.solidWalls); if (changed.has("glassWalls")) v.setGlassWalls((this.glassWalls ?? 20) / 100); if (changed.has("explode")) v.setExplode(this.explode); if (changed.has("keepRoof")) v.setKeepRoof(this.keepRoof); if (changed.has("keepCamera")) v.setKeepCamera(!!this.keepCamera); if (changed.has("plain")) v.setPlain(!!this.plain); if (changed.has("rightBack")) v.setRightBack(!!this.rightBack); if (changed.has("zoom")) v.setZoom(this.zoom ?? 1); if (changed.has("floorStack")) v.setFloorStack(this.floorStack); if (changed.has("theme")) v.setTheme(this.theme); if (changed.has("_locked")) v.setNavigationLocked(this._locked); if (changed.has("accent")) v.setAccent(this.accent ?? null); if (changed.has("furnitureColors")) v.setFurnitureColors(this.furnitureColors ?? null); if (changed.has("surfaceGrab")) v.setSurfaceGrab(this.surfaceGrab ?? null); if (changed.has("furnishTypes")) v.setFurnishTypes(this.furnishTypes ?? null); if (changed.has("furnish")) { v.setFurnishMode(this.furnish); this.syncDevices(true); } if (changed.has("selectedFurniture")) v.selectFurniture(this.selectedFurniture); if (changed.has("selectedDevice")) v.setSelectedDevice(this.selectedDevice); if (changed.has("weather") || changed.has("weatherEntityId") || changed.has("weatherDensity") || changed.has("timeOfDay")) this.syncDevices(true); if (changed.has("quality") && changed.get("quality") !== undefined) { v.setQuality(this.quality); this._low = v.low; } if (changed.has("showStats")) v.setStats(this.showStats); if (changed.has("building")) this.findIndex = null; } /** * Send device markers, door/window states, energy cables, people and floor label texts to the viewer * when a watched entity changed (or the building). Openings are matched with entities again when * the building or the entity registry changes. */ private shownFor: { building: Building; key: string; shown: Building } | null = null; /** Stored pictures of frames, loaded once each (image id -> data URL; "" while loading or gone). */ private framePictureData = new Map(); /** The photos of picture frames: stored pictures (loaded once), URLs, and the picture of an image or camera entity. */ private framePictures(hass: HomeAssistant, b: Building): LivePictureInput[] { const out: LivePictureInput[] = []; // the notes' stored photos are loaded ahead, so one shows at once when its note is opened for (const floor of b.floors) for (const note of floor.notes ?? []) if (note.photo?.startsWith("image:")) this.storedPicture(hass, note.photo.slice(6)); for (const floor of b.floors) for (const f of floor.furniture) { if (!f.picture || !furnitureShown(hass, f)) continue; const url = pictureUrl(hass, f.picture, (id) => this.storedPicture(hass, id)); if (url) out.push({ furnitureId: f.id, floorId: floor.id, url, border: f.picture_border ?? 0, fit: f.picture_fit === "contain" ? "contain" : "cover" }); } return out; } private storedPicture(hass: HomeAssistant, id: string): string | null { const known = this.framePictureData.get(id); if (known !== undefined) return known || null; this.framePictureData.set(id, ""); fetchImage(hass, id) .then((data) => { this.framePictureData.set(id, data); this.syncDevices(true); }) .catch(() => undefined); return null; } /** The building as the 3D view draws it: without the pieces whose visibility condition is not met. */ private get topologyFocus(): TopologySelection { return this.building&&this.floorId?floorSelection(this.building,this.floorId,this.roomId):this.topologySelection??ALL_TOPOLOGY; } private scopeBuilding(): Building { const b=this.building!;if(!b.topology)return b; const floors=topologyFloors(b,this.topologyFocus,true),key=floors.map((f)=>f.id).join("|"); if(this.scopedFor?.source!==b||this.scopedFor.key!==key)this.scopedFor={source:b,key,plan:{...b,floors}}; return this.scopedFor.plan; } private shownBuilding(hass: HomeAssistant | undefined): Building { const b = this.scopeBuilding(); const hidden = hiddenFurniture(hass, b); const layers = b.floors.filter((f) => f.layer && this.hiddenLayers.has(f.id)).map((f) => f.id); const key = [...hidden, ...layers.map((id) => `layer:${id}`)].join(","); if (this.shownFor?.building === b && this.shownFor.key === key) return this.shownFor.shown; const shown = withoutHidden(b, hidden); this.shownFor = { building: b, key, shown: layers.length ? { ...shown, floors: shown.floors.filter((f) => !layers.includes(f.id)) } : shown }; return this.shownFor.shown; } /** Layers hidden on this device (the trees, the decoration), remembered in the browser. */ private hiddenLayers: Set = (() => { try { return new Set(JSON.parse(localStorage.getItem("nextfloor.hidden_layers") ?? "[]") as string[]); } catch { return new Set(); } })(); private toggleLayer(id: string): void { if (this.hiddenLayers.has(id)) this.hiddenLayers.delete(id); else this.hiddenLayers.add(id); try { localStorage.setItem("nextfloor.hidden_layers", JSON.stringify([...this.hiddenLayers])); } catch { // without storage the choice lasts until the page reloads } if (this.viewer && this.building) this.viewer.setBuilding(this.shownBuilding(this.hass)); this.requestUpdate(); } /** The eyes of the layers, top middle: a tap shows or hides a layer. */ private renderLayers() { const layers = (this.building?.floors ?? []).filter((f) => f.layer); if (!layers.length || this.clean) return nothing; return html`
${layers.map((f) => html``)}
`; } private syncDevices(force: boolean): void { const v = this.viewer; const b = this.building?this.scopeBuilding():null; if (!v || !b || !this.hass) return; // time travel: the same view, fed with the states of the moment shown const travel = this._travel; const hass = travel && !travel.loading ? hassAt(this.hass, travel.history, travel.t) : this.hass; if (force || !this.openingLinks || this.linkedRegistry !== hass.entities) { this.openingLinks = openingEntities(hass, b.floors); this.furnitureLinks = furnitureEntities(hass, b.floors); this.linkedRegistry = hass.entities; this.findIndex = null; this.alertSrc = this.alerts ? alertSources(hass, b, this.weatherEntityId, this.openingLinks) : null; this.watched = watchedEntities({ hass, building: b, openingLinks: this.openingLinks, furnitureLinks: this.furnitureLinks, needsRoomSensors: this.heatMode !== "none" || this.roomLabels, alertSources: this.alertSrc, weatherEntityId: this.weatherEntityId, }); force = true; } const changed = force || this.watched.some((id) => this.shownStates.get(id) !== hass.states[id]); if (!changed) return; // a piece shown only while a helper is on (seasonal decoration) comes and goes with it const previous=this.shownFor?.shown,shown=this.shownBuilding(hass);if(shown!==previous)v.setBuilding(shown); this.shownStates = new Map(this.watched.map((id) => [id, hass.states[id]])); this.syncHydronics(v, b, hass); this.refreshToday(b); this.refreshForecast(b); const consumers = findConsumers(hass, b); // hidden layers bring no pins either const deviceMarkers = buildMarkers(hass, b.floors.some((f) => f.layer && this.hiddenLayers.has(f.id)) ? this.shownBuilding(hass) : b); this.placementInfo = new Map(deviceMarkers.map((m) => [m.id, { floorId: m.floorId, roomId: m.roomId, x: m.x, z: m.z, y: m.y, rotation: m.rotation ?? 0 }])); const furniture = this.furnitureMarkers(hass, b, new Set(deviceMarkers.map((m) => m.id)), new Set(consumers.map((c) => c.powerEntity))); consumers.push(...furniture.consumers); const summary = energySummary(hass, b, consumers, deviceSensors(b, (f) => this.furnitureLinks?.get(f.id)?.power ?? null)); // a placed power sensor shows its value as state text already, so only devices get a watt badge const byDevice = new Map(consumers.filter((c) => c.id !== c.powerEntity).map((c) => [c.id, c.power])); this.confirmSet = confirmEntities(hass, b.floors); // under NextFloor's cards (a playing speaker, a car in its spot) the device's own pin steps aside const carded = new Set(this.liveCardsOn ? this._liveCards.flatMap((c) => (c.kind === "media" ? [c.media.entity] : c.kind === "car" ? [c.spot] : [])) : []); // gardens, terraces and pools with an area, a thermometer or a pump: a pin of their own (a tap opens Outside) for (const floor of b.floors) for (const a of floor.outdoor ?? []) { if (!a.area_id && !a.temp_entity && !a.pump_entity) continue; const temp = a.temp_entity ? hass.states[a.temp_entity] : undefined; const pump = a.pump_entity ? hass.states[a.pump_entity] : undefined; const [cx, cz] = centroid(a.points); const t = temp && Number.isFinite(Number(temp.state)) ? `${formatNumber(hass, fromCelsius(hass, toCelsius(Number(temp.state), temp.attributes.unit_of_measurement)), 1)} ${tempUnit(hass)}` : ""; const running = !!pump && isActive(pump); deviceMarkers.push({ id: a.area_id ? `outdoor:${a.id}` : (a.pump_entity ?? a.temp_entity)!, floorId: floor.id, roomId: null, x: cx, z: cz, y: outdoorTopAt(floor, a, cx, cz) + 0.7, icon: mdiIcon(a.type === "pool" ? "pool" : a.type === "terrace" ? "table-chair" : "tree-outline"), name: (a.area_id && hass.areas?.[a.area_id]?.name) || translate(hass, `out_${a.type}` as I18nKey), text: [t, running ? translate(hass, "pool_pump_on") : ""].filter(Boolean).join(" · "), active: running, unavailable: false, glow: null, show: "always", }); } // pins moved by hand (devices that stand close together): shifted in the plan and in height; lamps keep theirs at the lamp const shifts = new Map>(); for (const floor of b.floors) { for (const p of floor.placements) if (p.pin_offset) shifts.set(`${floor.id}:${p.entity_id}`, p.pin_offset); for (const f of floor.furniture) if (f.pin_offset) shifts.set(`f:${f.id}`, f.pin_offset); } const shifted = (m: T): T => { const s = m.lamp ? undefined : (m.furnitureId ? shifts.get(`f:${m.furnitureId}`) : undefined) ?? shifts.get(`${m.floorId}:${m.id}`); return s ? { ...m, x: m.x + (s.x ?? 0), z: m.z + (s.z ?? 0), y: m.y + (s.y ?? 0) } : m; }; v.setDevices([ ...[...deviceMarkers, ...furniture.markers].map(shifted).map((m) => { // "without watts" drops the power badge (a plug shows only on / off) const power = m.show === "no_power" || ("energyDevice" in m && m.energyDevice) ? null : (byDevice.get(m.id) ?? null); // at night (kiosk) colour effects rest const marker = { ...m, power, powerText: power === null ? undefined : formatPower(hass, power), effect: this.dimmed ? undefined : m.effect, text: this.subMeterText(hass, b, summary, m.furnitureId) ?? m.text }; // the own name under the pin: per device, or for every named device (card option marker_names) const caption = m.ownName && (m.showName || this.markerNames) ? m.ownName : ""; const under = carded.has(m.id) || (!!m.furnitureId && carded.has(m.furnitureId)); return { ...marker, pin: this.showPin(marker) && !under, full: m.show === "always", caption }; }), ]); v.setPickTargets(furniture.targets, this.openingTargets(), this.secondBlinds()); v.setScreens(furniture.screens); v.setFridgeDoors(fridgeDoors(hass, b.floors)); v.setCovers(coverReaches(hass, b)); v.setRobots(this.robotInfos(hass, b)); // pets with a room sensor (Bermuda, ESPresense, a tracker tag): they roam the room it names const petRooms = new Map(); for (const floor of b.floors) for (const f of floor.furniture) { if (!packItem(f.type)?.pet || !f.room_sensor || f.room_sensor === "none") continue; petRooms.set(f.id, robotRoom(hass, floor.rooms.filter((r) => r.points.length >= 3), null, f.room_sensor)?.id ?? null); } if (petRooms.size) v.setPetRooms(petRooms); // roof windows: sash and blind follow their contact and cover like windows do v.setRoofWindows(roofWindowStates(hass, b)); v.setParked(parkedVehicles(hass, b)); v.setGateStates(gateStates(hass, b)); const types = new Map(b.floors.flatMap((f) => f.openings.map((o) => [o.id, o.type] as const))); const openingStates = new Map([...this.openingLinks!].map(([id, e]) => [id, openingState(hass, e, types.get(id))])); v.setOpeningStates(openingStates); this.setAlerts(this.alertSrc ? findAlerts(hass, b, this.alertSrc, this.openingLinks!) : []); this.watchLostContacts(hass); // the floor pictures follow lamps and blinds (not sensors), at most every few seconds const lampSig = [...deviceMarkers, ...furniture.markers].map((m) => `${m.id}:${m.glow ? `${m.glow.level.toFixed(1)}/${m.glow.color.map((c) => c.toFixed(1)).join("/")}` : 0}`).join(";") + "|" + [...openingStates].map(([id, o]) => `${id}:${o.open}:${o.cover === null ? "-" : o.cover.toFixed(1)}`).join(";"); if (lampSig !== this.thumbSig) { const first = this.thumbSig === ""; this.thumbSig = lampSig; if (!first) this.scheduleThumbs(1500); } // NextFloor: power flowing between the devices, sparkling modules, the house balance card // the advanced energy mode also needs the automatically found sensors of the sub-meters const livePic = energyPicture(hass, b, consumers, b.energy.advanced ? (f) => this.furnitureLinks?.get(f.id)?.power ?? null : undefined); const liveCars = this.liveCars(hass, b); // a charging car draws its power from the nearest wallbox (or the house) into the car for (const c of liveCars) { if (!c.car.home || (!c.car.charging && !c.car.plugged)) continue; const near = b.floors.flatMap((f) => f.furniture.filter((m) => m.type === "wallbox").map((m) => ({ floorId: f.id, x: m.x, z: m.z, y: 1 }))) .sort((p, q) => Math.hypot(p.x - c.at.x, p.z - c.at.z) - Math.hypot(q.x - c.at.x, q.z - c.at.z))[0]; // a wallbox close to the car: its charging cable hangs down to the car, plugged in or charging const cable = near && near.floorId === c.at.floorId && Math.hypot(near.x - c.at.x, near.z - c.at.z) < 9; const from = near ?? houseHub(b); if (!from || (!c.car.charging && !cable)) continue; livePic.arcs.push({ key: `car:${c.spot}`, from, to: { ...c.at, y: 0.8 }, power: c.car.charging ? (c.car.chargingW ?? 7000) : 0, color: [80, 175, 255], ...(cable ? { via: [{ ...from, y: 0.35 }, { floorId: c.at.floorId, x: (from.x + c.at.x) / 2, z: (from.z + c.at.z) / 2, y: 0.08 }, { ...c.at, y: 0.5 }], cable: true } : {}), }); } // a heat pump that heats: its heat flows into the house in orange const hub = houseHub(b); for (const p of this.liveHeatPumps(b)) { const heat = p.pump.heat ?? (p.pump.mode === "heating" || p.pump.mode === "water" ? (p.pump.power ?? 0) * (p.pump.cop ?? 3) : 0); if (hub && heat > 100 && p.pump.mode !== "cooling") livePic.arcs.push({ key: `heat:${p.id}`, from: { floorId: p.floorId, x: p.x, z: p.z, y: 0.8 }, to: hub, power: heat, color: [255, 120, 40] }); } const liveFlows = (this.flows ?? this._flows) && !this.dimmed; v.setLiveEnergy(liveFlows ? livePic.arcs : [], liveFlows ? livePic.sparks : []); if (JSON.stringify(livePic) !== JSON.stringify(this._liveEnergy)) this._liveEnergy = livePic; const liveMedia = this.liveMedia(hass, b); const playing = liveMedia.filter((m) => m.playing && !this.dimmed); v.setLiveSound( playing.filter((m) => m.rings > 0).map((m) => ({ id: m.entity, at: m.at, color: m.color, level: m.volume ?? 0.5, size: m.rings })), multiroom(playing).map(([a, c]) => [a.at, c.at]), ); this.syncLhCards(v, b, livePic, liveCars, playing, hass); // TV screens: a TV or monitor linked to a media player that runs shows what runs v.setLiveScreens(this.dimmed ? [] : liveScreens(hass, b, this.furnitureLinks)); v.setPictures(this.framePictures(hass, b)); // lawn sprinklers that water now (at night on the wall tablet effects rest) v.setLiveWater(this.dimmed ? [] : liveSprays(hass, b, this.furnitureLinks)); const persons = SHOW_PRESENCE ? personsInRooms(hass, b) : []; v.setPersons(persons); const counts = floorCounts(hass, b, this.openingLinks!, persons); v.setFloorInfo(new Map([...counts].map(([id, c]) => [id, floorInfoText(hass, c)]))); // daylight: sun through the windows and a lighter sky const config = hass.config; const sunNow = this.timeOfDay != null && config?.latitude !== undefined && config.longitude !== undefined ? sunPosition(todayAt(this.timeOfDay, config.time_zone), config.latitude, config.longitude) : readSun(hass); v.setSun(sunNow); v.setLocation(config?.latitude !== undefined && config.longitude !== undefined ? { latitude: config.latitude, longitude: config.longitude, zone: config.time_zone } : null); // the sky over the plot (NextFloor's own weather layer): clouds darken the stage, rain and snow fall along the wind const raw = this.weather && !this.dimmed ? readSkyWeather(hass, weatherEntity(hass, this.weatherEntityId ?? b.settings.weather_entity)) : null; const weather = raw ? withDensity(chosenEffects(raw, b.settings.weather_effects), this.weatherDensity) : null; this.cloud = weather?.cloud ?? 0; this._sky = skyLightness(sunNow?.elevation ?? null, this.cloud); v.setSky( this.weather && !this.dimmed ? { weather, sun: sunNow, north: b.settings.north ?? 0, sky: this.skyColor(), disc: (b.settings.weather_effects ?? ["sky"]).includes("sky"), low: this._low, } : null, ); this.applyTint(); const hasEnergy = summary.grid !== null || summary.solar !== null || summary.battery !== null || summary.tariff !== null; const energy = hasEnergy ? summary : null; // a new object would make Lit render again; only changed values do if (JSON.stringify(energy) !== JSON.stringify(this._energy)) this._energy = energy; } /** * A contact that went unavailable warns only after the grace time, which no state change marks: while one is * unavailable, look again every minute. */ private watchLostContacts(hass: HomeAssistant): void { const waiting = !!this.alertSrc && !this._travel && contactsPending(hass, this.alertSrc); if (waiting && !this.contactTimer) this.contactTimer = setInterval(() => { const b = this.building; if (this.alertSrc && b && this.hass && this.openingLinks && !this._travel) this.setAlerts(findAlerts(this.hass, b, this.alertSrc, this.openingLinks)); }, 60_000); if (!waiting && this.contactTimer) { clearInterval(this.contactTimer); this.contactTimer = undefined; } } /** New warnings start the pulse (and a jump to the room when wanted); none stops it. */ private setAlerts(alerts: Alert[]): void { const keys = alerts.map((a) => `${a.kind}:${a.entity}`); // quiet warnings (a contact that stopped answering) only show in the banner: no pulse, no jump const fresh = alerts.filter((a, i) => !this.seenAlerts.has(keys[i]) && !QUIET_ALERTS.has(a.kind)); this.seenAlerts = new Set(keys); if (keys.join() !== this._alerts.map((a) => `${a.kind}:${a.entity}`).join()) this._alerts = alerts; const pulsing = alerts.some((a) => !QUIET_ALERTS.has(a.kind)); if (pulsing && !this.alertTimer) this.alertTimer = setInterval(() => !document.hidden && this.applyTint(), this._low ? 200 : 100); if (!pulsing && this.alertTimer) { clearInterval(this.alertTimer); this.alertTimer = undefined; } if (fresh.length && this.alertJump) this.jumpTo(fresh[0]); } /** Show where a warning is: its floor and room, or the house for an alarm. */ private jumpTo(a: Alert): void { // an own warning: its details, or what was chosen for it (switch the entity, go to its room) if (a.kind === "own" && a.tap !== "room") { if (a.tap === "toggle" && canControl(this.hass, a.entity)) void this.hass.callService("homeassistant", "toggle", { entity_id: a.entity }); else openMoreInfo(this, a.entity); return; } if (!a.floorId) { this.fire("floor-tap", { floorId: null }); return; } if (this.floorId !== a.floorId) this.fire("floor-tap", { floorId: a.floorId }); // the host switches the floor first; the room follows once it has rendered if (a.roomId) setTimeout(() => this.fire("room-tap", { floorId: a.floorId, roomId: a.roomId }), 60); } /** Double tap on a room: all its lights off when one is on, otherwise all on (plan setting / card option room_double_tap). */ private onRoomDoubleTap(floorId: string, roomId: string): void { const b = this.building; const hass = this.hass; const floor = b?.floors.find((f) => f.id === floorId); const room = floor?.rooms.find((r) => r.id === roomId); if (!b || !hass || !floor || !room) return; const mode = roomToggleMode(b.settings.room_double_tap, this.roomDoubleTap); const lights = roomToggleLights(hass, floor, room, this.furnitureLinks, this.confirmSet, mode).filter((id) => canControl(hass, id)); if (!lights.length) return; const anyOn = lights.some((id) => hass.states[id]?.state === "on"); void hass.callService("homeassistant", anyOn ? "turn_off" : "turn_on", { entity_id: lights }); this.roomFlash = { roomId, until: performance.now() + 350 }; this.applyTint(); setTimeout(() => { this.roomFlash = null; this.applyTint(); }, 380); } private runScene(id: string): void { if (!canControl(this.hass, id)) return; void this.hass.callService(id.split(".")[0], "turn_on", { entity_id: id }); this._sceneFired = id; setTimeout(() => (this._sceneFired = null), 600); } /** * Floor colours of the rooms: the heatmap, the pulsing rooms of warnings and the flash of a double * tap; sent to the viewer only when they changed. */ private applyTint(): void { const v = this.viewer; const b = this.building; const hass = this.hass; if (!v || !b || !hass) return; let tint: Map | null = null; if (this.heatMode !== "none" && this.heatMode !== "values" && this.heatMode !== "wifi") { const mode = this.heatMode; const values = roomValues(hass, b, mode); // the legend's "nothing found" line depends on it: render again when that changes if (!values.size !== !this.heatValues.size) this.requestUpdate(); this.heatValues = values; const summer = isSummer(new Date(), hass.config?.latitude ?? 50); tint = new Map([...values].map(([id, value]) => [id, heatColor(mode, value, summer)])); } // "values": the numbers at the room names instead of coloured floors const info = new Map(); if (this.heatMode === "values") { for (const floor of b.floors) for (const room of floor.rooms) { const t = roomClimateValue(hass, floor, room, "temperature"); const h = roomClimateValue(hass, floor, room, "humidity"); const c = roomClimateValue(hass, floor, room, "co2"); const need = airingNeed(c, h, mouldRisk(t, h)); const parts = [ t !== null ? `${formatNumber(hass, fromCelsius(hass, t), 1)} ${tempUnit(hass)}` : null, h !== null ? `${formatNumber(hass, h, 0)} %` : null, c !== null ? `${formatNumber(hass, c, 0)} ppm` : null, need ? `💨 ${translate(hass, `air_${need}`)}` : null, ].filter((x): x is string => !!x); if (parts.length) info.set(room.id, parts.join(" · ")); } } v.setRoomInfo(info); // underfloor heating: the floor of a room glows warm while its heating runs (under the heat map, which shows values) if (!tint) { for (const floor of b.floors) for (const room of floor.rooms) { const st = room.floor_heating ? hass.states[room.floor_heating] : undefined; const heats = st && (isSymcon(hass) ? nativeBool(st) === true : st.entity_id.startsWith("climate.") ? st.attributes.hvac_action === "heating" : st.state === "on" || st.state === "open"); if (heats) (tint ??= new Map()).set(room.id, [0.55, 0.24, 0.08]); } } if (this._alerts.length) { tint ??= new Map(); const k = 0.55 + 0.45 * Math.sin(performance.now() / 160); for (const a of this._alerts) { if (QUIET_ALERTS.has(a.kind)) continue; const c = alertColor(a.kind).map((x) => x * k) as [number, number, number]; if (a.roomId) tint.set(a.roomId, c); else for (const f of b.floors) for (const r of f.rooms) tint.set(r.id, c); } } if (this.roomFlash && performance.now() < this.roomFlash.until) { tint ??= new Map(); tint.set(this.roomFlash.roomId, [0.9, 0.95, 1]); } const sig = tint ? [...tint].map(([id, c]) => `${id}:${c.map((x) => x.toFixed(2)).join(",")}`).join(";") : ""; if (sig === this.tintSig) return; this.tintSig = sig; v.setRoomTint(tint); } /** * Markers, energy consumers and lit screens of furniture with linked entities. Entities that are * placed as devices as well keep their device marker. */ private furnitureMarkers( hass: HomeAssistant, b: Building, taken: Set, consumerSensors: Set, ): { markers: (DeviceMarker & { fromFurniture: boolean; energyDevice?: boolean; care?: boolean; readout?: boolean })[]; consumers: Consumer[]; screens: Map; targets: Map } { const markers: (DeviceMarker & { fromFurniture: boolean; energyDevice?: boolean; care?: boolean; readout?: boolean })[] = []; const consumers: Consumer[] = []; const screens = new Map(); const targets = new Map(); const subMeters = subMeterIds(b); for (const floor of b.floors) { if (floor.layer && this.hiddenLayers.has(floor.id)) continue; for (const f of floor.furniture) { if (!furnitureShown(hass, f)) continue; const linked = this.furnitureLinks.get(f.id); // furniture with a state: a glowing plate on the item while its entity is on, occupied or home; // two entities light the halves (left/right of a bed, bottom/top of a bunk bed) const faces = this.stateFaces(hass, f); if (faces.length) screens.set(f.id, { color: faces[0].color, level: faces[0].level, faces }); // a light switch or socket: each button glows with its own entity; a tap switches it (or asks which, with several) // the household: a bin's pickup, post in the mailbox, a thirsty plant const care = householdKind(f.type); if (care && f.care_entity) { const marker = this.careMarker(hass, floor, f, care, f.care_entity); if (marker) { markers.push(marker.marker); if (marker.glow) screens.set(f.id, { color: marker.glow, level: 0.9, faces: [{ part: "all", color: marker.glow, level: 0.9 }] }); targets.set(f.id, f.care_entity); } continue; } const plate = packItem(f.type); // a curtain, roller screen, awning or gate: a tap opens the menu of the cover it follows if (f.cover_entity && hasMovingParts(plate)) targets.set(f.id, f.cover_entity); if (plate?.gangs) { // a smart plug or measuring switch behind a button: its power counts in the flow like any device's for (const g of (f.gang_entities ?? []).slice(0, plate.gangs)) { const sensor = g && g !== "none" ? powerSensorFor(hass, g) : null; const w = sensor ? readPower(hass.states[sensor]) : null; if (sensor && w !== null && !consumerSensors.has(sensor)) { consumerSensors.add(sensor); consumers.push({ id: g!, powerEntity: sensor, floorId: floor.id, x: f.x, z: f.z, power: Math.max(0, w) }); } } const gangs = gangGlows(hass, (f.gang_entities ?? []).slice(0, plate.gangs), /socket/.test(f.type)); if (gangs.length) screens.set(f.id, { color: gangs[0].color, level: gangs[0].level, gangs }); if (gangEntities(f.gang_entities, plate.gangs).length) targets.set(f.id, `gang:${f.id}`); continue; } if (isLamp(f.type)) { const lamp = this.lampMarker(hass, floor, f, linked?.entity ?? null); // a lamp with a power sensor (a smart plug, a measuring switch): its watts on the pin and in the house's balance const lampW = linked?.power ? readPower(hass.states[linked.power]) : null; if (linked?.power && lampW !== null) { if (lampW >= 1) lamp.text = lamp.text ? `${lamp.text} · ${powerText(hass, lampW)}` : powerText(hass, lampW); if (!consumerSensors.has(linked.power)) { consumerSensors.add(linked.power); consumers.push({ id: lamp.id, powerEntity: linked.power, floorId: floor.id, x: f.x, z: f.z, power: Math.max(0, lampW) }); } } markers.push(lamp); if (f.type === "ceiling_fan") { const fan = linked?.fan ? hass.states[linked.fan] : undefined; lamp.spin = fanSpin(fan); if (fan && !taken.has(fan.entity_id)) { taken.add(fan.entity_id); // the fan's own pin under the blades: tap switches it, a swipe changes its speed markers.push({ ...lamp, id: fan.entity_id, y: Math.max(0.5, lamp.y - 0.3), icon: f.icon ? mdiIcon(f.icon) : iconSvg("fan"), name: f.name || entityName(hass, fan.entity_id), text: fanText(hass, fan), active: isActive(fan), unavailable: isUnavailable(fan), glow: null, lamp: null, spin: undefined, pickable: undefined, effect: undefined }); } } continue; } // a fridge shows the temperatures of its compartments (and warns when one is too warm) const temps = isCooling(f.type) ? coolingTemps(hass, f, (c) => `${formatNumber(hass, fromCelsius(hass, c), 1)} ${tempUnit(hass)}`) : null; // a home battery with only its charge, a wallbox with only its status, a fridge with only its thermometer still gets its marker // any other device: its own thermometer (an inverter, a battery, a PC; #112) beside what it shows const deviceTemp = !isCooling(f.type) ? deviceTempOf(hass, f.temp_entity) : null; const deviceTempText = deviceTemp === null ? "" : `🌡 ${formatNumber(hass, fromCelsius(hass, deviceTemp), 1)} ${tempUnit(hass)}`; const extraRef = f.type === "home_battery" ? f.soc : f.type === "wallbox" ? f.status : temps ? (f.temp_entity && f.temp_entity !== "none" ? f.temp_entity : f.temp_entity2) : deviceTemp !== null ? f.temp_entity : null; const extra = extraRef && extraRef !== "none" ? extraRef : (f.values ?? []).find((v) => v.entity && v.entity !== "none")?.entity ?? null; const link = linked ?? (extra ? { entity: null, power: null } : undefined); if (!link) continue; // a battery goes by its charge first: its power sensor is often placed on its own as well const id = (f.type === "home_battery" ? (extra ?? link.entity ?? link.power) : (link.entity ?? link.power ?? extra))!; targets.set(f.id, id); const st = link.entity ? hass.states[link.entity] : undefined; // the meter's sensor is the grid (+ = import), the battery's can point the other way as well; // a sub-meter (advanced energy mode) measures its branch (+ = drawn) with its own sign const sub = subMeters.has(f.id); const invert = sub ? !!f.meter_invert : f.type === "meter" ? b.energy.grid_invert && !f.export : f.type === "home_battery" ? b.energy.battery_invert && !f.charge : false; let power = link.power ? readPower(hass.states[link.power], invert) : null; // separate second sensors: a battery's charging, a meter's export (then the first one is unsigned) const second = (f.type === "home_battery" && f.charge && f.charge !== "none" ? f.charge : f.type === "meter" && !sub && f.export && f.export !== "none" ? f.export : null) as string | null; const secondW = second ? readPower(hass.states[second]) : null; if (secondW !== null) power = Math.max(0, power ?? 0) - Math.max(0, secondW); if (link.power && power !== null && !consumerSensors.has(link.power)) { consumerSensors.add(link.power); consumers.push({ id, powerEntity: link.power, floorId: floor.id, x: f.x, z: f.z, power: Math.max(0, power), wallbox: f.type === "wallbox" || undefined }); } const running = (power ?? 0) > 10 || st?.state === "on" || st?.state === "running" || (isStatusSensor(st) && isActive(st)); if ((f.type === "radiator" || plate) && st && kindOf(st.entity_id) === "climate") { // glows while it heats; brighter the further the room is below its target. A pack item glows on its screen // part (a thermostat's display), or as a whole when it has none (a towel radiator) const a = st.attributes; if (a.hvac_action === "heating") { const gap = typeof a.temperature === "number" && typeof a.current_temperature === "number" ? a.temperature - a.current_temperature : 1; const heat = !!plate && !plate.parts.some((p) => p.screen); screens.set(f.id, { color: [1, 0.42, 0.1], level: Math.min(1, 0.45 + 0.25 * Math.max(0, gap)), heat: heat || undefined }); } } else if ((f.type === "washer" || f.type === "dryer" || f.type === "dishwasher") && running) { screens.set(f.id, { color: [0.3, 0.85, 1], level: 0.8 }); } else if (plate && running && !plate.light && plate.parts.some((p) => p.glow || p.screen)) { // any other electric pack item that runs: its status lights and display light up, like an appliance's screens.set(f.id, { color: [0.3, 0.85, 1], level: 0.8, leds: true }); } // a 3D printer that prints: the print grows on its bed, in the colour of its filament if (isPrinter3d(f.type)) { const pr = readPrinter(hass, link.entity ?? link.power); if (pr && pr.progress !== null && (pr.printing || /pause/.test(pr.status))) { const hex = pr.filaments[0] ?? "#38bdf8"; const rgb = [1, 3, 5].map((k) => parseInt(hex.slice(k, k + 2), 16) / 255) as [number, number, number]; screens.set(f.id, { color: rgb, level: 0.9, print: Math.max(0.02, pr.progress / 100) }); } } // a home battery shows its charge on its own front: a bar that fills, green when full, red when nearly empty if (f.type === "home_battery" && extra) { const soc = Number(hass.states[extra]?.state); if (Number.isFinite(soc)) screens.set(f.id, { color: soc > 60 ? [0.29, 0.87, 0.5] : soc > 25 ? [0.98, 0.8, 0.08] : [0.97, 0.44, 0.44], level: 0.95, fill: soc / 100 }); } if (st && hasScreen(f.type)) { // a screen is lit or dark (what plays on it is drawn by NextFloor's TV screens); a light (an aquarium, // a lit panel) glows in its own colour, other entities in the neon cyan const lit = kindOf(st.entity_id) === "light" ? lightGlow(st) : null; // many TV integrations (Samsung, LG) only report "on", never "playing": on is lit, dimmed const tvOn = kindOf(st.entity_id) === "media" && ["playing", "on", "paused", "idle"].includes(st.state); const color = lit ? lit.color : isActive(st) || tvOn ? ([0.22, 0.88, 1] as [number, number, number]) : null; if (color) screens.set(f.id, { color, level: st.state === "playing" ? 1 : 0.6, halo: f.ambilight ?? 1 }); } if (taken.has(id)) continue; taken.add(id); const kind = link.entity ? kindOf(link.entity) : null; const room = floor.rooms.find((r) => r.points.length >= 3 && pointInPolygon([f.x, f.z], r.points)); markers.push({ id, floorId: floor.id, roomId: room?.id ?? null, x: f.x, z: f.z, y: markerHeight(f) + mountBase(floor, f), icon: f.icon ? mdiIcon(f.icon) : iconSvg(kind ?? "switch"), name: f.name || (link.entity ? entityName(hass, link.entity) : furnitureName(hass, f.type)), ownName: f.name || undefined, showName: !!f.show_name, text: [ temps ? temps.text : f.type === "home_battery" ? this.batteryText(hass, extra, power) : f.type === "wallbox" ? this.wallboxText(hass, extra, power) : f.type === "meter" ? sub ? (power === null ? "" : formatPower(hass, power)) : this.meterText(hass, power) : st && (f.type === "washer" || f.type === "dryer" || f.type === "dishwasher") && running && remainingMinutes(hass, deviceSiblings(hass, link.entity ?? link.power)) !== null ? translate(hass, "care_time_left", { time: minutesText(remainingMinutes(hass, deviceSiblings(hass, link.entity ?? link.power))!) }) : st ? // every device with a power sensor shows its draw beside its state, the same way [stateText(hass, st), power !== null && power > 5 && !isStatusSensor(st) ? formatPower(hass, power) : ""].filter(Boolean).join(" · ") : power !== null ? formatPower(hass, Math.max(0, power)) : "", deviceTempText, deviceValuesText(hass, f.values), ] .filter(Boolean) .join(" · "), active: temps?.warm || (deviceTemp !== null && deviceTemp >= DEVICE_HOT) || (st ? isActive(st) : (power ?? 0) > 5), unavailable: st ? isUnavailable(st) : false, glow: null, // its pin grabs the item when furnishing furnitureId: f.id, // inverter, battery, wallbox: their own text (watts, charge, status) is always worth a pin energyDevice: f.type === "inverter" || f.type === "home_battery" || f.type === "wallbox" || f.type === "meter", // a fridge's temperatures are worth a pin, like an energy device's values readout: !!temps || !!f.values?.some((v) => v.entity && v.entity !== "none") || undefined, show: f.marker ?? undefined, fromFurniture: true, }); } } // the Wi-Fi map: an access point's reach as a disc on the floor (through walls), its pin tells its devices const wifi = this.heatMode === "wifi"; for (const m of markers) { const f = m.furnitureId ? b.floors.flatMap((fl) => fl.furniture).find((x) => x.id === m.furnitureId) : undefined; if (!f || !isAccessPoint(f.type)) continue; const ap = readAccessPoint(hass, this.furnitureLinks.get(f.id)?.entity ?? this.furnitureLinks.get(f.id)?.power ?? null); if (!ap) continue; if (ap.clients !== null) m.text = translate(hass, "wifi_clients", { n: ap.clients }); if (wifi) { m.wedge = { angle: 360, reach: 9, near: 0, color: coverageColor(ap), opacity: 0.4, through: true, walls: false }; m.show = "always"; } } // an item with its own tap action shows what it shows as usual; a tap on it or on its pin runs the action const own = ownTaps(b, markers); for (const f of b.floors.flatMap((fl) => fl.furniture)) if (isHydronic(f.type)) targets.set(f.id, `hydronic:${f.id}`); this.tapPins = own.pins; for (const f of b.floors.flatMap((fl) => fl.furniture)) if (f.tap?.action) targets.set(f.id, `tap:${f.id}`); // one without a pin of its own gets one above it, like a device's, that does the same for (const { floor, item: f } of own.bare) { const room = floor.rooms.find((r) => r.points.length >= 3 && pointInPolygon([f.x, f.z], r.points)); const name = f.name || furnitureName(hass, f.type); markers.push({ id: `tap:${f.id}`, floorId: floor.id, roomId: room?.id ?? null, x: f.x, z: f.z, y: markerHeight(f) + mountBase(floor, f), icon: mdiIcon(f.icon || "gesture-tap-button"), name, ownName: f.name || undefined, showName: !!f.show_name, text: "", active: false, unavailable: false, glow: null, furnitureId: f.id, show: f.marker ?? undefined, fromFurniture: true }); } return { markers, consumers, screens, targets }; } /** * Furniture a robot vacuum drives around: what stands on the floor of the room (cabinets, sofas, * beds, appliances). It drives under tables, desks, chairs and stools, over rugs and under anything * hung on the wall. */ private robotObstacles(floor: Building["floors"][number], room: [number, number][]): [number, number][][] { const OPEN_BELOW = new Set(["rug", "worktop", "table", "table_round", "coffee_table", "chair", "office_chair", "stool", "bar_stool", "bench", "desk", "robot_vacuum", "parking", "stairwell", "radiator", "tv_wall", "kitchen_wall", "led_strip"]); return floor.furniture .filter((m) => { if (OPEN_BELOW.has(m.type) || (m.type.startsWith("lamp_") && m.type !== "lamp_floor" && m.type !== "lamp_uplight")) return false; if (m.h < 0.04 || mountBase(floor, m) > 0.12) return false; const item = packItem(m.type); if (item && (item.hole || /table|desk|chair|stool|bench|rug|carpet|mat$/.test(m.type))) return false; return pointInPolygon([m.x, m.z], room) || furnitureFootprint(m).some((p) => pointInPolygon(p, room)); }) .map((m) => furnitureFootprint(m)); } /** Robot vacuums (docks with a vacuum entity): where they rest and what they do. */ private robotInfos(hass: HomeAssistant, b: Building): RobotInfo[] { const out: RobotInfo[] = []; // the robot's own map: a camera that describes one, and the two places that tie its grid to the plan const camera = mapCamera(hass); const live = readVacuum(hass, camera, b.settings.vacuum_map ?? null); let liveTaken = false; for (const floor of b.floors) { for (const f of floor.furniture) { if (f.type !== "robot_vacuum") continue; const entity = this.furnitureLinks.get(f.id)?.entity ?? null; const state = entity ? hass.states[entity]?.state : undefined; const mode: RobotInfo["mode"] = state === "cleaning" ? "cleaning" : state === "returning" ? "returning" : state === "error" ? "error" : state === "docked" || !state ? "docked" : "idle"; // the robot rests in front of its dock, facing away from it const a = (f.rotation * Math.PI) / 180; const off = f.d * 0.14; const rest: [number, number] = [f.x - Math.sin(a) * off, f.z + Math.cos(a) * off]; // the room the robot reports (a "current room" sensor), else the room of its dock const rooms = floor.rooms.filter((r) => r.points.length >= 3); const reported = mode === "cleaning" ? robotRoom(hass, rooms, entity, robotRoomSensor(hass, entity, f.room_sensor)) : null; const room = reported ?? rooms.find((r) => pointInPolygon(rest, r.points)); const obstacles = mode === "cleaning" && room ? this.robotObstacles(floor, room.points) : []; // the first robot vacuum takes the map the camera describes: it shows where that robot really is // and where it has been, instead of the lanes this view invents for the room // a robot map is only as current as the last frame something asked of the camera: while it cleans, a // pose from minutes ago would nail it to the wrong spot for good, so an old one is not used at all const seenAt = camera ? Date.parse(hass.states[camera]?.last_updated ?? "") : Number.NaN; const fresh = !Number.isFinite(seenAt) || Date.now() - seenAt < 2 * 60 * 1000; const own = entity?.startsWith("vacuum.") && live && !liveTaken && (fresh || (mode !== "cleaning" && mode !== "returning")) ? live : null; if (own) liveTaken = true; // when it stopped cleaning: its pad fades ten minutes later, so a finished clean does not lie on the // floor all day — the timeline is where the day stays const stoppedAt = entity ? Date.parse(hass.states[entity]?.last_changed ?? "") : Number.NaN; const settledAt = mode === "cleaning" || mode === "returning" ? null : Number.isFinite(stoppedAt) ? stoppedAt : null; out.push({ id: f.id, floorId: floor.id, rest, restHeading: -a, mode, room: room?.points ?? null, roomId: room?.id ?? null, obstacles, track: own?.path ?? null, pose: own?.pose ?? null, settledAt, }); } // robot mowers: a mower or its dock from the packs linked to a lawn_mower; it mows lanes over its lawn for (const f of floor.furniture) { if (!/:(robot_mower|mower_dock)$/.test(f.type)) continue; const entity = this.furnitureLinks.get(f.id)?.entity ?? null; if (!entity?.startsWith("lawn_mower.")) continue; const state = hass.states[entity]?.state; const mode: RobotInfo["mode"] = state === "mowing" ? "cleaning" : state === "returning" ? "returning" : state === "error" ? "error" : state === "docked" || !state ? "docked" : "idle"; const rest: [number, number] = [f.x, f.z]; const lawns = (floor.outdoor ?? []).filter((o) => o.type === "lawn" && o.points.length >= 3); const lawn = lawns.find((o) => pointInPolygon(rest, o.points)) ?? [...lawns].sort((p, q) => polygonArea(q.points) - polygonArea(p.points))[0]; // what stands on the lawn: beds, ponds, pools, terraces cut out of it const obstacles = lawn ? (floor.outdoor ?? []).filter((o) => o !== lawn && o.type !== "lawn" && o.points.some((p) => pointInPolygon(p, lawn.points))).map((o) => o.points) : []; out.push({ id: f.id, floorId: floor.id, rest, restHeading: (-f.rotation * Math.PI) / 180, mode, room: lawn?.points ?? null, roomId: lawn?.id ?? null, obstacles, y: lawn ? outdoorTopAt(floor, lawn, rest[0], rest[1]) : groundLevel(floor), mower: true }); } } return out; } /** Home battery: "64 % · ▲ 1,5 kW" (▲ charging, ▼ discharging; its power sensor counts discharging positive). */ private batteryText(hass: HomeAssistant, soc: string | null, power: number | null): string { const v = soc ? Number(hass.states[soc]?.state) : Number.NaN; const parts: string[] = []; if (Number.isFinite(v)) parts.push(`${formatNumber(hass, v, 0)} %`); if (power !== null && Math.abs(power) >= 10) parts.push(`${power < 0 ? "▲" : "▼"} ${formatPower(hass, Math.abs(power))}`); return parts.join(" · "); } /** A sub-meter with "show unmetered" on: what its floors use, and how much of it no placed device measures. */ private subMeterText(hass: HomeAssistant, b: Building, summary: EnergySummary, furnitureId: string | undefined): string | null { const label = furnitureId ? subMeterLabel(b, summary, furnitureId) : null; if (!label) return null; return formatPower(hass, label.use) + (label.unmetered === null ? "" : ` · ${translate(hass, "meter_unmetered", { w: formatPower(hass, label.unmetered) })}`); } /** Wallbox: "lädt · 11 kW", "angesteckt" or its power, from a status sensor (on/off or a state such as charging). */ /** The meter: what the house draws from the grid, or feeds into it. */ private meterText(hass: HomeAssistant, power: number | null): string { if (power === null) return ""; if (Math.abs(power) < 5) return formatPower(hass, 0); return `${translate(hass, power < 0 ? "energy_grid_export" : "energy_grid_import")} ${formatPower(hass, Math.abs(power))}`; } private wallboxText(hass: HomeAssistant, status: string | null, power: number | null): string { const st = status ? hass.states[status] : undefined; const raw = String(st?.state ?? "").toLowerCase(); const charging = (power ?? 0) > 50 || /charg|laden|lädt/.test(raw); const plugged = st?.entity_id.startsWith("binary_sensor.") ? raw === "on" : /connect|plug|ready|angesteckt|verbunden|wait|paused|suspend/.test(raw); const label = charging ? translate(hass, "wallbox_charging") : plugged ? translate(hass, "wallbox_plugged") : st && !isUnavailable(st) && !st.entity_id.startsWith("binary_sensor.") ? stateText(hass, st) : ""; const watts = power !== null && power > 50 ? formatPower(hass, power) : ""; return [label, watts].filter(Boolean).join(" · "); } /** The glowing faces of an item with a state entity (none while nothing is on). */ private stateFaces(hass: HomeAssistant, f: Furniture): NonNullable { const out: NonNullable = []; const refs: [EntityRef | undefined, "all" | "left" | "right" | "top" | "bottom"][] = f.state_entity2 && f.state_entity2 !== "none" ? [ [f.state_entity, f.state_split === "top_bottom" ? "bottom" : "left"], [f.state_entity2, f.state_split === "top_bottom" ? "top" : "right"], ] : [[f.state_entity, "all"]]; for (const [ref, part] of refs) { if (!ref || ref === "none") continue; const st = hass.states[ref]; if (!st || isUnavailable(st)) continue; const on = isActive(st) || st.state === "home" || st.state === "occupied" || st.state === "on"; if (!on) continue; const lit = kindOf(ref) === "light" ? lightGlow(st) : null; out.push({ part, color: lit ? lit.color : [1, 0.71, 0.28], level: lit ? lit.level : 0.85 }); } return out; } /** The pin of a household item: when the bin is collected, whether there is post, how dry a plant is; and its glow when it is due. */ private careMarker(hass: HomeAssistant, floor: Building["floors"][number], f: Furniture, care: "bin" | "mail" | "plant", entity: string): { marker: DeviceMarker & { fromFurniture: boolean; care: boolean }; glow: [number, number, number] | null } | null { const st = hass.states[entity]; if (!st) return null; let text = ""; let due = false; let glow: [number, number, number] | null = null; if (care === "bin") { const days = pickupDays(st); text = days === null ? stateText(hass, st) : days === 0 ? translate(hass, "care_bin_today") : days === 1 ? translate(hass, "care_bin_tomorrow") : translate(hass, "care_bin_days", { n: days }); due = days !== null && days <= 1; if (due) glow = [1, 0.72, 0.28]; } else if (care === "mail") { due = hasPost(st); text = translate(hass, due ? "care_mail_yes" : "care_mail_no"); if (due) glow = [1, 0.85, 0.3]; } else { const thirst = plantThirst(st, f.thirsty_below ?? 20); due = !!thirst?.thirsty; text = thirst ? (Number.isFinite(thirst.moisture) ? `${translate(hass, due ? "care_plant_thirsty" : "care_plant_ok")} · ${Math.round(thirst.moisture)} %` : translate(hass, due ? "care_plant_thirsty" : "care_plant_ok")) : stateText(hass, st); if (due) glow = [1, 0.45, 0.3]; } const room = floor.rooms.find((r) => r.points.length >= 3 && pointInPolygon([f.x, f.z], r.points)); const icon = { bin: "mdi:trash-can-outline", mail: "mdi:mailbox-outline", plant: "mdi:sprout-outline" }[care]; return { glow, marker: { id: entity, floorId: floor.id, roomId: room?.id ?? null, x: f.x, z: f.z, y: markerHeight(f) + mountBase(floor, f), icon: f.icon ? mdiIcon(f.icon) : mdiIcon(icon), name: f.name || furnitureName(hass, f.type), ownName: f.name || undefined, showName: !!f.show_name, text, active: due, unavailable: isUnavailable(st), glow: null, furnitureId: f.id, show: f.marker ?? undefined, fromFurniture: true, care: true, }, }; } /** A lamp: its 3D model glows with the linked light and is tapped directly. */ private lampMarker(hass: HomeAssistant, floor: Building["floors"][number], f: Furniture, entity: string | null): DeviceMarker & { fromFurniture: boolean; readout?: boolean } { const st = entity ? hass.states[entity] : undefined; // further bulbs of the same fixture (a night light, an ambient ring): the lamp glows with them while its main light is off const others = (f.extra_lights ?? []).map((id) => hass.states[id]).filter((s): s is HassEntity => !!s); const otherOn = others.find((s) => isActive(s)); const item = packItem(f.type); const model = LAMP_MODEL[f.type] ?? item?.light ?? "floor"; // a height above the floor set by hand wins (a table lamp on a shelf, a floor lamp on a platform); // an LED strip outside the house counts from the ground there (a path light flush with the lawn) const inRoom = floor.rooms.some((r) => r.points.length >= 3 && pointInPolygon([f.x, f.z], r.points)); const base = model === "strip" && !inRoom ? outdoorGround(floor, f.x, f.z) + (f.mount_y ?? 0) : f.mount_y != null && !item ? f.mount_y : item || model === "wall" || model === "strip" ? mountBase(floor, f) : model === "table" ? surfaceHeight(floor, f.x, f.z) : model === "bollard" || model === "garden" ? outdoorGround(floor, f.x, f.z) : 0; const room = floor.rooms.find((r) => r.points.length >= 3 && pointInPolygon([f.x, f.z], r.points)); // hanging lamps hang from the ceiling right above them: the room's own, or one set on the lamp (a sloping ceiling) const H = ceilingOf(floor, f); // pack lamps: the marker sits above the lamp (below it when it hangs from the ceiling) const y = item ? item.mount === "ceiling" ? Math.max(0.5, base - 0.15) : base + f.h + 0.2 : { ceiling: H - 0.3, downlight: H - 0.25, spot: H - 0.35, panel: H - 0.25, pendant: Math.max(0.6, H - f.h - 0.25), fan: Math.max(0.6, H - f.h - 0.2), floor: base + f.h + 0.25, uplight: base + f.h + 0.25, table: base + f.h + 0.2, wall: base + f.h + 0.2, strip: f.upright ? base + f.w + 0.15 : Math.max(0.3, base - 0.2), bollard: base + f.h + 0.25, garden: base + f.h + 0.25, }[model]; const marker: DeviceMarker & { fromFurniture: boolean; readout?: boolean } = { // a lamp without a light keeps a key of its own (it is drawn, but not tappable) id: entity ?? `lamp:${f.id}`, floorId: floor.id, roomId: room?.id ?? null, x: f.x, z: f.z, y, icon: iconSvg("light"), name: f.name || (entity ? entityName(hass, entity) : furnitureName(hass, f.type)), text: [st && (isActive(st) || !otherOn) ? stateText(hass, st) : otherOn ? entityName(hass, otherOn.entity_id) : "", deviceValuesText(hass, f.values)].filter(Boolean).join(" · "), readout: !!f.values?.some((v) => v.entity && v.entity !== "none"), active: (st ? isActive(st) : false) || !!otherOn, unavailable: st ? isUnavailable(st) : false, glow: st || others.length ? scaleGlow(fixtureGlow(st, others, f.color_entity && f.color_entity !== "none" ? hass.states[f.color_entity] : undefined), f.glow_scale) : null, lamp: model, rotation: f.rotation, mirror: !!f.mirror, roll: f.tilt ?? 0, upright: !!f.upright, rise: f.rise ?? 0, size: [f.w, f.d, f.h], base, pickable: !!entity, furnitureId: f.id, pack: item ? f.type : null, lightY: item ? (item.mount === "ceiling" ? base : base + f.h * 0.85) : undefined, ceiling: H, effect: st?.state === "on" ? lightAnimation(f, lightEffectSource(hass, f, entity)) : undefined, variant: f.variant, show: f.marker ?? undefined, fromFurniture: true, }; return st && entity ? withPluginPatch(hass, marker, st, false) : marker; } /** * Marker rule: "important" leaves out devices that their 3D object stands for (lamps, a TV that is * off) and keeps devices without an object (sensors, heating, switches) and values (watts, the app). */ private showPin(m: DeviceMarker & { fromFurniture?: boolean; energyDevice?: boolean; care?: boolean; readout?: boolean }): boolean { // while furnishing every placed device has a pin to grab it by if (this.furnish && !m.fromFurniture) return true; // the device's own setting wins over the marker mode (except "none", which hides every marker) if (m.show === "never" || this.markerMode === "none") return false; if (m.show === "always") return true; // only while it is on: a motion sensor while it detects, a door while it is open if (m.show === "active" || (this.building?.settings.motion_markers_active && isMotionSensor(this.hass, m.id))) { if (!m.active) return false; if (m.show === "active") return true; } // outside the opened room (the house, a floor, another room): the kinds chosen in the card if (this.markersOutside && !(this.roomId && m.roomId === this.roomId)) return this.markersOutside.includes(markerKind(m.id, !!m.lamp)); if (this.markerMode === "all") return true; if (m.lamp) return false; const kind = kindOf(m.id); if (kind === "light") return false; // a ceiling fan's pin is how it is switched (its blades belong to the light kit) if (m.fromFurniture && kind === "fan") return true; // a bin to put out, post in the box, a thirsty plant: important while it is due if (m.care) return m.active; // an item with its own tap action: its pin is the way to find it if (m.id.startsWith("tap:")) return true; // values worth reading (a fridge's temperatures) if (m.readout) return true; if (m.fromFurniture) return (m.power ?? 0) >= 1 || (kind === "media" && m.active) || (!!m.energyDevice && !!m.text); return true; } /** Tapping a window opens its blind (or contact); a door or garage door its cover or contact. */ private openingTargets(): Map { const out = new Map(); for (const [id, e] of this.openingLinks ?? []) { // a door with a smart lock is tapped to lock or unlock it const target = e.lock ?? e.cover ?? e.contact ?? e.tilt; if (target) out.set(id, target); } return out; } /** The second blind of an opening whose tap opens its first one: the right half of the opening is tapped for it. */ /** Saves the house as an STL file for 3D printing (1:100, millimetres). */ downloadStl(): void { const bytes = this.viewer?.exportStl(10); if (!bytes) return; const url = URL.createObjectURL(new Blob([bytes as BlobPart], { type: "model/stl" })); const a = document.createElement("a"); a.href = url; a.download = `nextfloor-${new Date().toISOString().slice(0, 10)}.stl`; a.click(); setTimeout(() => URL.revokeObjectURL(url), 5000); } private secondBlinds(): Map { const out = new Map(); for (const [id, e] of this.openingLinks ?? []) if (e.cover2 && !e.lock && e.cover) out.set(id, e.cover2); return out; } /** Pictures of the floors, drawn a moment after the plan or the look changed (once, not per frame). */ private scheduleThumbs(delay = 600): void { clearTimeout(this.thumbTimer); const floors = this.building?.floors.filter((f) => f.rooms.length).length ?? 0; if (!this.floorThumbs || (!this.building?.topology && floors < 2)) { this._thumbs = []; return; } // at most every few seconds, however often lamps change (the tablet level waits longer) const wait = this.building?.topology ? delay : Math.max(delay, this.thumbsAt + (this._low ? 8000 : 4000) - Date.now()); this.thumbTimer = setTimeout(() => { // at night (kiosk) the pictures are drawn once and then rest if (!this.viewer || (this.dimmed && this._thumbs.length)) return; // a hidden tab draws nothing; the pictures follow once it shows again if (document.hidden) { this.scheduleThumbs(3000); return; } this.thumbsAt = Date.now(); if(this.building?.topology){ const nodes=topologyItems(this.building,this.topologyFocus); for(const t of this.viewer.scopeThumbnails(nodes,this.narrowThumbs?104:150,this.narrowThumbs?78:112))this.topologyImages.set(t.key,t.url); this.requestUpdate(); }else this._thumbs = this.viewer.floorThumbnails(this.narrowThumbs ? 104 : 150, this.narrowThumbs ? 78 : 112); }, wait); } private get narrowThumbs(): boolean { return this._narrowStage; } private renderThumbs() { if(this.floorThumbs&&this.building?.topology){ return topologyNavigation(this.building,this.topologyFocus,this.topologyImages,(s)=>this.fire("topology-tap",s),this._thumbsCompact,()=>{this._thumbsCompact=!this._thumbsCompact;try{localStorage.setItem("nextfloor.thumbs_compact",this._thumbsCompact?"1":"0");}catch{}},this.narrowThumbs,this._shortStage); } if (!this._thumbs.length || !this.building || this._phoneStage) return nothing; const names = new Map(this.building.floors.map((f) => [f.id, f.name])); // the highest floor on top const order = [...this._thumbs].sort( (a, b) => (this.building!.floors.find((f) => f.id === b.floorId)?.elevation ?? 0) - (this.building!.floors.find((f) => f.id === a.floorId)?.elevation ?? 0), ); const compact = this._thumbsCompact; const fold = () => { this._thumbsCompact = !compact; try { localStorage.setItem("nextfloor.thumbs_compact", this._thumbsCompact ? "1" : "0"); } catch { // private mode: the choice lasts for this page only } }; return html``; } /** Long press: the quick menu at the device, or the details for devices without one. */ private onDeviceHold(entityId: string, x: number, y: number): void { const kind = kindOf(entityId); if (kind === "light" || kind === "cover" || kind === "switch" || kind === "fan" || kind === "lock") this._menu = { entity: entityId, x, y }; else openMoreInfo(this, entityId); } /** Swipe up or down on a lamp (brightness) or a blind (position). */ private onDeviceSwipe(entityId: string, phase: "start" | "move" | "end", dy: number, x: number, y: number): boolean { const st = this.hass?.states[entityId]; if (phase === "start") { // devices that ask before switching are not moved by a swipe (it turns the view instead) if (!st || isUnavailable(st) || !canControl(this.hass, entityId) || this.confirmSet.has(entityId)) return false; const kind = kindOf(entityId); if (kind === "light" && lightAbilities(st).dim) { const pct = st.state === "on" ? (typeof st.attributes.brightness === "number" ? Math.round((st.attributes.brightness as number) / 2.55) : 100) : 0; this._swipe = { entity: entityId, kind: "light", start: pct, value: pct, x, y }; return true; } // a fan with speeds: up = faster, down to 0 = off if (kind === "fan" && typeof st.attributes.percentage_step === "number") { const pct = st.state === "on" && typeof st.attributes.percentage === "number" ? st.attributes.percentage : 0; this._swipe = { entity: entityId, kind: "fan", start: pct, value: pct, x, y }; return true; } if (kind === "cover" && coverPositionable(st)) { const pos = st.attributes.current_position as number; this._swipe = { entity: entityId, kind: "cover", start: pos, value: pos, x, y }; return true; } return false; } const s = this._swipe; if (!s || s.entity !== entityId) return false; if (phase === "move") { // the whole range over about 220 pixels; up = brighter / blind up const value = Math.round(Math.min(100, Math.max(0, s.start - (dy / 220) * 100))); if (value !== s.value) this._swipe = { ...s, value }; // at most a few calls per second while the finger moves const now = performance.now(); if (now - this.swipeSent > 350) { this.swipeSent = now; this.applySwipe(); } } else { this.applySwipe(); clearTimeout(this.swipeTimer); this.swipeTimer = setTimeout(() => (this._swipe = null), 700); } return true; } private applySwipe(): void { if (this._swipe && !canControl(this.hass, this._swipe.entity)) return; const s = this._swipe; if (!s || !this.hass) return; if (s.kind === "light") { if (s.value <= 0) void this.hass.callService("light", "turn_off", { entity_id: s.entity }); else void this.hass.callService("light", "turn_on", { entity_id: s.entity, brightness_pct: s.value }); } else if (s.kind === "fan") { if (s.value <= 0) void this.hass.callService("fan", "turn_off", { entity_id: s.entity }); else void this.hass.callService("fan", "set_percentage", { entity_id: s.entity, percentage: s.value }); } else void this.hass.callService("cover", "set_cover_position", { entity_id: s.entity, position: s.value }); } /** Fly to a search result: rooms are selected, devices shown on their floor and flashing. */ /** Opens a room, on another floor too: the floor first, then the room (the host opens one step per tap). */ private openRoom(floorId: string, roomId: string): void { if (this.floorId === floorId && this.roomId === roomId) return; if (this.floorId !== floorId) { this.fire("floor-tap", { floorId }); setTimeout(() => this.fire("room-tap", { floorId, roomId }), 60); } else this.fire("room-tap", { floorId, roomId }); } private goTo(item: SearchItem): void { this._find = null; if (item.kind === "room" || item.kind === "circuit") { if (item.roomId) this.openRoom(item.floorId, item.roomId); return; } if (this.floorId !== item.floorId) this.fire("floor-tap", { floorId: item.floorId }); // after the host has switched the floor (its own camera flight starts first) setTimeout(() => this.viewer?.focus(item.floorId, item.x, item.z, item.y, item.entity), 120); } /** Start or stop hearing announcements (once per view; Home Assistant subscribes again after a reconnect by itself). */ private listenToAnnouncements(on: boolean): void { if (!on) { this.stopAnnouncements?.(); this.stopAnnouncements = null; clearTimeout(this.announceTimer); return; } if (this.stopAnnouncements) return; // a placeholder until the subscription stands, so a second update does not subscribe twice let stopped = false; this.stopAnnouncements = () => (stopped = true); void subscribeAnnouncements(this.hass, (a) => this.announce(a)).then((stop) => { if (stopped) stop(); else this.stopAnnouncements = stop; }); } /** An announcement arrived: show it big over the house, chime and speak it (once per page, only if meant for this screen). */ private announce(a: Announcement): void { // the action nextfloor.reload_screens: load the page again, some seconds apart so the tablets do not all fetch at once const reload = a as unknown as { reload?: boolean; template?: string | null }; if (reload?.reload === true) { if (!reload.template || reload.template === this.templateName) setTimeout(() => location.reload(), 500 + Math.random() * 6000); return; } // only a real announcement (a message to say); anything else on the subscription is ignored if (typeof a?.message !== "string" || !a.message.trim()) return; if (!forThisScreen(a, this.screenName) || !claim(a)) return; const duration = showFor(a.message); this._announcement = { message: a.message, until: Date.now() + duration }; clearTimeout(this.announceTimer); this.announceTimer = setTimeout(() => (this._announcement = null), duration); void playAnnouncement(this.hass, a); } private renderAnnouncement() { const a = this._announcement; if (!a) return nothing; return html``; } private renderAlerts() { const b = this.building; if (!this._alerts.length || !b) return nothing; const shown = this._alerts.slice(0, 3); return html``; } /** Scenes and scripts of the selected room's area as chips (while no panel lists them). */ private renderScenes() { const b = this.building; if (!this.scenes || !this.roomId || this.panelOpen || !b || !this.hass) return nothing; const room = b.floors.flatMap((f) => f.rooms).find((r) => r.id === this.roomId); const ids = room ? roomEntities(this.hass, room).filter((id) => kindOf(id) === "scene" || kindOf(id) === "script").slice(0, 6) : []; if (!ids.length) return nothing; const areaName = room?.area_id ? this.hass.areas?.[room.area_id]?.name : undefined; return html`
${ids.map((id) => html``)}
`; } private renderFind() { const b = this.building; if (!b || !this.hass) return nothing; if (this._find === null) { return html``; } const results = searchItems((this.findIndex ??= searchIndex(this.hass, b)), this._find); return html`
(this._find = (e.target as HTMLInputElement).value)} @keydown=${(e: KeyboardEvent) => { if (e.key === "Escape") this._find = null; if (e.key === "Enter" && results[0]) this.goTo(results[0]); }} /> ${this._find.trim() ? html`
${results.length ? results.map( (it) => html``, ) : html`

${translate(this.hass, "find_none")}

`}
` : nothing}
`; } /** * The star: a small menu for the floor shown (or the whole house) with all lights on / off, all blinds * up / down and the house's favourites (#145). House-wide actions want a second tap. */ private renderCentral() { const b = this.building; const hass = this.hass; if (!b || !hass || !this.central || this._find !== null) return nothing; const t = (k: I18nKey, vars?: Record) => translate(hass, k, vars); const star = html``; if (!this._central) return star; const floor = this.floorId ? b.floors.find((f) => f.id === this.floorId) : undefined; const floors = floor ? [floor] : b.floors; const lights = floors.flatMap((f) => floorControls(hass, f).lights).filter((id) => canControl(hass, id)); const covers = floors.flatMap((f) => floorControls(hass, f).covers).filter((id) => canControl(hass, id)); const lightsOn = lights.filter((id) => hass.states[id]?.state === "on").length; const house = !floor; // house-wide: the first tap arms the button ("sure?"), the second runs it const act = (key: string, domain: string, service: string, ids: string[]) => { if (!ids.length) return; if (house && this._armed !== key) { this._armed = key; clearTimeout(this.armTimer); this.armTimer = setTimeout(() => (this._armed = null), 3500); return; } this._armed = null; void hass.callService(domain, service, { entity_id: ids }); }; const button = (key: string, label: I18nKey, domain: string, service: string, ids: string[]) => html``; const onFloor = b.settings.favorite_floors ?? {}; const favorites = (b.settings.favorites ?? []).filter((id) => hass.states[id] && (!onFloor[id] || !floor || onFloor[id] === floor.id)); const own = this.buttons ?? b.settings.buttons ?? []; return html`${star} `; } /** The eye: one tap hides every bar and overlay so only the stage remains, the next brings them back. */ private toggleLock(): void { this._locked = !this._locked; try { localStorage.setItem(LOCK_KEY, this._locked ? "1" : "0"); } catch { // without storage the lock lasts until the page reloads } } /** Opens time travel over the last `hours` (24 or 168) at its start, or closes it and shows the house live again. */ private async openTravel(hours: number | null): Promise { clearInterval(this.travelTimer); this.travelTimer = undefined; if (hours === null || !this.hass) { this._travel = null; this.syncDevices(true); return; } const to = Date.now(); const from = to - hours * 3600_000; this._travel = { history: new Map(), from, to, t: from, playing: false, speed: hours > 24 ? 3600 : 600, hours, moments: [], loading: true }; try { const history = await loadHistory(this.hass, replayable(this.watched), from, to); if (!this._travel || this._travel.from !== from) return; this._travel = { ...this._travel, history, moments: changeMoments(history, from, to), loading: false }; } catch { this._travel = null; this._error = translate(this.hass, "travel_failed"); return; } this.syncDevices(true); } private travelTo(t: number): void { const tr = this._travel; if (!tr) return; this._travel = { ...tr, t: Math.min(tr.to, Math.max(tr.from, t)) }; this.syncDevices(true); } private playTravel(on: boolean): void { const tr = this._travel; if (!tr) return; clearInterval(this.travelTimer); this.travelTimer = undefined; this._travel = { ...tr, playing: on, t: on && tr.t >= tr.to ? tr.from : tr.t }; if (!on) return; this.travelTimer = setInterval(() => { const now = this._travel; if (!now) return; const t = now.t + 250 * now.speed; if (t >= now.to) this.playTravel(false); this.travelTo(t); }, 250); } private renderTravel() { if (!this.hass || this.clean) return nothing; const t = (k: I18nKey) => translate(this.hass, k); const tr = this._travel; if (!tr) { if (!this.travelButton) return nothing; return html``; } const locale = this.hass.language ?? navigator.language; const when = new Intl.DateTimeFormat(locale, { weekday: "short", hour: "2-digit", minute: "2-digit" }).format(new Date(tr.t)); const span = tr.to - tr.from || 1; const speeds: [number, I18nKey][] = [ [60, "travel_speed_min"], [600, "travel_speed_10min"], [3600, "travel_speed_hour"], ]; return html`
${tr.loading ? t("travel_loading") : when}
this.travelTo(Number((e.target as HTMLInputElement).value))} />
`; } private toggleWalk(): void { const v = this.viewer; if (!v) return; if (this._walking) { v.stopWalk(); this._walking = false; } else this._walking = v.startWalk() !== null; this._stick = null; } /** The touch stick: drag the knob up to walk, down to step back, sideways to turn. */ private stickMove(e: PointerEvent, start = false): void { const pad = e.currentTarget as HTMLElement; if (start) pad.setPointerCapture(e.pointerId); else if (!this._stick) return; const r = pad.getBoundingClientRect(); const radius = r.width / 2; let [x, y] = [(e.clientX - r.left - radius) / radius, (e.clientY - r.top - radius) / radius]; const l = Math.hypot(x, y); if (l > 1) [x, y] = [x / l, y / l]; this._stick = [x, y]; this.viewer?.setWalkStick(Math.abs(x) < 0.12 ? 0 : x, Math.abs(y) < 0.12 ? 0 : y); } private stickEnd(): void { this._stick = null; this.viewer?.setWalkStick(0, 0); } private renderWalk() { if (!this.hass || this.clean || (!this.walkButton && !this._walking)) return nothing; const t = (k: I18nKey) => translate(this.hass, k); const knob = this._stick ?? [0, 0]; return html` ${this._walking ? html`
this.stickMove(e, true)} @pointermove=${(e: PointerEvent) => this.stickMove(e)} @pointerup=${() => this.stickEnd()} @pointercancel=${() => this.stickEnd()}>

${t("walk_hint")}

` : nothing}`; } private renderLock() { if (!this.lockButton || !this.hass || this.clean) return nothing; const label = translate(this.hass, this._locked ? "lock3d_off" : "lock3d_on"); return html``; } /** The clock in its corner; top left it shares the column with the sensor and energy bar (see renderTopLeft). */ private renderClock(inColumn = false) { if (!this.clock || !this.hass || (this.clock === "top_left" && !inColumn)) return nothing; const locale = this.hass.language ?? navigator.language; const now = new Date(this._now); const time = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).format(now); const day = new Intl.DateTimeFormat(locale, { weekday: "long", day: "numeric", month: "long" }).format(now); return html``; } private renderEye() { // while the search is open its field takes the eye's place (#220) if (!this.cleanButton || !this.hass || (this._find !== null && !this.clean)) return nothing; const label = translate(this.hass, this.clean ? "controls_show" : "controls_hide"); return html``; } private renderSwipe() { const s = this._swipe; if (!s || !this.hass) return nothing; const off = s.kind === "light" && s.value <= 0; return html`
${entityName(this.hass, s.entity)} ${off ? translate(this.hass, "swipe_off") : `${s.value} %`}
`; } /** A light switch or socket was tapped: one button switches at once, several open a small list to pick from. */ private tapPlate(furnitureId: string, x: number, y: number): void { const f = this.building?.floors.flatMap((fl) => fl.furniture).find((it) => it.id === furnitureId); const ids = f ? gangEntities(f.gang_entities, packItem(f.type)?.gangs ?? 0) : []; if (ids.length === 1) return this.onDeviceTap(ids[0], x, y); if (ids.length > 1) this._plate = { ids, x, y }; } private renderPlate() { const p = this._plate; if (!p || !this.hass) return nothing; const hass = this.hass; const close = () => (this._plate = null); return html`
`; } private renderMenu() { const m = this._menu; if (!m || !this.hass) return nothing; const stage = this.renderRoot.querySelector(".nf-stage") as HTMLElement | null; const w = stage?.clientWidth ?? 800; const h = stage?.clientHeight ?? 600; const left = Math.max(8, Math.min(w - 240, m.x - 116)); const top = Math.max(8, Math.min(h - 360, m.y - 170)); return html`
(this._menu = null)}>
!p.speakers?.length || p.speakers.includes(m.entity))} ?confirmSwitch=${this.confirmSet.has(m.entity)} .myPosition=${this.myPositionOf(m.entity)} .tiltEntity=${coverTiltEntity(this.hass, this.building?.floors ?? [], m.entity)} @close=${() => (this._menu = null)} >`; } /** The favourite position of a blind (Somfy's "My") set on a window it covers, or null. */ private myPositionOf(entity: string): number | null { for (const floor of this.building?.floors ?? []) for (const o of floor.openings) { const links = this.openingLinks?.get(o.id); if (o.my_position != null && (links?.cover === entity || links?.cover2 === entity)) return o.my_position; } return null; } private onDeviceTap(entityId: string, x = 0, y = 0): void { // lamps without a light are drawn, but nothing of Home Assistant stands behind them if (entityId.startsWith("lamp:")) return; // in the past nothing is switched if (this._travel) return; if (entityId.startsWith("hydronic:")) { const item = this.building?.floors.flatMap((f) => f.furniture).find((f) => f.id === entityId.slice(9)); if (item && this.hass) void loadHydronics().then((mod) => { if (this.isConnected && this.hass) { this.hydronicModule = mod; return mod.openHydronic(this.hass, item); } }).catch((err) => { this._error = String(err); }); return; } const ownTap = entityId.startsWith("tap:") ? entityId.slice(4) : this.tapPins.get(entityId); if (ownTap) { const f = this.building?.floors.flatMap((fl) => fl.furniture).find((it) => it.id === ownTap); if (f?.tap) runButton(this.hass, this, f.tap); return; } if (this.pluginTapped(entityId)) return; if (entityId.startsWith("gang:")) return this.tapPlate(entityId.slice(5), x, y); // an outdoor area's pin opens Outside, with the devices of its area if (entityId.startsWith("outdoor:")) { this.fire("room-tap", { floorId: null, roomId: "nf-outside" }); return; } // the street end of the grid cable opens the grid sensor: the balance's, else the meter's (#223) if (entityId === "grid") { const b = this.building; const sensor = b ? (b.energy.grid ?? deviceSensors(b, (f) => this.furnitureLinks?.get(f.id)?.power ?? null).grid) : null; if (sensor) openMoreInfo(this, sensor); return; } const kind = kindOf(entityId); if (this.hass.symconObjects !== undefined && !canControl(this.hass, entityId)) { if (this.hass.states[entityId]) this._menu = { entity: entityId, x, y }; return; } // blinds have no single on/off: a tap opens their quick menu (up, positions, stop, down); speakers and TVs open theirs // (play, skip, volume, sources and the stations set for them) if (kind === "cover" || kind === "media") { this._menu = { entity: entityId, x, y }; return; } // a smart lock always asks first, whichever way it goes if (kind === "lock") { const unlocked = isUnlocked(this.hass, entityId); const name = entityName(this.hass, entityId); if (confirm(translate(this.hass, unlocked ? "lock_confirm_lock" : "lock_confirm_unlock", { name }))) void this.hass.callService("lock", unlocked ? "lock" : "unlock", { entity_id: entityId }); return; } if (kind && TOGGLE_KINDS.has(kind)) { if (this.confirmSet.has(entityId) && !confirm(translate(this.hass, "confirm_switch", { name: entityName(this.hass, entityId) }))) return; void toggleEntity(this.hass, entityId); } else openMoreInfo(this, entityId); } /** Hands a tap on a placed device to the plugins (a camera opens its live picture); true when one took it. */ private pluginTapped(entityId: string): boolean { const state = this.hass?.states[entityId]; const placement = this.placementInfo.get(entityId); if (!state || !placement) return false; const placed = this.building?.floors.find((f) => f.id === placement.floorId)?.placements.find((p) => p.entity_id === entityId); return pluginTap({ hass: this.hass, entityId, state }, placement, placed?.plugin ?? undefined, { showWindow: (node, options) => { if (node && "hass" in node) (node as Node & { hass: unknown }).hass = this.hass; this._pluginWindow = node ? { node, title: options?.title ?? "" } : null; }, moreInfo: (id) => openMoreInfo(this, id ?? entityId), }); } private renderPluginWindow() { const w = this._pluginWindow; if (!w) return nothing; return html`
e.stopPropagation()}>
${w.title}
${w.node}
`; } /** The start view: the card's own, else the one remembered in the editor. */ private startViewOf(): StartView | null { return this.startView ?? this.building?.settings.start_view ?? null; } /** The camera as it stands (for "remember this view as the start"). */ currentView(): StartView | null { return this.viewer?.currentView() ?? null; } resetView(): void { this.viewer?.resetView(); } private fire(type: string, detail: unknown): void { this.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true })); } private toggleFlows(): void { this._flows = !this._flows; try { localStorage.setItem("nextfloor.flows", this._flows ? "1" : "0"); } catch { // private mode: the choice lasts for this page only } this.syncDevices(true); } /** The floating cards (house balance; car and music follow) and the points in the plan they hang over. */ /** The cars of the parking spots: what each reports, and the point over the spot (over the car when it is there). */ /** Heat pumps in the plan whose device reports temperatures or heat. */ private liveHeatPumps(b: Building): { id: string; name: string; floorId: string; x: number; z: number; at: { floorId: string; x: number; z: number; y: number }; pump: HeatPumpInfo }[] { const hass = this.hass; if (!hass) return []; const out: ReturnType = []; for (const floor of b.floors) for (const f of floor.furniture) { if (!isHeatPump(f.type)) continue; const link = this.furnitureLinks?.get(f.id); const pump = readHeatPump(hass, link?.entity ?? link?.power ?? null); if (pump) out.push({ id: f.id, name: f.name || furnitureName(hass, f.type), floorId: floor.id, x: f.x, z: f.z, at: { floorId: floor.id, x: f.x, z: f.z, y: mountBase(floor, f) + f.h + 0.5 }, pump }); } return out; } /** 3D printers in the plan whose device reports a print (the card shows while it prints, and a while after). */ private livePrinters(b: Building): { id: string; name: string; at: { floorId: string; x: number; z: number; y: number }; printer: PrinterInfo }[] { const hass = this.hass; const out: { id: string; name: string; at: { floorId: string; x: number; z: number; y: number }; printer: PrinterInfo }[] = []; if (!hass) return out; for (const floor of b.floors) for (const f of floor.furniture) { if (!isPrinter3d(f.type)) continue; const link = this.furnitureLinks?.get(f.id); const printer = readPrinter(hass, link?.entity ?? link?.power ?? null); if (!printer || (!printer.printing && !/pause|finish|complete|error/.test(printer.status))) continue; out.push({ id: f.id, name: f.name || furnitureName(hass, f.type), at: { floorId: floor.id, x: f.x, z: f.z, y: mountBase(floor, f) + f.h + 0.5 }, printer }); } return out; } private liveCars(hass: HomeAssistant, b: Building): { spot: string; name: string; at: { floorId: string; x: number; z: number; y: number }; car: CarInfo }[] { const out: { spot: string; name: string; at: { floorId: string; x: number; z: number; y: number }; car: CarInfo }[] = []; for (const floor of b.floors) { for (const f of floor.furniture) { if (f.type !== "parking") continue; const car = readCar(hass, f); if (!car || (car.soc === null && car.range === null && car.locked === null && car.climateOn === null)) continue; const vehicle = parkedVehicle(hass, f); const veh = vehicle ? vehicleFurniture(f, vehicle) : null; const name = f.name || (vehicle ? furnitureName(hass, vehicle) : furnitureName(hass, f.type)); out.push({ spot: f.id, name, at: { floorId: floor.id, x: f.x, z: f.z, y: mountBase(floor, f) + (veh?.h ?? 0.2) + 0.6 }, car }); } } return out; } /** Media players in the plan: placed as a device, or linked to furniture (TV, speaker); their point is on top of it. */ private liveMedia(hass: HomeAssistant, b: Building): MediaNow[] { const spots: { entity: string; name: string; at: { floorId: string; x: number; z: number; y: number }; rings?: number | null }[] = []; for (const floor of b.floors) { for (const f of floor.furniture) { const e = this.furnitureLinks?.get(f.id)?.entity; if (e?.startsWith("media_player.")) spots.push({ entity: e, name: f.name || furnitureName(hass, f.type), at: { floorId: floor.id, x: f.x, z: f.z, y: mountBase(floor, f) + f.h + 0.15 }, rings: f.sound_rings }); } for (const pl of floor.placements) { if (pl.entity_id.startsWith("media_player.")) spots.push({ entity: pl.entity_id, name: pl.name || entityName(hass, pl.entity_id), at: { floorId: floor.id, x: pl.x, z: pl.z, y: (pl.y ?? 1.1) + 0.15 }, rings: pl.sound_rings }); } } return mediaNow(hass, spots); } /** Today's appointments, loaded at most every 15 minutes, and again after midnight. */ private refreshToday(b: Building): void { const hass = this.hass; const calendars = b.settings.calendars ?? []; const days = Math.max(1, Math.min(7, b.settings.today_days ?? 1)); // a new day or a new number of days loads again at once const day = `${new Date().toDateString()}|${days}`; if (!hass || !calendars.length || (Date.now() - this.todayAt < 900_000 && day === this.todayDay)) return; this.todayAt = Date.now(); this.todayDay = day; void loadToday(hass, calendars, days).then((items) => (this._todayItems = items)); } /** The forecast, asked for at most every 30 minutes, and at once when the entity or the day changes. */ private refreshForecast(b: Building): void { const hass = this.hass; const entity = b.settings.forecast && hass ? weatherEntity(hass, this.weatherEntityId ?? b.settings.weather_entity) : null; if (!hass || !entity) return; const key = `${entity}|${new Date().toDateString()}`; if (Date.now() - this.forecastAt < 1_800_000 && key === this.forecastKey) return; this.forecastAt = Date.now(); this.forecastKey = key; void loadForecast(hass, entity).then((raw) => (this._forecast = raw)); } /** The weather forecast card (#84): a row per day with the weather, high and low, and the rain. */ private renderForecast(corner: "top_left" | "top_right") { const b = this.building; const hass = this.hass; const card = b?.settings.forecast; if (!b || !hass || !card || card.corner !== corner || this.clean) return nothing; if (corner === "top_right" && (this.roomId || this.panelOpen)) return nothing; const days = forecastDays(this._forecast, Math.max(1, Math.min(7, card.days))); if (!days.length) return nothing; const entity = weatherEntity(hass, this.weatherEntityId ?? b.settings.weather_entity); const attrs = entity ? hass.states[entity]?.attributes : undefined; const unit = String(attrs?.temperature_unit ?? "°"); const rainUnit = String(attrs?.precipitation_unit ?? "mm"); const lang = hass.language ?? navigator.language; const name = new Intl.DateTimeFormat(lang, { weekday: "short" }); const deg = (v: number | null) => (v === null ? "–" : `${Math.round(v)}°`); return html`
    ${days.map( (d, i) => html`
  • ${i === 0 ? translate(hass, "today") : name.format(new Date(d.day))} ${deg(d.high)} ${deg(d.low)} ${d.rain !== null && d.rain > 0 ? `💧${d.rain.toLocaleString(lang, { maximumFractionDigits: 1 })} ${rainUnit}` : d.chance !== null && d.chance > 0 ? `💧${Math.round(d.chance)} %` : ""}
  • `, )}
`; } private renderToday(utilities: ReturnType) { const b = this.building; const hass = this.hass; // the room panel (a room, or Outside) takes the right side; the Today card would lie under it and catch its taps (#83) if (!b || !hass || this.clean || this.roomId || this.panelOpen) return nothing; const forecast = this.renderForecast("top_right"); const today = this.today === false ? nothing : this.renderTodayCard(b, hass); if (today === nothing && forecast === nothing && utilities === nothing) return nothing; return html`
${utilities}${today}${forecast}
`; } private renderTodayCard(b: Building, hass: HomeAssistant) { const bins = binsDue(hass, b, Date.now(), { today: translate(hass, "care_bin_today"), tomorrow: translate(hass, "care_bin_tomorrow") }); const items = sortDay([...bins, ...(this._todayItems ?? [])]); if (!items.length && !(b.settings.calendars ?? []).length) return nothing; const open = this._todayOpen !== false; const date = new Intl.DateTimeFormat(hass.language ?? navigator.language, { weekday: "long", day: "numeric", month: "long" }).format(new Date()); const lang = hass.language ?? navigator.language; const dayName = (n: number) => { if (n === 1) return translate(hass, "tomorrow"); const d = new Date(); d.setDate(d.getDate() + n); return new Intl.DateTimeFormat(lang, { weekday: "long", day: "numeric", month: "numeric" }).format(d); }; // over several days a heading before the first line of each later day const lines = items.flatMap((i, k) => [ (i.day ?? 0) > 0 && (items[k - 1]?.day ?? 0) !== i.day ? html`
  • ${dayName(i.day ?? 0)}
  • ` : nothing, html`
  • ${i.title}${i.source}
  • `, ]); return html`
    ${open ? items.length ? html`
      ${lines}
    ` : html`

    ${translate(hass, "today_none")}

    ` : nothing}
    `; } private week: WeekBars | null = null; private weekAt = 0; /** The last seven days for the house card, from the long-term statistics, loaded at most every hour while the card shows. */ private refreshWeek(b: Building): void { const hass = this.hass; if (!hass || this._travel || Date.now() - this.weekAt < 3_600_000) return; this.weekAt = Date.now(); const found = deviceSensors(b, (f) => this.furnitureLinks?.get(f.id)?.power ?? null); const e = b.energy; const src = { solar: e.solar ? [e.solar] : found.solar, grid: e.grid ?? found.grid, gridInvert: !!e.grid_invert, battery: e.battery ? [e.battery] : found.battery, batteryInvert: !!e.battery_invert, consumption: e.consumption, }; void loadWeek(hass, src) .then((week) => { this.week = week; this.syncDevices(true); }) .catch(() => (this.week = null)); } /** The open floor's own meter (with its share of the house's use), then gas and water with the house's balance: what their sensors read now. */ private meterRows(b: Building, consumption: number | null = null): { icon: string; label: string; value: string }[] { 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 meter = floor && isSymcon(hass) ? floorUtilityReadings(hass, floor, b.floors.flatMap((f) => f.rooms)).find((r) => r.kind === "electricity" && r.metric === "power" && r.unit === "W") : undefined; const floorPower = isSymcon(hass) ? meter?.value ?? null : floor?.power_entity ? readPower(hass?.states[floor.power_entity]) : null; if (floor && (meter || floorPower !== null)) { const share = !meter?.incomplete && floorPower !== null && consumption && consumption > 0 ? ` · ${translate(hass, "floor_power_share", { n: Math.round((Math.max(0, floorPower) / consumption) * 100) })}` : ""; rows.push({ icon: "⚡", label: floor.name, value: `${meter ? utilityText(hass, meter) : powerText(hass, floorPower!)}${share}` }); } for (const [key, icon, label] of [["gas", "🔥", "energy_gas_short"], ["water", "💧", "energy_water_short"]] as const) { const id = b.energy[key]; const st = id ? hass?.states[id] : undefined; if (st && !isUnavailable(st)) rows.push({ icon, label: translate(hass, label), value: stateText(hass, st) }); } return rows; } /** Solar and consumption over the last 24 hours for the house card, loaded at most every 10 minutes while the card shows. */ private refreshDayCurves(b: Building): void { const hass = this.hass; if (!hass || this._travel || Date.now() - this.curvesAt < 600_000) return; this.curvesAt = Date.now(); const balance = (h: HomeAssistant) => energySummary(h, b, findConsumers(h, b), deviceSensors(b, (f) => this.furnitureLinks?.get(f.id)?.power ?? null)); const ids = statesRead(hass, balance); const to = Date.now(); const from = to - 24 * 3600_000; void loadHistory(hass, ids, from, to, true) .then((history) => { this.dayCurves = dayCurves(hass, history, from, to, balance); this.syncDevices(true); }) .catch(() => (this.dayCurves = null)); } private syncHydronics(v: NextFloorViewer, b: Building, hass: HomeAssistant): void { const generation = ++this.hydronicGeneration; const items = this.shownBuilding(hass).floors.filter((floor) => !this.floorId || floor.id === this.floorId).flatMap((floor) => floor.furniture.filter((item) => isHydronic(item.type)).map((item) => ({ floor, item }))); if (!items.length) { v.setHydronics([]); this.hydronicModule?.refreshHydronic(hass, b, !!this._travel); return; } void loadHydronics().then((mod) => { if (generation !== this.hydronicGeneration || this.viewer !== v || !this.isConnected) return; this.hydronicModule = mod; v.setHydronics(items.map(({ floor, item }) => ({ ...mod.hydronicVisual(hass, item, floor.id, mountBase(floor, item)), animate: !this.dimmed && !this._travel }))); mod.refreshHydronic(hass, b, !!this._travel); }).catch((err) => { this._error = String(err); }); } private syncLhCards(v: NextFloorViewer, b: Building, pic: EnergyPicture, cars: ReturnType, media: MediaNow[], hass: HomeAssistant): void { const cards: LiveCard[] = []; const s = pic.summary; const hasEnergy = s.solar !== null || s.grid !== null || s.battery !== null || s.consumption !== null; const hub = houseHub(b); // over the house, or over the floor that is open (the card stays in the floor views too) const top = (this.floorId ? b.floors.find((f) => f.id === this.floorId) : undefined) ?? [...b.floors].sort((p, q) => q.elevation - p.elevation)[0]; if (this.liveCardsOn && !this.dimmed && !this.roomId && hasEnergy && hub && top) { // over the middle of the house, above the roof let x = 0, z = 0, n = 0; for (const r of top.rooms) for (const [px, pz] of r.points) (x += px), (z += pz), n++; cards.push({ kind: "house", at: { floorId: top.id, x: n ? x / n : hub.x, z: n ? z / n : hub.z, y: top.height + (this.floorId ? 1.2 : 3.2) }, summary: s, autarky: pic.autarky, curves: this.dayCurves ?? undefined, week: this.week ?? undefined, meters: this.meterRows(b, s.consumption) }); this.refreshDayCurves(b); this.refreshWeek(b); } if (this.liveCardsOn && !this.dimmed && !this.roomId) { for (const c of cars) cards.push({ kind: "car", at: c.at, spot: c.spot, name: c.name, car: c.car }); for (const p of this.livePrinters(b)) cards.push({ kind: "printer", at: p.at, name: p.name, printer: p.printer }); for (const p of this.liveHeatPumps(b)) cards.push({ kind: "heatpump", at: p.at, name: p.name, pump: p.pump }); for (const m of media) cards.push({ kind: "media", at: { ...m.at, y: m.at.y + 0.5 }, media: m }); } if (this.liveCardsOn && !this.dimmed) { cards.push(...roomClimateCards(hass, b, this.floorId, this.roomId)); cards.push(...furniturePowerCards(hass, b, this.furnitureLinks ?? new Map(), this.floorId, this.roomId)); for (const floor of b.floors) for (const item of floor.furniture) { if (!isHydronic(item.type) || item.hydronic?.card === false || (this.floorId && floor.id !== this.floorId) || !furnitureShown(hass, item)) continue; const room = this.roomId ? floor.rooms.find((r) => r.id === this.roomId) : null; if (this.roomId && (!room || !pointInPolygon([item.x, item.z], room.points))) continue; cards.push({ kind: "hydronic", item, readOnly: !!this._travel, at: { floorId: floor.id, x: item.x + (item.pin_offset?.x ?? 0), z: item.z + (item.pin_offset?.z ?? 0), y: mountBase(floor, item) + item.h + .3 + (item.pin_offset?.y ?? 0) } }); } } if (JSON.stringify(cards) !== JSON.stringify(this._liveCards)) this._liveCards = cards; v.setLiveAnchors( cards.map((c) => c.at), cards.length ? (i, x, y, visible, density) => this.placeLhCard(i, x, y, visible, density) : null, ); } /** Called by the viewer after every frame: moves a card to its point without a Lit render. */ private placeLhCard(i: number, x: number, y: number, visible: boolean, density: number): void { const el = this.renderRoot.querySelector(`.live-card[data-i="${i}"]`); if (!el) return; const card = this._liveCards[i], key = `${card.kind}:${card.at.floorId}:${card.at.x}:${card.at.z}`; const wasVisible = el.dataset.zoomKey === key && el.dataset.zoomVisible === "1"; const active = this.shadowRoot?.activeElement; const focused = !!active && el.contains(active); const zoomVisible = focused || cardVisibleAtZoom(card, density, wasVisible); el.dataset.zoomKey = key; el.dataset.zoomVisible = zoomVisible ? "1" : "0"; el.dataset.density = String(Math.round(density)); el.dataset.priority = String(focused ? 110 : cardDetail(card).priority); el.dataset.focused = focused ? "1" : "0"; el.dataset.x = String(x); el.dataset.y = String(y); el.style.visibility = visible && zoomVisible ? "visible" : "hidden"; // the last card of the frame: lay them all out so none covers another if (i === this._liveCards.length - 1) unstackLhCards(this.renderRoot); } private toggleHouseFold(): void { this._houseFolded = !this._houseFolded; try { localStorage.setItem("nextfloor.house_card_folded", this._houseFolded ? "1" : "0"); } catch { // private mode: the choice lasts for this page only } } private toggleLhCards(): void { this._liveCardOn = !this._liveCardOn; try { localStorage.setItem("nextfloor.cards", this._liveCardOn ? "1" : "0"); } catch { // private mode: the choice lasts for this page only } this.syncDevices(true); } /** Top left: the clock there, with the own sensors and the energy bar below it instead of under it. */ private renderTopLeft() { const bar = this.clean ? nothing : this.renderLhEnergy(); const forecast = this.renderForecast("top_left"); if ((this.clock !== "top_left" && forecast === nothing) || !this.hass) return bar; return html`
    ${this.clock === "top_left" ? this.renderClock(true) : nothing}${bar}${forecast}
    `; } /** NextFloor's energy bar: what the house makes, uses, stores and trades, and the switches for flows and cards. */ private renderLhEnergy() { const own = this.ownSensors(); const e = this._liveEnergy?.summary; const energy = !!e && !this.roomId && this.showEnergy && !!this.hass && !(e.consumption === null && e.grid === null && e.solar === null && e.battery === null); const climate = this.building?.floors.some((f) => f.rooms.some((r) => r.climate_card) || f.furniture.some((m) => m.power_card || (isHydronic(m.type) && m.hydronic?.card !== false))); const climateToggle = climate ? this.renderCardToggle() : nothing; const roomNames = this.roomNamesButton ? html`` : nothing; if (!energy) return own.length || climateToggle !== nothing || roomNames !== nothing ? html`
    ${roomNames}${own}${climateToggle}
    ` : nothing; const t = (k: Parameters[1]) => translate(this.hass, k); const items: { cls: string; label: string; value: string }[] = []; if (e.solar !== null) items.push({ cls: "solar", label: t("energy_solar"), value: formatPower(this.hass, e.solar) }); if (e.consumption !== null) items.push({ cls: "total", label: t("energy_consumption"), value: formatPower(this.hass, e.consumption) }); if (e.rest !== undefined && e.rest !== null) items.push({ cls: "total", label: t("energy_rest"), value: formatPower(this.hass, e.rest) }); if (e.battery !== null || e.soc !== null) { const parts = [e.battery !== null ? formatPower(this.hass, Math.abs(e.battery)) : null, e.soc !== null ? `${Math.round(e.soc)} %` : null].filter(Boolean); items.push({ cls: "battery", label: t("energy_battery"), value: parts.join(" · ") }); } if (e.grid !== null) { const exporting = e.grid < 0; items.push({ cls: exporting ? "export" : "grid", label: t(exporting ? "energy_grid_export" : "energy_grid_import"), value: formatPower(this.hass, Math.abs(e.grid)) }); } if (e.tariff) items.push({ cls: "tariff", label: t("energy_tariff"), value: `${formatNumber(this.hass, e.tariff.value, 3)} ${e.tariff.unit}`.trim() }); if (this.building) for (const m of this.meterRows(this.building)) items.push({ cls: "meter", label: `${m.icon} ${m.label}`, value: m.value }); return html`
    ${roomNames} ${this.liveCardsOn && this._liveCards.some((c) => c.kind === "house") ? nothing : items.map((i) => html`
    ${i.label}${i.value}
    `)} ${this.flows !== null ? nothing : html``} ${this.renderCardToggle()} ${own}
    `; } private renderCardToggle() { return this.holograms !== null ? nothing : html``; } /** Native utility readings for the current building/floor scope. */ private utilityOverview(inline: boolean) { const b = this.building?this.scopeBuilding():null; if (!b || !isSymcon(this.hass) || !this.showEnergy || this.clean || this.roomId || this.panelOpen || (!inline && !this._utilityOverviewVisible)) return nothing; const rooms = b.floors.flatMap((f) => f.rooms), floors = this.floorId ? b.floors.filter((f) => f.id === this.floorId) : b.floors; if (!floors.some((f) => floorUtilityReadings(this.hass, f, rooms).length || floorUtilityAreas(this.hass, f, rooms, true).length)) return nothing; return html`) => { e.stopPropagation(); if (e.detail.roomId) this.openRoom(e.detail.floorId, e.detail.roomId); else this.fire("floor-tap", { floorId: e.detail.floorId }); }}>`; } /** The plan's own sensors and utility controls at the top. */ private ownSensors() { const summary = this.utilityOverview(true); const overviewToggle = summary === nothing ? nothing : html``; const ids = this.sensorBar && this.hass ? (this.building?.settings.status_entities ?? []) : []; const people = isSymcon(this.hass) ? (this.building?.presence ?? []).filter((link) => isSymconVariable(this.hass, link.person, [0])).map((link) => html`
    ${link.name || entityName(this.hass, link.person)}${nativeBool(this.hass.states[link.person]) === null ? "–" : nativeBool(this.hass.states[link.person]) ? "Anwesend" : "Abwesend"}${trendButton(this.hass, [link.person], link.name || "Anwesenheit")}
    `) : []; const weather = isSymcon(this.hass) ? Object.entries(this.building?.settings.weather_variables ?? {}).filter((entry): entry is [keyof typeof WEATHER_VARIABLE_LABELS, string] => !!entry[1] && entry[1] !== "none").map(([key, id]) => [WEATHER_VARIABLE_LABELS[key] || key, id]) : []; 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` event.stopPropagation()}>
    Wetter
    ${weather.map(([label, id]) => html`

    ${label}${nativeText(this.hass.states[id])}${trendButton(this.hass, [id], label)}

    `)}
    ` : nothing; const floors = isSymcon(this.hass) ? (this.building?this.scopeBuilding().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` event.stopPropagation()}>
    Stockwerkszähler
    ${floors.map(({ floor, readings }) => html`

    ${floor.name}

    `)}
    ` : nothing; return [overviewToggle, summary, ...people, weatherValues, utilities, ...ids .filter((id) => this.hass.states[id]) .map( (id) => html`${trendButton(this.hass, [id], entityName(this.hass, id))}`, )]; } /** The map's credit while a real map lies under the plan (OpenStreetMap asks for it). */ private renderMapCredit() { const map = this.building?.settings.map; if (!mapShown(map)) return nothing; return html`${mapCredit(map).text}`; } private renderLegend() { if (this.heatMode === "wifi") return this.renderWifiLegend(); if (this.heatMode === "none" || this.heatMode === "values") return nothing; const summer = isSummer(new Date(), this.hass?.config?.latitude ?? 50); const scale = scaleOf(this.heatMode, summer); // temperatures are coloured in °C and shown in Home Assistant's unit const temp = this.heatMode === "temperature"; const lo = temp ? fromCelsius(this.hass, scale.stops[0][0]) : scale.stops[0][0]; const hi = temp ? fromCelsius(this.hass, scale.stops[scale.stops.length - 1][0]) : scale.stops[scale.stops.length - 1][0]; const unit = temp ? tempUnit(this.hass) : scale.unit; const t = (k: Parameters[1]) => translate(this.hass, k); return html`
    ${t(`heat_${this.heatMode}`)}${this.heatMode === "temperature" ? html` ${t(summer ? "heat_summer" : "heat_winter")}` : nothing} ${formatNumber(this.hass, lo, 0)} ${unit}${formatNumber(this.hass, hi, 0)} ${unit} ${this.heatValues.size ? nothing : html`${t("heat_none_found")}`}
    `; } /** The Wi-Fi map's legend: the access points, the devices they carry, and the network devices that are offline. */ private renderWifiLegend() { const hass = this.hass; const b = this.building; if (!hass || !b) return nothing; const t = (k: I18nKey, v?: Record) => translate(hass, k, v); const aps = b.floors.flatMap((f) => f.furniture.filter((m) => isAccessPoint(m.type)).map((m) => readAccessPoint(hass, this.furnitureLinks?.get(m.id)?.entity ?? this.furnitureLinks?.get(m.id)?.power ?? null))); const known = aps.filter((a): a is NonNullable => !!a); const clients = known.reduce((s, a) => s + (a.clients ?? 0), 0); const placed = b.floors.flatMap((f) => f.placements.map((p) => hass.states[p.entity_id])); const health = networkHealth(placed); return html`
    📶 ${t("heat_wifi")} ${t("wifi_aps", { n: aps.length, clients })} ${health.online + health.offline.length ? html`${t("wifi_network", { online: health.online, offline: health.offline.length })}` : nothing} ${health.offline.length ? html`${health.offline.slice(0, 4).join(", ")}` : nothing} ${aps.length ? nothing : html`${t("wifi_none")}`}
    `; } /** The sky colour behind the house right now (night: deep blue-black, day: lighter and bluer, clouds in between). */ private skyColor(): [number, number, number] { const stage = STAGE[this.theme] ?? STAGE.neon; const sky = this._sky; return stage.night[0].map((v, i) => Math.round(v + (stage.day[0][i] - v) * sky)) as [number, number, number]; } protected render() { const utilities = this.utilityOverview(false); const sky = this._sky; const mix = (a: number[], b: number[]) => `rgb(${a.map((v, i) => Math.round(v + (b[i] - v) * sky)).join(",")})`; const stage = STAGE[this.theme] ?? STAGE.neon; const style = `--nf-sky:${mix(stage.night[0], stage.day[0])};--nf-ground:${mix(stage.night[1], stage.day[1])}` + backdropStyle(this.building?.settings.backdrop); return html`
    ${this._error ? html`

    ${this._error}

    ` : nothing} ${this.renderTopLeft()} ${renderLhCards(this.hass, this._liveCards, (domain, service, entity, data) => this.hass?.callService(domain, service, { entity_id: entity, ...data }), { folded: this._houseFolded, toggle: () => this.toggleHouseFold() }, !!this.roomId || this.panelOpen)} ${this.clean ? nothing : this.renderLegend()} ${this.renderMapCredit()} ${this.renderAlerts()} ${this.renderAnnouncement()} ${this.clean ? nothing : html`${this.renderThumbs()} ${this.renderScenes()} ${this.renderFind()} ${this.renderCentral()}`} ${this.renderSwipe()} ${this.renderMenu()} ${this.renderPlate()} ${this.renderEye()} ${this.renderLock()} ${this.renderWalk()} ${this.renderTravel()} ${this.renderClock()} ${this.renderToday(utilities)} ${this.renderLayers()} ${this.renderPluginWindow()} ${this.showStats && this._stats ? html`${this._stats.fps ? translate(this.hass, "stats_fps", { fps: this._stats.fps, ms: this._stats.worstMs }) : translate(this.hass, "stats_idle")} ${this._stats.busy.length ? html`(${this._stats.busy.map((b) => translate(this.hass, `stats_busy_${b}` as I18nKey)).join(", ")})` : nothing} · ${translate(this.hass, "stats", { calls: this._stats.calls, tris: this._stats.triangles.toLocaleString() })} · ${translate(this.hass, this._stats.low ? "stats_low" : "stats_full", { r: formatNumber(this.hass, this._stats.pixelRatio, 2) })}` : nothing}
    `; } static styles = [ tokens, controls, liveCardStyles, css` :host { display: block; position: relative; min-height: 200px; } .nf-alert-banner { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; justify-content: center; gap: 6px; max-width: calc(100% - 24px); z-index: 4; } .nf-alert { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 7px 14px 7px 12px; border: 0; border-left: 4px solid #ff3b4f; border-radius: 12px; background: var(--nf-chrome-solid); color: var(--nf-text); font: 600 13.5px var(--nf-font); box-shadow: 0 0 18px rgba(255, 59, 79, 0.35); cursor: pointer; animation: nf-alert-pulse 1.2s ease-in-out infinite; } .nf-alert-water, .nf-alert-window_rain { border-left-color: #4fb3ff; box-shadow: 0 0 18px rgba(79, 179, 255, 0.35); } .nf-alert-alarm_pending { border-left-color: #ffb547; box-shadow: 0 0 18px rgba(255, 181, 71, 0.35); } .nf-announcement { position: absolute; inset: 18% 8% auto; z-index: 30; display: flex; align-items: center; gap: 18px; margin: 0 auto; max-width: 860px; padding: 22px 28px; border: 1px solid color-mix(in srgb, var(--nf-accent) 55%, transparent); border-radius: 22px; background: var(--nf-chrome-solid); color: var(--nf-text); box-shadow: 0 0 40px color-mix(in srgb, var(--nf-accent) 35%, transparent), 0 18px 50px rgba(0, 0, 0, 0.45); font: 700 clamp(22px, 3.6vw, 40px) / 1.25 var(--nf-font); text-align: left; cursor: pointer; animation: nf-announce-in 0.35s ease-out; } .nf-announcement-icon { font-size: 1.3em; } @keyframes nf-announce-in { from { opacity: 0; transform: translateY(-12px) scale(0.98); } } @media (prefers-reduced-motion: reduce) { .nf-announcement { animation: none; } } /* a contact that stopped answering is a chore, not an emergency: no glow, no pulse */ .nf-alert-contact_lost, .nf-alert-own { border-left-color: #ffb547; box-shadow: none; animation: none; } .nf-alert-more { align-self: center; color: var(--nf-muted); font-size: 13px; } @keyframes nf-alert-pulse { 50% { box-shadow: 0 0 4px transparent; } } .nf-has-alerts .nf-energy, .nf-has-alerts .nf-topleft { top: 58px; } /* the clock top left stacks above the sensor and energy bar rather than covering it */ .nf-topleft { position: absolute; left: 12px; top: 10px; z-index: 3; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; max-width: calc(100% - 24px); pointer-events: none; } .nf-topleft > .nf-clock, .nf-topleft > .nf-energy { position: static; max-width: 100%; } .nf-scenes { position: absolute; left: 60px; right: 60px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; z-index: 2; pointer-events: none; } .nf-scenes .nf-chip { pointer-events: auto; } @media (prefers-reduced-motion: reduce) { .nf-alert, .nf-dev-found { animation: none; } } .nf-stage { position: absolute; inset: 0; overflow: hidden; container-type: size; container-name: nf; background: radial-gradient(ellipse at 50% 35%, var(--nf-sky, var(--nf-bg2)), var(--nf-ground, var(--nf-bg)) 72%); transition: background 2s ease; } .nf-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; } .nf-canvas:active { cursor: grabbing; } :host([readable]) .nf-pin { font-size: 15px; padding: 6px 12px; } :host([readable]) .nf-pin-info small, :host([readable]) .nf-pin-floor span { font-size: 14px; opacity: 1; } :host([readable]) .nf-pin-floor b { font-size: 18px; } :host([readable]) .nf-dev { font-size: 14px; color: var(--nf-text); } .nf-note-pin { background: #ffe58a; color: #3a2e00; border-color: #c9a400; max-width: 260px; overflow: hidden; text-overflow: ellipsis; } .nf-note-pin.nf-note-due { background: #ffa726; color: #2a1600; } .nf-note-pin.nf-note-open { white-space: normal; text-align: left; } .nf-note-photo { display: block; width: 100%; max-height: 200px; object-fit: cover; margin-top: 6px; border-radius: 6px; } .nf-labels { position: absolute; inset: 0; pointer-events: none; } .nf-pin-info { display: grid; gap: 1px; text-align: center; } .nf-pin-info small { font-size: 11px; font-weight: 500; opacity: 0.9; font-variant-numeric: tabular-nums; } .nf-pin { position: absolute; left: 0; top: 0; pointer-events: auto; font: 600 12.5px var(--nf-title-font); color: var(--nf-text); background: var(--nf-chrome); border: 1px solid var(--nf-line); border-radius: 10px; padding: 5px 10px; cursor: pointer; white-space: nowrap; backdrop-filter: blur(6px); box-shadow: var(--nf-shadow); } .nf-pin-floor { display: grid; justify-items: start; gap: 1px; padding: 8px 14px; border-radius: 12px; background: var(--nf-accent); color: var(--nf-accent-text); border-color: transparent; box-shadow: var(--nf-shadow); } .nf-pin-floor b { font: 700 15px var(--nf-title-font); letter-spacing: -0.01em; } .nf-pin-floor span { font: 500 12px var(--nf-font); opacity: 0.78; } .nf-dev { position: absolute; left: 0; top: 0; pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; padding: 4px; border-radius: 999px; border: 1px solid var(--nf-line); background: var(--nf-chrome); color: var(--nf-muted); font: 600 12px var(--nf-font); cursor: pointer; white-space: nowrap; backdrop-filter: blur(6px); touch-action: manipulation; -webkit-user-select: none; user-select: none; transition: opacity 0.2s ease; } .nf-dev-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: color-mix(in srgb, var(--nf-soft) 14%, transparent); } .nf-dev-text { display: none; padding-right: 6px; color: var(--nf-text); font-variant-numeric: tabular-nums; max-width: 160px; overflow: hidden; text-overflow: ellipsis; } .nf-dev-watt:empty { display: none; } .nf-dev-watt { padding: 1px 6px 1px 0; color: var(--nf-accent); font-variant-numeric: tabular-nums; font-weight: 700; } .nf-dev-on .nf-dev-watt { color: #2a1a00; } .nf-person { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; overflow: hidden; background: #ff5fd2; color: #fff; font: 700 12px var(--nf-font); box-shadow: 0 0 0 2px rgba(255, 95, 210, 0.45), 0 0 18px #ff5fd2; pointer-events: auto; } .nf-person img { width: 100%; height: 100%; object-fit: cover; } .nf-person[hidden] { display: none; } .nf-no-room-names .nf-pin[data-room] { display: none !important; } /* tablet level: blur over the canvas and glowing shadows are expensive on weak GPUs */ .nf-stage.nf-low { transition: none; } .nf-low .nf-pin, .nf-low .nf-dev, .nf-low .nf-dev-on, .nf-low .nf-energy-item, .nf-low .nf-find input, .nf-low .nf-find-list, .nf-low .nf-find-btn, .nf-low .nf-swipe, .nf-low .nf-thumb { backdrop-filter: none; box-shadow: none; transition: none; } .nf-thumbs { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; max-height: calc(100% - 140px); overflow-y: auto; scrollbar-width: none; z-index: 2; } .nf-thumb { position: relative; display: grid; padding: 0; width: 150px; border: 1px solid var(--nf-line); border-radius: 14px; background: color-mix(in srgb, var(--nf-chrome) 70%, transparent); color: var(--nf-text); cursor: pointer; overflow: hidden; font: inherit; box-shadow: var(--nf-shadow); opacity: 0.72; transition: opacity 0.15s, border-color 0.15s; } .nf-thumb:hover, .nf-thumb[aria-pressed="true"] { opacity: 1; } .nf-thumb[aria-pressed="true"] { border-color: var(--nf-accent); box-shadow: var(--nf-shadow), 0 0 0 2px var(--nf-accent); } .nf-thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; } .nf-thumb span { position: absolute; left: 8px; bottom: 6px; font-size: 12px; font-weight: 600; } .nf-thumb img + span { inset: auto 0 0 0; padding: 18px 10px 6px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, 0.62)); } .nf-thumbs-fold { align-self: flex-start; width: 26px; height: 22px; padding: 0; border: 1px solid var(--nf-line); border-radius: 8px; background: var(--nf-chrome); color: var(--nf-text); font-size: 11px; cursor: pointer; } /* folded: plain floor buttons with their names, no pictures (D177) */ .nf-thumbs-compact .nf-thumb { padding: 6px 10px; min-width: 0; } .nf-thumbs-compact .nf-thumb span { position: static; background: none; padding: 0; } .nf-thumb-house { display: flex; align-items: center; gap: 8px; padding: 8px 10px; } .nf-thumb-house span { position: static; text-shadow: none; } /* a low stage (a card of 420 px): the pictures start under the top bar and stop above the buttons at the bottom left */ .nf-thumbs.nf-thumbs-short { top: 52px; transform: none; max-height: calc(100% - 52px - 150px); } .nf-thumbs-small .nf-thumb { width: 104px; } .nf-find-btn { position: absolute; left: 12px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 13px; background: var(--nf-chrome); color: var(--nf-text); box-shadow: var(--nf-shadow); cursor: pointer; } /* the star sits above the search button, its menu opens above it */ .nf-central-btn { position: absolute; left: 12px; bottom: calc(56px + var(--nf-bottom-inset, 0px)); width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 13px; background: var(--nf-chrome); color: var(--nf-text); box-shadow: var(--nf-shadow); cursor: pointer; z-index: 3; } .nf-central-on { color: var(--nf-accent); } .nf-central { position: absolute; left: 12px; bottom: calc(104px + var(--nf-bottom-inset, 0px)); width: min(320px, calc(100% - 24px)); max-height: calc(100% - 140px); overflow-y: auto; box-sizing: border-box; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid var(--nf-line); border-radius: 16px; background: var(--nf-chrome); color: var(--nf-text); box-shadow: var(--nf-shadow); backdrop-filter: blur(10px); z-index: 4; } .nf-central > b { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; } .nf-central-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; } .nf-central-row small { opacity: 0.6; } .nf-central .nf-btn { min-width: 64px; } .nf-central-armed { background: #ff8a3d !important; color: #1a0d00 !important; } .nf-central-favs { display: flex; flex-wrap: wrap; gap: 6px; } .nf-own-btn { display: inline-flex; align-items: center; gap: 6px; } .nf-own-btn ha-icon { --mdc-icon-size: 18px; } .nf-central-hint { margin: 0; font-size: 13px; opacity: 0.7; } .nf-layers { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; z-index: 3; } .nf-has-alerts .nf-layers { top: 58px; } /* top right: "Today" and the forecast below it, one column */ .nf-right-col { position: absolute; top: 12px; right: 12px; width: min(280px, calc(100% - 24px)); max-height: calc(100% - 140px); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 3; pointer-events: none; } .nf-right-col > * { pointer-events: auto; } .nf-utility-right { height: calc(100% - 140px); } .nf-has-utility-overview:not(.nf-narrow) > .nf-energy, .nf-has-utility-overview:not(.nf-narrow) > .nf-topleft { max-width: calc(100% - 316px); } .nf-has-utility-overview .nf-energy { align-items: flex-start; } .nf-narrow .nf-utility-right { top: auto !important; bottom: 64px; height: 42%; max-height: 42%; justify-content: flex-end; width: min(280px, calc(100% - 24px)); } .nf-has-alerts .nf-right-col { top: 58px; } /* "Today": the day's appointments and bins, folds to its title */ .nf-today { width: 100%; min-height: 0; overflow-y: auto; box-sizing: border-box; padding: 8px 12px 10px; border-radius: 16px; border: 1px solid var(--nf-line); background: var(--nf-chrome); box-shadow: var(--nf-shadow); backdrop-filter: blur(10px); color: var(--nf-text); z-index: 3; } .nf-low :is(.nf-today, .nf-forecast) { backdrop-filter: none; } .nf-today-day { display: block !important; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--nf-muted); } /* the forecast: a row per day */ .nf-forecast { box-sizing: border-box; flex: none; padding: 6px 12px; border-radius: 16px; border: 1px solid var(--nf-line); background: var(--nf-chrome); box-shadow: var(--nf-shadow); backdrop-filter: blur(10px); color: var(--nf-text); pointer-events: auto; } .nf-forecast ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: auto auto auto auto; column-gap: 10px; row-gap: 2px; align-items: baseline; font-size: 13px; } .nf-forecast li { display: contents; } .nf-fc-day { color: var(--nf-muted); } .nf-fc-temp { font-variant-numeric: tabular-nums; white-space: nowrap; } .nf-fc-temp small { color: var(--nf-muted); } .nf-fc-rain { font-size: 12px; color: var(--nf-soft); white-space: nowrap; } .nf-today-folded { width: auto; align-self: flex-end; padding-bottom: 8px; } .nf-today-head { display: flex; gap: 8px; align-items: baseline; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; text-align: left; } .nf-today-head span { font-size: 12px; color: var(--nf-muted); } .nf-today ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; } .nf-today li { display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: baseline; font-size: 14px; } .nf-today time { font-variant-numeric: tabular-nums; color: var(--nf-accent); font-weight: 600; } .nf-today small { display: block; font-size: 11px; color: var(--nf-muted); } .nf-today-past { opacity: 0.45; } .nf-today-none { margin: 6px 0 0; font-size: 13px; color: var(--nf-muted); } /* opened from the start on a wall tablet: a size larger, easy to hit */ .nf-central-big { width: min(420px, calc(100% - 24px)); font-size: 16px; } .nf-central-big .nf-chip, .nf-central-big .nf-btn { min-height: 44px; padding: 8px 16px; font-size: 15px; } .nf-own-btn[aria-pressed="true"] { border-color: var(--nf-accent); color: var(--nf-accent); box-shadow: 0 0 12px color-mix(in srgb, var(--nf-accent) 45%, transparent); } .nf-low .nf-central { backdrop-filter: none; } /* the eye sits beside the search button; alone in the corner once the view is clean */ .nf-travel-btn { position: absolute; left: 188px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 1px solid rgba(160, 240, 255, 0.35); background: rgba(8, 16, 34, 0.7); color: var(--nf-text); font-size: 14px; cursor: pointer; z-index: 4; } .nf-travel { position: absolute; left: 50%; bottom: calc(62px + var(--nf-bottom-inset, 0px)); transform: translateX(-50%); width: min(860px, calc(100% - 24px)); display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 18px; background: rgba(8, 16, 34, 0.82); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4); color: var(--nf-text); z-index: 5; flex-wrap: wrap; } .nf-travel button, .nf-travel select { min-height: 32px; border: 0; border-radius: 999px; padding: 0 10px; background: rgba(127, 127, 127, 0.16); color: inherit; font: inherit; font-size: 13px; cursor: pointer; } .nf-travel select option { color: #111; } .nf-travel .nf-travel-play { width: 36px; padding: 0; background: var(--nf-accent); color: #041018; } .nf-travel-span[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--nf-accent); color: var(--nf-accent); } .nf-travel-live { color: #ff5a6b !important; } .nf-travel-when { min-width: 92px; font-variant-numeric: tabular-nums; font-size: 14px; } .nf-travel-track { position: relative; flex: 1 1 220px; height: 28px; } .nf-travel-track svg { position: absolute; inset: 9px 0; width: 100%; height: 10px; fill: var(--nf-accent); opacity: 0.55; pointer-events: none; } .nf-travel-track input { position: absolute; inset: 0; width: 100%; margin: 0; background: transparent; accent-color: var(--nf-accent); } .nf-walk-btn { position: absolute; left: 144px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border-radius: 50%; border: 1px solid rgba(160, 240, 255, 0.35); background: rgba(8, 16, 34, 0.7); color: var(--nf-text); font-size: 16px; cursor: pointer; z-index: 4; } .nf-walk-on { color: #041018; background: var(--nf-accent); border-color: var(--nf-accent); } .nf-stick { position: absolute; right: 28px; bottom: calc(70px + var(--nf-bottom-inset, 0px)); width: 120px; height: 120px; border-radius: 50%; background: rgba(8, 16, 34, 0.45); border: 1px solid rgba(160, 240, 255, 0.35); display: grid; place-items: center; touch-action: none; z-index: 4; } .nf-stick span { width: 52px; height: 52px; border-radius: 50%; background: var(--nf-accent); opacity: 0.85; pointer-events: none; } .nf-walk-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); margin: 0; padding: 6px 12px; border-radius: 999px; background: rgba(8, 16, 34, 0.6); color: var(--nf-muted); font-size: 12px; pointer-events: none; z-index: 3; } .nf-lock3d { position: absolute; left: 100px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border-radius: 50%; border: 1px solid rgba(160, 240, 255, 0.35); background: rgba(8, 16, 34, 0.7); color: var(--nf-text); cursor: pointer; z-index: 4; } .nf-lock3d-on { color: #041018; background: var(--nf-accent); border-color: var(--nf-accent); } .nf-plugin-window { position: absolute; right: 12px; bottom: 12px; z-index: 6; width: min(420px, calc(100% - 24px)); border-radius: 12px; overflow: hidden; background: rgba(10, 16, 22, 0.92); border: 1px solid rgba(127, 208, 255, 0.35); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45); color: #e6f4fb; } .nf-pw-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; font-size: 13px; } .nf-pw-head span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .nf-pw-close { border: 0; background: transparent; color: inherit; font-size: 16px; cursor: pointer; padding: 2px 6px; } .nf-pw-body { line-height: 0; } .nf-clock { position: absolute; z-index: 3; display: flex; flex-direction: column; padding: 8px 14px; border-radius: 16px; background: rgba(8, 16, 34, 0.55); color: var(--nf-text); pointer-events: none; line-height: 1.1; } .nf-clock b { font-size: clamp(28px, 6cqmin, 64px); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; } .nf-clock span { font-size: clamp(12px, 1.8cqmin, 18px); color: var(--nf-muted); } .nf-clock-top_left { left: 16px; top: 16px; } .nf-clock-top_right { right: 16px; top: 16px; align-items: flex-end; } .nf-clock-bottom_left { left: 16px; bottom: calc(60px + var(--nf-bottom-inset, 0px)); } .nf-clock-bottom_right { right: 16px; bottom: calc(60px + var(--nf-bottom-inset, 0px)); align-items: flex-end; } .nf-eye { position: absolute; left: 56px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border-radius: 50%; border: 1px solid rgba(160, 240, 255, 0.35); background: rgba(8, 16, 34, 0.7); color: var(--nf-text); cursor: pointer; z-index: 4; } /* in the clean view the button sits at the top: a tablet's taskbar or gesture bar covers the bottom edge and the button was lost there (#75) */ .nf-eye-clean { left: auto; bottom: auto; right: calc(12px + env(safe-area-inset-right, 0px)); top: calc(12px + env(safe-area-inset-top, 0px)); opacity: 0.55; } .nf-eye:hover, .nf-eye-clean:hover { opacity: 1; } .nf-find { position: absolute; left: 12px; bottom: calc(10px + var(--nf-bottom-inset, 0px)); width: min(340px, calc(100% - 24px)); display: flex; flex-direction: column-reverse; gap: 6px; z-index: 3; } .nf-find input { box-sizing: border-box; width: 100%; height: 42px; padding: 0 42px 0 14px; border: 1px solid var(--nf-line); border-radius: 14px; background: var(--nf-chrome); color: var(--nf-text); font: inherit; font-size: 15px; box-shadow: var(--nf-shadow); backdrop-filter: blur(8px); } .nf-find-close { position: absolute; right: 6px; bottom: 6px; width: 30px; height: 30px; border: 0; border-radius: 10px; background: none; color: var(--nf-muted); cursor: pointer; } .nf-find-list { display: grid; padding: 6px; border-radius: 14px; background: var(--nf-chrome); box-shadow: var(--nf-shadow); backdrop-filter: blur(8px); } .nf-find-list button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 10px; background: none; color: var(--nf-text); text-align: left; font: inherit; cursor: pointer; } .nf-find-list button:hover, .nf-find-list button:focus-visible { background: rgba(127, 127, 127, 0.14); } .nf-find-list b { display: block; font-weight: 600; } .nf-find-list small, .nf-find-list p { color: var(--nf-muted); font-size: 12px; margin: 0; } .nf-find-list p { padding: 8px 10px; } .nf-find-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; background: rgba(127, 127, 127, 0.15); flex: none; } .nf-find-icon svg { width: 16px; height: 16px; } .nf-swipe { position: absolute; transform: translate(-50%, calc(-100% - 28px)); display: grid; grid-template-columns: auto auto; align-items: center; gap: 2px 12px; padding: 8px 12px; border-radius: 14px; background: var(--nf-chrome); box-shadow: var(--nf-shadow); pointer-events: none; white-space: nowrap; z-index: 4; } .nf-swipe span { font-size: 12px; color: var(--nf-muted); } .nf-swipe b { grid-row: 2; font: 700 22px var(--nf-title-font); } .nf-swipe i { grid-row: 1 / 3; grid-column: 2; position: relative; width: 10px; height: 44px; border-radius: 5px; background: rgba(127, 127, 127, 0.25); overflow: hidden; } .nf-swipe em { position: absolute; left: 0; right: 0; bottom: 0; background: var(--nf-warm); } .nf-plate-menu { position: absolute; z-index: 6; display: flex; flex-direction: column; gap: 4px; min-width: 220px; padding: 6px; border-radius: 16px; background: var(--nf-bg2, #1c2233); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45); } .nf-plate-menu button { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; min-height: 42px; padding: 0 10px; border: 0; border-radius: 12px; background: none; color: var(--nf-text, #e8eeff); font: inherit; text-align: left; cursor: pointer; } .nf-plate-menu button:hover { background: rgba(127, 127, 127, 0.14); } .nf-plate-menu button.on b { background: var(--nf-accent, #37e0ff); color: #041018; } .nf-plate-menu b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: rgba(127, 127, 127, 0.2); font-size: 12px; } .nf-plate-menu i { font-style: normal; color: var(--nf-muted, #9aa5bd); font-size: 13px; } .nf-menu-backdrop { position: absolute; inset: 0; z-index: 5; } .nf-through { position: absolute; inset: 0; z-index: 4; pointer-events: none; } /* the camera wall: a glass sheet over the scene with every camera's picture */ .nf-wall { position: absolute; inset: 56px 12px calc(var(--nf-bottom-inset, 0px) + 12px); z-index: 5; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 16px; background: rgba(8, 16, 34, 0.86); border: 1px solid rgba(160, 240, 255, 0.4); box-shadow: var(--nf-shadow); overflow: auto; } .nf-wall-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; color: var(--nf-text); } .nf-wall-head .nf-wall-title { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; } .nf-wall-title b { color: #ff6b6b; font-weight: 600; } .nf-wall-tools { display: flex; gap: 6px; } .nf-wall-big { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; border-radius: 12px; overflow: hidden; background: #0a1426; } .nf-wall-big img { width: 100%; height: 100%; object-fit: contain; } /* the stream player: a bare card, as wide as the sheet allows for a 16:9 picture */ .nf-wall-big > hui-picture-entity-card, .nf-wall-big > hui-error-card { width: min(100%, calc((100vh - 200px) * 16 / 9)); --ha-card-background: transparent; --ha-card-border-width: 0; --ha-card-box-shadow: none; } .nf-wall-grid { flex: 1; display: grid; align-content: safe center; justify-content: center; gap: 12px; min-height: 0; overflow-y: auto; } .nf-wall-cam { position: relative; padding: 0; border: 1px solid rgba(160, 240, 255, 0.3); border-radius: 12px; overflow: hidden; background: #0a1426; cursor: pointer; width: 100%; height: 100%; } .nf-wall-cam img, .nf-wall-none { width: 100%; height: 100%; object-fit: cover; display: flex; align-items: center; justify-content: center; color: #8aa; } .nf-wall-seen { border-color: rgba(255, 80, 90, 0.9); box-shadow: 0 0 14px rgba(255, 60, 70, 0.5); } .nf-wall-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; font-size: 12px; text-align: left; color: var(--nf-text); background: linear-gradient(transparent, rgba(0, 0, 0, 0.7)); } .nf-wall-name b { color: #ff6b6b; font-weight: 600; } /* a lightning bolt of the weather layer lights up the whole stage for a moment */ .live-flash::after { content: ""; position: absolute; inset: 0; z-index: 3; background: radial-gradient(circle at 50% 20%, rgba(235, 242, 255, 0.55), rgba(200, 215, 255, 0.18) 70%); pointer-events: none; } .nf-through-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: var(--nf-blend); } .nf-through-bar { position: absolute; left: 50%; bottom: calc(var(--nf-bottom-inset, 0px) + 14px); transform: translateX(-50%); display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); padding: 8px 10px 8px 16px; border-radius: 999px; background: var(--nf-chrome); backdrop-filter: blur(12px); border: 1px solid var(--nf-line); pointer-events: auto; } .nf-through-name { font-weight: 600; white-space: nowrap; } /* a small note that the picture is a still, so nobody wonders why it does not move */ .nf-still { font-size: 11px; font-weight: 400; opacity: 0.65; white-space: nowrap; margin-left: 6px; } .nf-through-bar input[type="range"] { width: 140px; accent-color: var(--nf-accent); } .nf-through-on :is(.nf-pin, .nf-dev, .nf-energy, .nf-legend, .nf-thumbs, .nf-scenes, .nf-find-btn, .nf-stats) { display: none; } nf-quick-menu { position: absolute; z-index: 6; } .nf-dev-found { animation: nf-found 0.6s ease-in-out 4; } @keyframes nf-found { 50% { scale: 1.35; filter: drop-shadow(0 0 12px var(--nf-accent)); } } .nf-map-credit { position: absolute; right: 8px; bottom: 4px; z-index: 2; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, var(--nf-chrome) 80%, transparent); color: var(--nf-soft); font-size: 10px; text-decoration: none; } .nf-legend { position: absolute; left: 12px; /* above the star button */ bottom: calc(104px + var(--nf-bottom-inset, 0px)); display: grid; gap: 4px; min-width: 180px; padding: 8px 11px; border-radius: 12px; background: var(--nf-chrome); box-shadow: var(--nf-shadow); font-size: 12px; pointer-events: none; } .nf-legend-bar { height: 8px; border-radius: 4px; } .nf-legend-range { display: flex; justify-content: space-between; color: var(--nf-muted); font-variant-numeric: tabular-nums; } .nf-legend-none { color: var(--nf-warm); } .nf-energy { position: absolute; left: 12px; top: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 24px); pointer-events: none; } .nf-energy-item { display: grid; padding: 5px 11px 6px; border-radius: 12px; background: var(--nf-chrome); border-left: 3px solid var(--nf-line); box-shadow: var(--nf-shadow); backdrop-filter: blur(6px); font-variant-numeric: tabular-nums; } .nf-energy-item span { font-size: 11px; color: var(--nf-muted); } .nf-energy-item b { font: 700 15px var(--nf-title-font); } .nf-energy-total { border-left-color: #6fd8ff; } .nf-energy-grid { border-left-color: var(--nf-accent); } .nf-energy-export, .nf-energy-solar { border-left-color: #ffc633; } .nf-energy-battery { border-left-color: #59ff8c; } .nf-flow-toggle { pointer-events: auto; cursor: pointer; border: 0; border-left: 3px solid var(--nf-line); color: inherit; text-align: left; font: inherit; } .nf-weather-dialog { pointer-events:auto; width:min(380px,calc(100vw - 32px)); max-height:75dvh; overflow:auto; box-sizing:border-box; padding:16px; background:var(--nf-chrome-solid); color:var(--nf-text); font:14px/1.5 system-ui,sans-serif; border:1px solid var(--nf-line); border-radius:12px; box-shadow:var(--nf-shadow); } .nf-weather-dialog::backdrop { background:#0008; } .nf-weather-dialog header,.nf-weather-dialog p { display:flex; justify-content:space-between; gap:16px; margin:8px 0; } .nf-weather-dialog p span { color:var(--nf-muted); } .nf-weather-dialog p b { font-size:13px; white-space:nowrap; } .nf-own-sensor { pointer-events: auto; cursor: pointer; border: 0; border-left: 3px solid var(--nf-accent); color: inherit; text-align: left; font: inherit; max-width: 220px; } .nf-own-sensor span, .nf-own-sensor b { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .nf-flow-toggle[aria-pressed="true"] { border-left-color: var(--nf-accent); } .nf-flow-toggle span { display: none; } .nf-flow-toggle b { opacity: 0.4; filter: grayscale(1); } .nf-flow-toggle[aria-pressed="true"] b { opacity: 1; filter: none; } .nf-energy-tariff { border-left-color: #b98cff; } /* narrow stages (portrait tablets, phones): the energy values scroll in one row */ @container nf (max-width: 900px) { .nf-energy { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; pointer-events: auto; } .nf-legend { bottom: auto; top: 62px; } .nf-has-alerts .nf-legend { top: 110px; } } /* a room sheet covers the lower half: the view's own controls step aside */ @container nf ((max-width: 700px) or ((orientation: portrait) and (max-width: 1000px))) { .nf-panel-open :is(.nf-find-btn, .nf-find, .nf-thumbs, .nf-legend, .nf-stats, .nf-scenes) { display: none; } } @media (pointer: coarse) { .nf-find-close { width: 40px; height: 40px; right: 1px; bottom: 1px; } .nf-dev { padding: 6px; } .nf-pin { padding: 8px 12px; } } .nf-dev-full .nf-dev-text { display: inline; } .nf-dev-name:empty { display: none; } .nf-dev-name { position: absolute; top: calc(100% + 3px); left: 50%; transform: translateX(-50%); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px 6px; border-radius: 6px; font-size: 10.5px; font-weight: 600; line-height: 1.35; /* a fixed dark plate, so a fixed light text: the theme text colour can be dark (day themes, pins that are on) */ color: #f2f5fb; background: rgba(10, 16, 32, 0.72); pointer-events: none; } .nf-dev-sel { outline: 2px solid var(--nf-accent); outline-offset: 2px; } .nf-dev-on { color: #2a1a00; border-color: transparent; background: var(--nf-glow, var(--nf-warm)); box-shadow: 0 0 16px var(--nf-glow, var(--nf-warm)); } .nf-dev-on .nf-dev-icon { background: color-mix(in srgb, var(--nf-text) 28%, transparent); } .nf-dev-on .nf-dev-text { color: #2a1a00; } .nf-dev-na { opacity: 0.45; } .nf-dev-dim { opacity: 0.35; } .nf-dev[hidden], .nf-pin[hidden] { display: none; } .nf-pin-active { background: var(--nf-accent); color: var(--nf-accent-text); border-color: transparent; box-shadow: var(--nf-shadow); } .nf-stats b { color: var(--nf-accent); font-weight: 700; } .nf-stats { padding: 4px 9px; border-radius: 8px; background: var(--nf-chrome); position: absolute; right: 10px; bottom: calc(8px + var(--nf-bottom-inset, 0px)); font-size: 11.5px; color: var(--nf-muted); font-variant-numeric: tabular-nums; pointer-events: none; } .nf-error { position: absolute; inset: auto 16px 16px; color: var(--nf-danger); } `, ]; } if (!customElements.get("nf-view3d")) customElements.define("nf-view3d", NfView3d); /** Power as "850 W" or "1,2 kW". */ function formatPower(hass: HomeAssistant | undefined, w: number): string { return Math.abs(w) >= 1000 ? `${formatNumber(hass, w / 1000, 1)} kW` : `${Math.round(w)} W`; } /** Marker height above furniture: in front of a screen, above wall units, else just above the top. */ function markerHeight(f: Furniture): number { if (f.type === "tv_board") return f.h + 0.9; // wall TV and wall cabinet: above the item (their height above the floor comes from mountBase) if (f.type === "tv_wall" || f.type === "kitchen_wall") return f.h + 0.25; return f.h + 0.35; } /** The text under a fan's pin: its speed in per cent while it runs, its state otherwise. */ function fanText(hass: HomeAssistant, st: HassEntity): string { const pct = st.attributes.percentage; return st.state === "on" && typeof pct === "number" ? `${Math.round(pct)} %` : stateText(hass, st); }