service/home-assistant: add esphome

This commit is contained in:
Felix Buehler 2023-11-26 16:27:53 +01:00
parent bd039d6581
commit 92047a8207

View file

@ -80,52 +80,56 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.home-assistant = { services = {
enable = true; home-assistant = {
enable = true;
inherit (cfg) package; inherit (cfg) package;
config = { config = {
default_config = { }; default_config = { };
homeassistant = { homeassistant = {
name = "Home"; name = "Home";
inherit (cfg) latitude longitude elevation; inherit (cfg) latitude longitude elevation;
unit_system = "metric"; unit_system = "metric";
time_zone = cfg.timezone; time_zone = cfg.timezone;
external_url = "https://automation.${domain}"; external_url = "https://automation.${domain}";
internal_url = "http://127.0.0.1:${toString cfg.port}"; internal_url = "http://127.0.0.1:${toString cfg.port}";
};
http = {
server_port = cfg.port;
use_x_forwarded_for = true;
trusted_proxies = [
"127.0.0.1"
"::1"
];
};
prometheus.requires_auth = false;
}; };
http = {
server_port = cfg.port; extraComponents = [
use_x_forwarded_for = true; "backup"
trusted_proxies = [ "prometheus"
"127.0.0.1" ] ++ cfg.extraComponents;
"::1"
];
};
prometheus.requires_auth = false;
}; };
extraComponents = [ prometheus.scrapeConfigs = [
"backup" {
"prometheus" job_name = "home-assistant";
] ++ cfg.extraComponents; metrics_path = "/api/prometheus";
}; static_configs = [
{
targets = [ "127.0.0.1:${toString cfg.port}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
services.prometheus.scrapeConfigs = [ esphome.enable = true;
{ };
job_name = "home-assistant";
metrics_path = "/api/prometheus";
static_configs = [
{
targets = [ "127.0.0.1:${toString cfg.port}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
my.services.prometheus.rules = { my.services.prometheus.rules = {
homeassistant = { homeassistant = {
@ -147,14 +151,35 @@ in
}; };
}; };
} }
{
subdomain = "esphome";
inherit (config.services.esphome) port;
extraConfig = {
locations."/" = {
proxyWebsockets = true;
};
};
}
]; ];
webapps.apps.home-assistant = { webapps.apps = {
dashboard = { home-assistant = {
name = "Home-Automation"; dashboard = {
category = "infra"; name = "Home-Automation";
icon = "house-signal"; category = "infra";
url = "https://automation.${domain}"; icon = "house-signal";
url = "https://automation.${domain}";
method = "get";
};
};
esphome = {
dashboard = {
name = "Home-Firmware";
category = "infra";
icon = "house-laptop";
url = "https://esphome.${domain}";
method = "get";
};
}; };
}; };
}; };