summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/shack/glados/multi/wasser.nix
blob: 74ce736a668b2743c6795b715bbbe2e65c5897f4 (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
# uses:
#  switch.crafting_giesskanne_relay
let
  glados = import ../lib;
  seconds = 20;
  wasser = "switch.crafting_giesskanne_relay";
in
{
  sensor = map ( entity_id: {
      platform = "statistics";
      name = "Statistics for ${entity_id}";
      inherit entity_id;
      max_age.minutes = "60";
    }) ["sensor.crafting_brotbox_soil_moisture"];


  automation =
  [
    { alias = "Water the plant for ${toString seconds} seconds";
      trigger = [
        { # trigger at 20:00 no matter what
          # TODO: retry or run only if switch.wasser is available
          platform = "time";
          at = "20:00:00";
        }
      ];
      action =
      [
        {
          service = "homeassistant.turn_on";
          entity_id =  [
            wasser
          ];
        }
        { delay.seconds = seconds; }
        {
          service = "homeassistant.turn_off";
          entity_id =  [
            wasser
          ];
        }
      ];
    }
    { alias = "Always turn off water after ${toString (seconds * 2)}seconds";
      trigger = [
        {
          platform = "state";
          entity_id = wasser;
          to = "on";
          for.seconds = seconds*2;
        }
      ];
      action =
      [
        {
          service = "homeassistant.turn_off";
          entity_id =  [ wasser ];
        }
      ];
    }
  ];
}