home-assistant: fix mqtt and floorplan
Some checks failed
Check flake / build-amd64-linux (push) Failing after 3m22s

This commit is contained in:
2025-03-10 22:12:36 +00:00
parent 6ec24bd694
commit fd2ddd3878
2 changed files with 142 additions and 154 deletions

View File

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

View File

@ -6,87 +6,82 @@
... ...
}: }:
let
cfg = config.modules.services.home-assistant;
in
{ {
config = lib.mkIf cfg.enable { services.mosquitto = {
services.mosquitto = { enable = true;
enable = true; listeners = [
listeners = [ {
{ acl = [ "pattern readwrite #" ];
acl = [ "pattern readwrite #" ]; omitPasswordAuth = true;
omitPasswordAuth = true; port = 1883;
port = 1883; settings = {
settings = { allow_anonymous = true;
allow_anonymous = true; };
}; }
} ];
]; };
};
age.secrets."files/services/zigbee2mqtt/secret.yaml" = { age.secrets."files/services/zigbee2mqtt/secret.yaml" = {
file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age"; file = "${self.inputs.secrets}/files/services/zigbee2mqtt/secret.yaml.age";
path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml"; path = "${config.services.zigbee2mqtt.dataDir}/secret.yaml";
owner = "zigbee2mqtt"; owner = "zigbee2mqtt";
group = "zigbee2mqtt"; group = "zigbee2mqtt";
}; };
services.zigbee2mqtt = { services.zigbee2mqtt = {
package = pkgs.unstable.zigbee2mqtt; package = pkgs.unstable.zigbee2mqtt;
enable = true; enable = true;
dataDir = "/var/lib/zigbee2mqtt"; dataDir = "/var/lib/zigbee2mqtt";
settings = { settings = {
homeassistant = lib.optionalAttrs config.services.home-assistant.enable { homeassistant = lib.optionalAttrs config.services.home-assistant.enable {
discovery_topic = "homeassistant"; discovery_topic = "homeassistant";
status_topic = "hass/status"; status_topic = "hass/status";
}; };
availability = true; availability = true;
frontend = true; frontend = true;
device_options = { device_options = {
retain = true; retain = true;
}; };
serial = { serial = {
port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0"; port = "/dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0";
adapter = "zstack"; adapter = "zstack";
}; };
advanced = { advanced = {
channel = 20; channel = 20;
network_key = "!secret.yaml network_key"; network_key = "!secret.yaml network_key";
pan_id = 13001; pan_id = 13001;
ext_pan_id = [ ext_pan_id = [
79 79
1 1
73 73
47 47
250 250
136 136
124 124
222 222
]; ];
transmit_power = 20; transmit_power = 20;
}; };
mqtt = { mqtt = {
version = 5; version = 5;
server = "mqtt://localhost:1883"; server = "mqtt://localhost:1883";
};
}; };
}; };
};
modules.services.borgmatic.directories = [ modules.services.borgmatic.directories = [
config.services.mosquitto.dataDir config.services.mosquitto.dataDir
config.services.zigbee2mqtt.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"
];
};
}; };
} }