summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/stats/telegraf/airsensor.nix
blob: 9d481000ff2b8f52af3d3d747954503bab487ebc (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
{ pkgs, ...}:
let
  genTopic = name: topic: tags: {
      servers = [ "tcp://localhost:1883" ];
      qos = 0;
      connection_timeout = "30s";
      topics = [ topic ];
      tags = tags;
      persistent_session = false;
      name_override = name;
      data_format = "value";
      data_type = "float";
    };
  bamStat = stat:   # Temperature or Humidity
            host:   # easy{1-4}
            sensor: # dht11, dht22, ds18
            (genTopic stat
                      "/bam/${host}/${sensor}/${stat}"
                      {"host" = host;
                       "scope" = "bam";
                       "sensor" = sensor;
                      } );
  dht22 = host: [(bamStat "Temperature" host "dht22")
                 (bamStat "Humidity" host "dht22")];
  dht11 = host: [(bamStat "Temperature" host "dht11")
                 (bamStat "Humidity" host "dht11")];
  ds18 = host:  [(bamStat "Temperature" host "ds18")];
in {
  services.udev.extraRules = ''
    SUBSYSTEMS=="usb", ATTRS{product}=="iAQ Stick", GROUP="input"
  '';
  users.users.telegraf.extraGroups = [ "input" ];
  services.telegraf.extraConfig.inputs.exec =  [
    {
      commands = [ "${pkgs.airsensor-py}/bin/airsensor-py"];
      timeout = "10s";
      data_format = "value";
      data_type = "integer";
      name_override = "airquality";
      interval = "10s";
      tags.unit="VOC";
    }
  ];
  services.telegraf.extraConfig.inputs.mqtt_consumer =
       (dht22 "easy1")
    ++ (dht22 "easy2")
    ++ (dht11 "easy3")
    ++ (ds18  "easy3");
}