Add honme-assistant module

This commit is contained in:
Hendrik Sokolowski 2023-06-12 17:04:12 +02:00
parent f60a0bc019
commit e10e91571c
4 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,62 @@
{
lib,
config,
options,
pkgs,
...
}:
with lib; let
cfg = config.pub-solar.home-assistant;
in {
imports = [
./home-assistant.nix
./mqtt.nix
./zigbee.nix
];
options.pub-solar.home-assistant = {
enable = mkOption {
description = "Control your home";
type = types.bool;
default = false;
};
config = options.services.home-assistant.config;
extraComponents = options.services.home-assistant.extraComponents;
extraPackages = options.services.home-assistant.extraPackages;
mqtt = {
enable = mkOption {
description = "use mqtt";
type = types.bool;
default = true;
};
users = mkOption {
description = "mqtt users";
# type = types.AttrSet;
default = null;
};
};
zigbee2mqtt = {
enable = mkOption {
description = "Enable zigbee2mqtt";
type = types.bool;
default = false;
};
device = mkOption {
description = "Device to connect to zigbee network";
type = types.nullOr types.str;
default = null;
};
adapter = mkOption {
description = "Specify zigbee adapter type";
type = types.nullOr types.str;
default = null;
};
};
};
}

View file

@ -0,0 +1,21 @@
{
lib,
config,
pkgs,
...
}:
with lib; let
cfg = config.pub-solar.home-assistant;
in {
config = mkIf cfg.enable {
services.home-assistant = {
enable = true;
openFirewall = true;
extraComponents =
cfg.extraComponents
++ lib.optionals cfg.mqtt.enable ["mqtt"];
extraPackages = cfg.extraPackages;
config = cfg.config;
};
};
}

View file

@ -0,0 +1,21 @@
{
lib,
config,
pkgs,
...
}:
with lib; let
haCfg = config.pub-solar.home-assistant;
cfg = config.pub-solar.home-assistant.mqtt;
in {
config = mkIf (haCfg.enable && cfg.enable) {
networking.firewall.allowedTCPPorts = [
1883 # mosquitto
];
services.mosquitto = {
enable = true;
listeners = [{users = cfg.users;}];
};
};
}

View file

@ -0,0 +1,35 @@
{
lib,
config,
pkgs,
...
}:
with lib; let
haCfg = config.pub-solar.home-assistant;
cfg = config.pub-solar.home-assistant.zigbee2mqtt;
in {
config = mkIf (haCfg.enable && cfg.enable) {
networking.firewall.allowedTCPPorts = [
8080 # zigbee2mqtt
];
#services.udev.extraRules = ''KERNEL=="${cfg.device}", OWNER="zigbee2mqtt", GROUP="zigbee2mqtt"'';
services.zigbee2mqtt = {
enable = true;
settings = {
frontend = true;
permit_join = false;
homeassistant = true;
mqtt = {
user = "z2m";
password = "!secrets.yaml mqtt_password";
};
serial = {
port = cfg.device;
adapter = mkIf (cfg.adapter != null) cfg.adapter;
};
};
};
};
}