diff --git a/hosts/pi/home-assistant/floorplan/default.nix b/hosts/pi/home-assistant/floorplan/default.nix index 9ef247b..171c679 100644 --- a/hosts/pi/home-assistant/floorplan/default.nix +++ b/hosts/pi/home-assistant/floorplan/default.nix @@ -1,94 +1,87 @@ { - config, - lib, pkgs, ... }: -let - cfg = config.modules.services.home-assistant; -in { - config = lib.mkIf cfg.enable { - services.home-assistant = { - customLovelaceModules = [ - pkgs.lovelace-floorplan - ]; + services.home-assistant = { + customLovelaceModules = [ + pkgs.lovelace-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; }; - 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"; + }; - defaults = { - hover_action = "hover-info"; - hold_action = "toggle"; - tap_action = "more-info"; - }; - - rules = [ - { - name = "Rooms"; - entities = [ - { - entity = "light.bedroom_lamps"; - element = "area.bedroom"; + 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"; } - { - 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"; + return "light-off"; + ''; + }; + } + { + name = "Temperature"; + entities = [ + "sensor.motion_sensor_temperature" + ]; + state_action = [ + { + service = "floorplan.text_set"; service_data = '' - if (entity.state === "on") { - return "light-on"; + if (!isNaN(entity.state)) { + return Math.round(entity.state * 10) / 10 + "°"; } - return "light-off"; + return "Unknown"; ''; - }; - } - { - 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"; - }; - } - ]; - } - ]; - }; + } + { + service = "floorplan.class_set"; + service_data = { + class = "static-temp"; + }; + } + ]; + } + ]; }; } diff --git a/hosts/pi/home-assistant/mqtt.nix b/hosts/pi/home-assistant/mqtt.nix index e0d580b..f59b78e 100644 --- a/hosts/pi/home-assistant/mqtt.nix +++ b/hosts/pi/home-assistant/mqtt.nix @@ -6,87 +6,82 @@ ... }: -let - cfg = config.modules.services.home-assistant; -in { - config = lib.mkIf cfg.enable { - services.mosquitto = { - enable = true; - listeners = [ - { - acl = [ "pattern readwrite #" ]; - omitPasswordAuth = true; - port = 1883; - settings = { - allow_anonymous = true; - }; - } - ]; - }; + services.mosquitto = { + enable = true; + listeners = [ + { + acl = [ "pattern readwrite #" ]; + omitPasswordAuth = true; + port = 1883; + settings = { + allow_anonymous = true; + }; + } + ]; + }; - age.secrets."files/services/zigbee2mqtt/secret.yaml" = { - file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age"; - path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml"; - owner = "zigbee2mqtt"; - group = "zigbee2mqtt"; - }; + age.secrets."files/services/zigbee2mqtt/secret.yaml" = { + file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age"; + path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml"; + owner = "zigbee2mqtt"; + group = "zigbee2mqtt"; + }; - services.zigbee2mqtt = { - package = pkgs.unstable.zigbee2mqtt; - enable = true; - dataDir = "/var/lib/zigbee2mqtt"; - settings = { - homeassistant = lib.optionalAttrs config.services.home-assistant.enable { - discovery_topic = "homeassistant"; - status_topic = "hass/status"; - }; - availability = true; - frontend = true; - device_options = { - retain = true; - }; - serial = { - port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0"; - adapter = "zstack"; - }; - advanced = { - channel = 20; - network_key = "!secret.yaml network_key"; - pan_id = 13001; - ext_pan_id = [ - 79 - 1 - 73 - 47 - 250 - 136 - 124 - 222 - ]; - transmit_power = 20; - }; - mqtt = { - version = 5; - server = "mqtt://localhost:1883"; - }; + services.zigbee2mqtt = { + package = pkgs.unstable.zigbee2mqtt; + enable = true; + dataDir = "/var/lib/zigbee2mqtt"; + settings = { + homeassistant = lib.optionalAttrs config.services.home-assistant.enable { + discovery_topic = "homeassistant"; + status_topic = "hass/status"; + }; + availability = true; + frontend = true; + device_options = { + retain = true; + }; + serial = { + port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0"; + adapter = "zstack"; + }; + advanced = { + channel = 20; + network_key = "!secret.yaml network_key"; + pan_id = 13001; + ext_pan_id = [ + 79 + 1 + 73 + 47 + 250 + 136 + 124 + 222 + ]; + transmit_power = 20; + }; + mqtt = { + version = 5; + server = "mqtt://localhost:1883"; }; }; + }; - modules.services.borgmatic.directories = [ - config.services.mosquitto.dataDir - config.services.zigbee2mqtt.dataDir + modules.services.borgmatic.directories = [ + config.services.mosquitto.dataDir + config.services.zigbee2mqtt.dataDir + ]; + + services.home-assistant = { + config.mqtt = { }; + extraComponents = [ + "mqtt" + "mqtt_eventstream" + "mqtt_json" + "mqtt_room" + "mqtt_statestream" ]; - - services.home-assistant = { - config.mqtt = { }; - extraComponents = [ - "mqtt" - "mqtt_eventstream" - "mqtt_json" - "mqtt_room" - "mqtt_statestream" - ]; - }; }; }