{ config, lib, pkgs, ... }: let cfg = config.modules.services.home-assistant; in { config = lib.mkIf cfg.enable { services.home-assistant = { config.lovelace.resources = [{ url = "/local/nixos-lovelace-modules/floorplan.js"; type = "module"; }]; customLovelaceModules = [ pkgs.ha-floorplan ]; }; environment.etc."home-assistant/www/floorplan/style.css".source = ./style.css; environment.etc."home-assistant/www/floorplan/config.yaml".text = builtins.toJSON { image = { location = "/local/floorplan/beetham.svg"; cache = false; }; stylesheet = { location = "/local/floorplan/style.css"; cache = false; }; defaults = { hover_action = "hover-info"; hold_action = "toggle"; tap_action = "more-info"; }; rules = [ { name = "Rooms"; entities = [ { entity = "light.bedroom_lamps"; element = "area.bedroom"; } { entity = "light.hallway_spots"; element = "area.hallway"; } { entity = "light.living_room_lamps"; element = "area.livingroom"; } { entity = "light.office_lamps"; element = "area.office"; } ]; tap_action = "light.toggle"; state_action = { service = "floorplan.class_set"; service_data = '' if (entity.state === "on") { return "light-on"; } return "light-off"; ''; }; } { name = "Temperature"; entities = [ "sensor.motion_sensor_temperature" ]; state_action = [ { service = "floorplan.text_set"; service_data = '' if (!isNaN(entity.state)) { return Math.round(entity.state * 10) / 10 + "°"; } return "Unknown"; ''; } { service = "floorplan.class_set"; service_data = { class = "static-temp"; }; } ]; } ]; }; }; }