summaryrefslogtreecommitdiffstats
path: root/lass/2configs/hass/default.nix
blob: 7765db84efa4e07c4fdc51fb0d41f5851092412b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{ config, lib, pkgs, ... }:
with import ./lib.nix { inherit lib; };
let
  unstable = import (pkgs.fetchFromGitHub {
    owner = "nixos";
    repo = "nixpkgs";
    rev = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).rev;
    sha256 = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).sha256;
  }) {};
  dwdwfsapi = pkgs.python3Packages.buildPythonPackage rec {
    pname = "dwdwfsapi";
    version = "1.0.3";

    src = pkgs.python3Packages.fetchPypi {
      inherit pname version;
      sha256 = "0fcv79xiq0qr4kivhd68iqpgrsjc7djxqs2h543pyr0sdgb5nz9x";
    };

    buildInputs = with pkgs.python3Packages; [
      requests ciso8601
    ];

    # LC_ALL = "en_US.UTF-8";
  };

in {
  imports = [
    ./zigbee.nix
    ./rooms/bett.nix
    ./rooms/essen.nix
    ./rooms/nass.nix
  ];

  krebs.iptables.tables.filter.INPUT.rules = [
    { predicate = "-i int0 -p tcp --dport 1883"; target = "ACCEPT"; } # mosquitto
    { predicate = "-i docker0 -p tcp --dport 1883"; target = "ACCEPT"; } # mosquitto
    { predicate = "-i int0 -p tcp --dport 8123"; target = "ACCEPT"; } # hass
    { predicate = "-i int0 -p tcp --dport 1337"; target = "ACCEPT"; } # hass
    { predicate = "-i retiolum -p tcp --dport 8123"; target = "ACCEPT"; } # hass
    { predicate = "-i retiolum -p tcp --dport 1337"; target = "ACCEPT"; } # hass frontend
    { predicate = "-i wiregrill -p tcp --dport 8123"; target = "ACCEPT"; } # hass
  ];

  services.home-assistant = {
    enable = true;
    package = (unstable.home-assistant.overrideAttrs (old: {
      doInstallCheck = false;
    })).override {
      extraPackages = _: [ dwdwfsapi ];
    };
    configWritable = true;
    lovelaceConfigWritable = true;
    config = let
      tasmota_s20 = name: topic: {
        platform = "mqtt";
        inherit name;
        state_topic = "stat/${topic}/POWER";
        command_topic = "cmnd/${topic}/POWER";
        payload_on = "ON";
        payload_off = "OFF";
      };
    in {
      homeassistant = {
        name = "Home";
        time_zone = "Europe/Berlin";
        latitude = "52.46187";
        longitude = "13.41489";
        elevation = 90;
        unit_system = "metric";
        customize = friendly_names;
      };
      config = {};
      sun.elevation = 66;
      shopping_list = {};
      discovery = {};
      frontend = {};
      http = {};
      mqtt = {
        broker = "localhost";
        port = 1883;
        client_id = "home-assistant";
        username = "gg23";
        password = "gg23-mqtt";
        keepalive = 60;
        protocol = 3.1;

        discovery = true;
        birth_message = {
          topic = "/hass/status";
          payload = "online";
        };
        will_message = {
          topic = "/hass/status";
          payload = "offline";
        };
      };
      sensor = [
        {
          platform = "dwd_weather_warnings";
          region_name = "Berlin";
        }
      ];
      switch = [
        (tasmota_s20 "TV" "tv")
        (tasmota_s20 "Drucker Strom" "drucker")
        (tasmota_s20 "Waschmaschine" "wasch")
        (tasmota_s20 "Stereo Anlage" "stereo")
      ];
      mobile_app = {};
      weather = [
        {
          platform = "openweathermap";
          api_key = "xxx"; # TODO put into secrets
        }
      ];
      system_health = {};
      history = {};
      shopping_list = {};
    };
  };

  services.mosquitto = {
    enable = true;
    host = "0.0.0.0";
    allowAnonymous = false;
    checkPasswords = true;
    users.gg23 = {
      password = "gg23-mqtt";
      acl = [ "topic readwrite #" ];
    };
  };

  environment.systemPackages = [ pkgs.mosquitto ];
}