2020-10-11 10:49:06 +02:00
|
|
|
{ config, pkgs, ... }:
|
2020-10-03 16:32:06 +02:00
|
|
|
|
2020-11-14 11:20:21 +01:00
|
|
|
with pkgs;
|
2020-10-21 20:54:55 +02:00
|
|
|
|
2020-10-22 19:15:55 +02:00
|
|
|
let
|
|
|
|
mqttDomain = "mqtt.${config.networking.domain}";
|
2020-10-22 22:08:16 +02:00
|
|
|
mqttWSPort = "9001";
|
2020-11-14 11:20:21 +01:00
|
|
|
in {
|
2021-02-16 03:43:33 +01:00
|
|
|
# just installed for ConBee firmware updates
|
2020-10-07 14:37:57 +02:00
|
|
|
environment.systemPackages = with pkgs; [ deconz ];
|
|
|
|
|
2020-10-22 19:15:55 +02:00
|
|
|
services.nginx = {
|
|
|
|
virtualHosts = {
|
2020-11-14 11:20:21 +01:00
|
|
|
${mqttDomain} = {
|
2020-10-22 19:15:55 +02:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
2020-10-22 22:08:16 +02:00
|
|
|
proxyPass = "http://localhost:${mqttWSPort}";
|
2020-10-22 19:15:55 +02:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-10-21 20:54:55 +02:00
|
|
|
|
2020-11-14 11:20:21 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ config.services.mosquitto.port ];
|
2020-10-21 20:54:55 +02:00
|
|
|
|
|
|
|
services.mosquitto = {
|
|
|
|
enable = true;
|
|
|
|
host = "0.0.0.0";
|
|
|
|
checkPasswords = true;
|
2020-10-22 19:15:55 +02:00
|
|
|
extraConf = ''
|
2020-10-22 22:08:16 +02:00
|
|
|
listener ${mqttWSPort}
|
2020-10-22 19:15:55 +02:00
|
|
|
protocol websockets
|
|
|
|
'';
|
2020-10-21 20:54:55 +02:00
|
|
|
users = {
|
|
|
|
"hass" = {
|
|
|
|
acl = [
|
|
|
|
"topic readwrite homeassistant/#"
|
|
|
|
"topic readwrite tasmota/#"
|
|
|
|
"topic readwrite owntracks/#"
|
|
|
|
];
|
|
|
|
hashedPasswordFile = "/etc/nixos/secrets/mqtt/hass";
|
|
|
|
};
|
2020-10-22 19:16:43 +02:00
|
|
|
"tasmota" = {
|
2020-11-14 11:20:21 +01:00
|
|
|
acl = [ "topic readwrite tasmota/#" "topic readwrite homeassistant/#" ];
|
2020-10-22 19:16:43 +02:00
|
|
|
hashedPasswordFile = "/etc/nixos/secrets/mqtt/tasmota";
|
|
|
|
};
|
2020-10-21 20:54:55 +02:00
|
|
|
"owntracks" = {
|
2020-11-14 11:20:21 +01:00
|
|
|
acl = [ "topic readwrite owntracks/#" ];
|
2020-10-21 20:54:55 +02:00
|
|
|
hashedPasswordFile = "/etc/nixos/secrets/mqtt/owntracks";
|
|
|
|
};
|
2020-10-22 19:17:19 +02:00
|
|
|
"felix" = {
|
2020-11-14 11:20:21 +01:00
|
|
|
acl = [ "topic read owntracks/#" "topic readwrite owntracks/felix/#" ];
|
2020-10-22 19:17:19 +02:00
|
|
|
hashedPasswordFile = "/etc/nixos/secrets/mqtt/felix";
|
|
|
|
};
|
|
|
|
"birgit" = {
|
2020-11-14 11:20:21 +01:00
|
|
|
acl = [ "topic read owntracks/#" "topic readwrite owntracks/birgit/#" ];
|
2020-10-22 19:17:19 +02:00
|
|
|
hashedPasswordFile = "/etc/nixos/secrets/mqtt/birgit";
|
|
|
|
};
|
2020-10-21 20:54:55 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-03 16:32:06 +02:00
|
|
|
services.home-assistant = {
|
|
|
|
enable = true;
|
|
|
|
openFirewall = true;
|
|
|
|
config = {
|
|
|
|
homeassistant = {
|
|
|
|
name = "Home";
|
|
|
|
latitude = "!secret latitude";
|
|
|
|
longitude = "!secret longitude";
|
|
|
|
elevation = 0;
|
|
|
|
unit_system = "metric";
|
|
|
|
temperature_unit = "C";
|
|
|
|
external_url = "https://home.felschr.com";
|
2021-06-10 12:03:44 +02:00
|
|
|
internal_url = "http://192.168.1.234:8123";
|
2020-10-03 16:32:06 +02:00
|
|
|
};
|
2020-10-11 10:13:22 +02:00
|
|
|
default_config = { };
|
|
|
|
config = { };
|
2020-12-02 10:29:39 +01:00
|
|
|
"automation editor" = "!include automations.yaml";
|
2021-03-21 12:13:36 +01:00
|
|
|
automation = { };
|
2020-10-11 10:13:22 +02:00
|
|
|
frontend = { };
|
|
|
|
mobile_app = { };
|
|
|
|
discovery = { };
|
|
|
|
zeroconf = { };
|
|
|
|
ssdp = { };
|
|
|
|
shopping_list = { };
|
2021-02-16 03:43:33 +01:00
|
|
|
zha = {
|
|
|
|
database_path = "/var/lib/hass/zigbee.db";
|
2021-03-21 12:13:36 +01:00
|
|
|
zigpy_config = { ota = { ikea_provider = true; }; };
|
2020-10-07 14:37:57 +02:00
|
|
|
};
|
2020-10-21 20:54:55 +02:00
|
|
|
mqtt = {
|
|
|
|
broker = "localhost";
|
2020-10-22 19:16:43 +02:00
|
|
|
port = config.services.mosquitto.port;
|
2020-10-21 20:54:55 +02:00
|
|
|
username = "hass";
|
|
|
|
password = "!secret mqtt_password";
|
|
|
|
discovery = true;
|
|
|
|
discovery_prefix = "homeassistant";
|
|
|
|
};
|
2020-11-14 11:20:21 +01:00
|
|
|
owntracks = { mqtt_topic = "owntracks/#"; };
|
2020-12-02 10:29:39 +01:00
|
|
|
netatmo = {
|
|
|
|
client_id = "!secret netatmo_client_id";
|
|
|
|
client_secret = "!secret netatmo_client_secret";
|
|
|
|
};
|
2021-03-21 12:13:36 +01:00
|
|
|
sensor = [{
|
|
|
|
platform = "template";
|
|
|
|
sensors = {
|
|
|
|
energy_total_usage = {
|
|
|
|
friendly_name = "Total Energy Usage";
|
|
|
|
unit_of_measurement = "kWh";
|
|
|
|
value_template = ''
|
|
|
|
{{
|
|
|
|
(states.sensor.outlet_computer_energy_total.state | float) +
|
|
|
|
(states.sensor.outlet_tv_energy_total.state | float)
|
|
|
|
}}
|
|
|
|
'';
|
2020-12-02 10:29:39 +01:00
|
|
|
};
|
2021-03-21 12:13:36 +01:00
|
|
|
};
|
|
|
|
}];
|
2020-12-02 10:29:39 +01:00
|
|
|
utility_meter = {
|
|
|
|
energy_total_usage_daily = {
|
|
|
|
source = "sensor.energy_total_usage";
|
|
|
|
cycle = "daily";
|
|
|
|
};
|
|
|
|
energy_total_usage_monthly = {
|
|
|
|
source = "sensor.energy_total_usage";
|
|
|
|
cycle = "monthly";
|
|
|
|
};
|
|
|
|
energy_total_usage_yearly = {
|
|
|
|
source = "sensor.energy_total_usage";
|
|
|
|
cycle = "yearly";
|
|
|
|
};
|
|
|
|
};
|
2020-10-03 16:32:06 +02:00
|
|
|
};
|
|
|
|
# configWritable = true; # doesn't work atm
|
|
|
|
};
|
|
|
|
}
|